Making an Add-in (VSTA)

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

Hi,

how about

myTarget.Transform.X = …
myTarget.Transform.Y = …

In the API help you ll find an example under the section RsTarget.

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.

myTask.SyncData(“Module1/” + myTarget.Name, SyncDirection.ToController, new System.Collections.Generic.List());

'// 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,

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.

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;
http://www.developerfusion.com/tools/convert/vb-to-csharp/