Cloneobjects in a loop


#1

Hello,

I have the following code with vQtyAcross=5. So in theory it should clone the object 5 times and rename it with the counter value at the end of “FileContainer-”. It only creates 2 and does not change the name of the 2nd item.

Also, vFileContainerWidthPixels is set with a formula earlier in the code.
Thoughts?

vTempName="FileContainer-"
showvariables vTempName
vName=vTempName+"1"
vCounter=1
loop
stoploopif vCounter > val(vQtyAcross)
object vName
vCloneObjectRectangle=objectinfo("rectangle")
cloneobjects   "rectangle",rectangleoffset(vCloneObjectRectangle,0,vFileContainerWidthPixels),"name",vName
selectnoobjects
vCounter=vCounter+1
vName=vTempName+str(vCounter)
showvariables vName
endloop

#2

I don’t know if I can explain everything you say is happening. But there are a couple of issues I can see.

The object command is trying to select an object you haven’t created yet. Apparently, the object you want to clone is already selected.

After your selectnoobjects command, no object is selected, and the object command can’t find an object with the name you have given it, so the second time through, it doesn’t know which object to clone.


#3

Change the line to:

cloneobjects   "rectangle",rectangleoffset(vCloneObjectRectangle,0,vFileContainerWidthPixels),
    "name",vTempName+str(vCounter+1)