Is it possible to change the wobj in a loop?

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 := Rsin(45-a);
Y := R
cos(45-a);
Z := 0;
q1 := 0.5sqrt(1-sin(45-a));
q2 := 0.5
sqrt(1+sin(45-a));
q3 := 0.5sqrt(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

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!

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.

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?

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.

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

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

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

Dear “lemster68”,

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

Thank you very much!

You are welcome. :slight_smile: