# Write a Robtarget Help !!!

**URL:** <https://tech-community.robotics.abb.com/t/write-a-robtarget-help/3806>\
**Category:** Developer Tools\
**Created:** [September 16, 2010, 6:17pm UTC](https://tech-community.robotics.abb.com/t/write-a-robtarget-help/3806 "2010-09-16T18:17:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackcoder](https://avatars.discourse-cdn.com/v4/letter/b/d26b3c/32.png) [@blackcoder](https://tech-community.robotics.abb.com/u/blackcoder)\
**Post date:** [September 16, 2010, 6:17pm UTC](https://tech-community.robotics.abb.com/t/write-a-robtarget-help/3806/1 "2010-09-16T18:17:38Z")

</div>

Dim c As New Controller()

Dim motion As MotionSystem = c.MotionSystem

Dim mech As MechanicalUnit = motion.GetActiveMechanicalUnit()

Dim robP As RobTarget

robP = mech.GetPosition(CoordinateSystemType.WorkObject)

Dim rdRobtarget As RapidData = c.Rapid.GetRapidData(“T\_ROB1”, “SrvSysInit”, “ptest”)

Dim rtValue As RobTarget = DirectCast(rdRobtarget.Value, RobTarget)

rdRobtarget.WriteItem(robP)

i want to change ptest robtarget position to my current robtarget position but always an error not change my ptest robtarget what is the problem please help

---

<div class="post-metadata">

**Author:** ![Lennart\_H](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@Lennart\_H](https://tech-community.robotics.abb.com/u/Lennart_H)\
**Post date:** [September 17, 2010, 10:48am UTC](https://tech-community.robotics.abb.com/t/write-a-robtarget-help/3806/2 "2010-09-17T10:48:01Z")

</div>

Please post the error text.

---

<div class="post-metadata">

**Author:** ![blackcoder](https://avatars.discourse-cdn.com/v4/letter/b/d26b3c/32.png) [@blackcoder](https://tech-community.robotics.abb.com/u/blackcoder)\
**Post date:** [September 18, 2010, 10:59pm UTC](https://tech-community.robotics.abb.com/t/write-a-robtarget-help/3806/3 "2010-09-18T22:59:35Z")

</div>

error code is

object reference not set to an instance of an object

See the end of this message for details on invoking  
just-in-time (JIT) debugging instead of this dialog box.  
\*\*\*\*\*\*\*\*\*\*\*\*\*\* Exception Text \*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Message: Object reference not set to an instance of an object.  
System.NullReferenceException: Object reference not set to an instance of an object.  
at ABB.Robotics.Controllers.RapidDomain.UserDefined.FillFromString(String newValue)  
 ←   
ABB.Robotics.InternalException at FillFromString in ABB.Robotics.Controllers.RapidDomain.UserDefined  
at ABB.Robotics.Dcl.ExceptionHelp.ReThrowException(String objStr, String method, Exception exception, String additionalinfo)  
at ABB.Robotics.Dcl.ExceptionHelp.GenerateException(String objStr, String method, Exception exception, String additionalinfo)  
at ABB.Robotics.Dcl.ExceptionHelp.GenerateException(Object obj, String method, Exception exception, String additionalinfo)  
at ABB.Robotics.Dcl.ExceptionHelp.GenerateException(Object obj, String method, Exception exception)  
at ABB.Robotics.Controllers.RapidDomain.RapidData.ReadItem(Int32 index)

---

<div class="post-metadata">

**Author:** ![Lennart\_H](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@Lennart\_H](https://tech-community.robotics.abb.com/u/Lennart_H)\
**Post date:** [September 20, 2010, 2:02pm UTC](https://tech-community.robotics.abb.com/t/write-a-robtarget-help/3806/4 "2010-09-20T14:02:35Z")

</div>

Are you trying to write to a RobTarget stored in an array? I put you the question because the WriteItem method is used when writing to a specific RobTarget that is stored in an array of RobTargets.

If this is not the case please find below code (C#) that will read the current position of the manipulator and then writes the data to a RobTarget variable.

m\_MotionSystem = this.controller.MotionSystem;

m\_MechanicalUnit = m\_MotionSystem.ActiveMechanicalUnit;

RobTarget CurrPos = new RobTarget();

RobTarget rt = new RobTarget();

RapidData rd = this.controller.Rapid.GetRapidData(“T\_ROB1”, “sample”, “pTest”);

CurrPos=m\_MechanicalUnit.GetPosition(CoordinateSystemType.WorkObject);

rt=(ABB.Robotics.Controllers.RapidDomain.RobTarget)rd.Value;

rt = CurrPos;

this.m\_master = Mastership.Request(this.controller.Rapid);

rd.Value = rt;

this.m\_master.Dispose();
