Making an Add-in (VSTA)
' Creates a new target in the active task and adds it to a path<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Public Sub Macro_CreateTarget()
' Check that we have an active station
Dim station As Station = Project.ActiveProject
If station Is Nothing Then
Exit Sub
End If
Dim activeTask As RsTask = station.ActiveTask
If activeTask Is Nothing Then
Exit Sub
End If
' Find an unused name
Dim targetName As String = ""
For i As Int32 = 0 To Int32.MaxValue
targetName = "MyTarget_" + i.ToString()
If activeTask.DataDeclarations.Contains(targetName) = False Then
Exit For
End If
Next
' Create a robtarget
Dim robTarget As New RsRobTarget()
robTarget.Name = targetName
' Add the robtarget to the active task
activeTask.DataDeclarations.Add(robTarget)
' Create a target associated with the robtarget and the active workobject
Dim workObject As RsWorkObject = activeTask.ActiveWorkObject
Dim myTarget As New RsTarget(workObject, robTarget)
myTarget.Name = targetName
' Add the target to the active task
activeTask.Targets.Add(myTarget)
Logger.AddMessage(New LogMessage("RobotStudio Sample: Created " + targetName + " in " + activeTask.Name))
' If the task has an active path procedure, create a new move instruction and add it
Dim path As RsPathProcedure = activeTask.ActivePathProcedure
If path IsNot Nothing Then
Dim tool As RsToolData = activeTask.ActiveTool
Dim procDef As RsProcessDefinition = activeTask.ActiveProcessDefinition
Dim procTempl As RsProcessTemplate = procDef.ActiveProcessTemplate
Dim moveInstr As New RsMoveInstruction(activeTask, procDef.Name, _
procTempl.Name, procTempl.ActiveMotionType, _
workObject.Name, robTarget.Name, tool.Name)
path.Instructions.Add(moveInstr)
Logger.AddMessage(New LogMessage("Sample Add-In: Added " + targetName + " to " + path.Name))
End If
End Sub
Comments
-
Hi,
how about
myTarget.Transform.X = ...
myTarget.Transform.Y
= ...
In the API help you ll find an example under the section RsTarget.
0 -
Hi,
Thanks for your help! It works for me.Do you also know how to convert the code below in VSTA code ?'// Sync the RobTaget to the VC.<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />
myTask.SyncData("Module1/" + myTarget.Name, SyncDirection.ToController, new System.Collections.Generic.List<SyncLogMessage>());
'// Sync the path to the VC.
if (myTask.SyncPathProcedure("Module1/" + myPath.Name, SyncDirection.ToController, new ArrayList()))
{
Logger.AddMessage(new LogMessage("SyncPathProcedure of path " + myPath.Name + " succeded!"));
}
else
{
Logger.AddMessage(new LogMessage("SyncPathProcedure of path " + myPath.Name + " falied!"));
}
'// Sync the complete task to the VC.
if (myTask.SyncToController(new ArrayList()))
{
Logger.AddMessage(new LogMessage("SyncToController succeded!"));
}
else
{
Logger.AddMessage(new LogMessage("SyncToController falied!"));
}
Regards,0 -
Hi,
looks like C# code. VSTA uses .NET means you can use c# as well as visual basic. i am not familiar with visual basic but it if youa re it shouldn t be that hard to to convert it to visual baisc.
apox2010-03-29 00:37:140 -
Hi,
as Apox said you can create both C# and VB.NET projects in VSTA.If you want to translate the code you can try this tools that provides translations in both directions;
0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 786 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings