# Is it possible to change the wobj in a loop?

**URL:** <https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231>\
**Category:** RobotStudio\
**Created:** [May 11, 2018, 12:59pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231 "2018-05-11T12:59:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![AZamfir](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@AZamfir](https://tech-community.robotics.abb.com/u/AZamfir)\
**Post date:** [May 11, 2018, 12:59pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/1 "2018-05-11T12:59:44Z")

</div>

I defined a few wobj as below:

PERS wobjdata wobj\_0 :=[FALSE, TRUE, “”, [ [0, -1570, 550], [1, 0, 0 ,0] ], [[0, 0, 0], [1, 0, 0 ,0] ] ];  
PERS wobjdata wobj\_5 :=[FALSE, TRUE, “”, [ [0, -1570, 550], [0.99905, 0.03082, -0.03082, 0] ], [[0, 0, 0], [1, 0, 0 ,0] ] ];  
PERS wobjdata wobj\_10 :=[FALSE, TRUE, “”, [ [0, -1570, 550], [0.99619, 0.06163, -0.06163, 0] ], [[0, 0, 0], [1, 0, 0 ,0] ] ];  
PERS wobjdata wobj\_15 :=[FALSE, TRUE, “”, [ [0, -1570, 550], [0.99144, 0.09230, -0.09230, 0] ], [[0, 0, 0], [1, 0, 0 ,0] ] ];  
PERS wobjdata wobj\_20 :=[FALSE, TRUE, “”, [ [0, -1570, 550], [0.98481, 0.12279, -0.12279, 0] ], [[0, 0, 0], [1, 0, 0 ,0] ] ];  
PERS wobjdata wobj\_25 :=[FALSE, TRUE, “”, [ [0, -1570, 550], [0.97630, 0.15305, -0.15305, 0] ], [[0, 0, 0], [1, 0, 0 ,0] ] ];

and then I used them in a script as follows:

FOR a FROM 0 TO 90 STEP 5 DO  
X := R_sin(45-a);  
Y := R_cos(45-a);  
Z := 0;  
q1 := 0.5_sqrt(1-sin(45-a));  
q2 := 0.5_sqrt(1+sin(45-a));  
q3 := 0.5_sqrt(1-sin(45-a));  
q4 := -0.5_sqrt(1+sin(45-a));  
nenorm := [q1, q2, q3, q4];  
p{a+1} := [[X,Y,Z],nenorm,[-1,0,0,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];

ENDFOR

FOR a FROM 0 TO 90 STEP 5 DO

MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_0;  
ENDFOR

FOR a FROM 90 TO 0 STEP -5 DO

MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_5;  
ENDFOR

FOR a FROM 0 TO 90 STEP 5 DO  
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_10;  
ENDFOR

FOR a FROM 90 TO 0 STEP -5 DO

MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_15;  
ENDFOR

FOR a FROM 0 TO 90 STEP 5 DO  
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_20;  
ENDFOR

FOR a FROM 90 TO 0 STEP -5 DO

MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_25;  
ENDFOR

Is it possible to replace the six FOR above with a kind of two-level FOR as below?

FOR n FROM 0 TO 20 STEP 10 DO  
FOR a FROM 0 TO 90 STEP 5 DO  
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_n;  
ENDFOR

FOR a FROM 90 TO 0 STEP -5 DO

MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj\_n+5;  
ENDFOR

ENDFOR

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [May 11, 2018, 1:16pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/2 "2018-05-11T13:16:35Z")

</div>

Not like that. Put the names of your workobjects into an array, then use \Wobj:=ArgName{a}; I think this will work, might need some playing around with to get it exactly right. Good luck!

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [May 11, 2018, 5:25pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/3 "2018-05-11T17:25:42Z")

</div>

Looks like you will have to use a similar strategy for your robtargets, the robot will not like it the way you have written it.

---

<div class="post-metadata">

**Author:** ![AZamfir](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@AZamfir](https://tech-community.robotics.abb.com/u/AZamfir)\
**Post date:** [May 15, 2018, 12:37pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/4 "2018-05-15T12:37:00Z")

</div>

Thank you very much!

I have inserted, before “PROC main()”, the following statement:  
PERS wobjdata wobjtest{45};  
The immediate effect was an Error message:  
Description: Persistent name wobjtest ambiguous.  
Actions: Program data must have names that are unique within the module. Rename the data or change the conflicting name.

In fact I am not sure I can define an Array of wobjdata. In the “RAPID Instructions Functions and Data types”, chapter 3.76 (wobjdata - Work object data) I found the following:  
“Limitations  
The work object data should be defined as a persistent variable (PERS) and should  
not be defined within a routine. The current values are then saved when the program  
is saved and are retrieved on loading.  
Arguments of the type work object data in any motion instruction should only be  
an entire persistent (not array element or record component).”

What do you think?

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [May 15, 2018, 12:45pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/5 "2018-05-15T12:45:13Z")

</div>

That is correct, wobjdata cannot be in an array. What I was suggesting is a string array with those workobject’s names in it. Thus, the function ArgName to identify the workobject.

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [May 15, 2018, 2:30pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/6 "2018-05-15T14:30:56Z")

</div>

Sorry, A little error I noticed: \Wobj:=ArgName(WorkobjectName{a});

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [May 15, 2018, 3:50pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/7 "2018-05-15T15:50:14Z")

</div>

OK, tried it out and debugged it myself in RS…

PROC Routine2()

FOR i FROM 1 TO 6 DO  
! Make a string array with the names of your workobjects  
! myWobj needs to be declared variable  
GetDataVal stWobjName{i},myWobj;  
! Declare myWobj2 as PERS  
myWobj2:=myWobj;  
MoveJ p201,v1000,z50,miniGun8\_45mmFlame\WObj:=myWobj2;  
ENDFOR  
ENDPROC

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [May 15, 2018, 7:30pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/8 "2018-05-15T19:30:28Z")

</div>

Sorry about the ArgName misinformation, I further tried it with the addition of the robtargets, which I mentioned before will need to have a similar strategy.

PROC Routine2()

FOR i FROM 1 TO 6 DO  
GetDataVal stWobjName{i},myWobj;  
myWobj2:=myWobj;  
FOR j FROM 1 TO 10 DO  
GetDataVal stTargetName{j},myRobtarget;  
myRobtarget2:=myRobtarget;  
MoveJ myRobtarget2,v1000,z50,miniGun8\_45mmFlame\WObj:=myWobj2;  
ENDFOR  
ENDFOR  
ENDPROC

---

<div class="post-metadata">

**Author:** ![AZamfir](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@AZamfir](https://tech-community.robotics.abb.com/u/AZamfir)\
**Post date:** [May 17, 2018, 1:58pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/9 "2018-05-17T13:58:12Z")

</div>

Dear “lemster68”,

I have adapted the simple, short code you suggested and the problem is now solved!

Thank you very much!

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [May 17, 2018, 2:39pm UTC](https://tech-community.robotics.abb.com/t/is-it-possible-to-change-the-wobj-in-a-loop/8231/10 "2018-05-17T14:39:37Z")

</div>

You are welcome. 🙂
