# Making an Add-in (VSTA)

**URL:** <https://tech-community.robotics.abb.com/t/making-an-add-in-vsta/3477>\
**Category:** RobotStudio\
**Created:** [March 27, 2010, 4:06pm UTC](https://tech-community.robotics.abb.com/t/making-an-add-in-vsta/3477 "2010-03-27T16:06:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/system/32/6_2.png) [@system](https://tech-community.robotics.abb.com/u/system)\
**Post date:** [March 27, 2010, 4:06pm UTC](https://tech-community.robotics.abb.com/t/making-an-add-in-vsta/3477/1 "2010-03-27T16:06:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apox](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/apox/32/2392_2.png) [@apox](https://tech-community.robotics.abb.com/u/apox)\
**Post date:** [March 28, 2010, 12:35am UTC](https://tech-community.robotics.abb.com/t/making-an-add-in-vsta/3477/2 "2010-03-28T00:35:43Z")

</div>

Hi,

how about

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

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/system/32/6_2.png) [@system](https://tech-community.robotics.abb.com/u/system)\
**Post date:** [March 28, 2010, 11:37am UTC](https://tech-community.robotics.abb.com/t/making-an-add-in-vsta/3477/3 "2010-03-28T11:37:31Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![apox](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/apox/32/2392_2.png) [@apox](https://tech-community.robotics.abb.com/u/apox)\
**Post date:** [March 29, 2010, 12:36am UTC](https://tech-community.robotics.abb.com/t/making-an-add-in-vsta/3477/4 "2010-03-29T00:36:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Niklas\_Skoglund](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@Niklas\_Skoglund](https://tech-community.robotics.abb.com/u/Niklas_Skoglund)\
**Post date:** [April 8, 2010, 5:54pm UTC](https://tech-community.robotics.abb.com/t/making-an-add-in-vsta/3477/5 "2010-04-08T17:54:46Z")

</div>

Hi,

as Apox said you can create both C# and [VB.NET](http://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/](http://www.developerfusion.com/tools/convert/vb-to-csharp/)
