I’m trying to make an add-in with VSTA for robotstudio by using the sample code for creating a new robtarget. When the new target is imported in robotstudio all the coordinates (X,Y,Z) are zero.
How can I change these coordinates ?
This is the example code that I use:
’ Creates a new target in the active task and adds it to a path
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