XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : Appending to an Array?

01-21-2009, 08:01 PM
Hi everyone, i have a question.

I'm trying to append a large number of objects to an array.
All my objects name start the same way "Shape_whateverComesNextAfter"

So i'd like to append them all in an array using the similarity in the name since all the control objects i'll ever use will be named that way.

So i've tried writing it this way

shapeAll= $Shape_*
append shps shapeAll

The order in which my shapes get appended doesn't matter for what i want to use my array.

Obviously it doesn't work otherwise i wouldn't post on this forum :P

If anybody can help me it would be greatly appreciated.

Thanks for your time.

01-21-2009, 08:07 PM
I think, this appends only the variable shapeAll into the array, not each Shape-object. I would try this:

append shps #($Shape_*)

Edit: Updated Code.

01-21-2009, 08:13 PM
Use collect to loop through the objects and create an array on the fly:
shps = for obj in $Shape_* collect obj
shps = $Shape_* as array
And to add more objects to this array later on, you can use the join function to merge two arrays:
join shps (for obj in $Blah_* collect obj)

01-21-2009, 08:17 PM
Thanks a lot guys for all the solutions :)

01-21-2009, 08:45 PM
an alternative to 'join' that you might encounter is += ;

a = #(1,2,3)
#(1, 2, 3)
b = #(4,5,6)
#(4, 5, 6)
a += b
#(1, 2, 3, 4, 5, 6)

#(1, 2, 3, 4, 5, 6)

This mostly finds use when you don't want to work on the array in-place;

a = #(1,2,3)
#(1, 2, 3)
b = #(4,5,6)
#(4, 5, 6)
c = a+b
#(1, 2, 3, 4, 5, 6)
#(1, 2, 3, 4, 5, 6)
#(1, 2, 3)

01-21-2009, 09:06 PM
Question again. Appending in the array worked fine using collect. I get an error though when i try to run the rest of the code. If you guys can help it would be great. Thanks again.

fn zeroOutControllers=
shpsPR= for obj in $Shape_* collect obj

-- Zero Out Position and Rotation Controllers for all the Control Shapes
for i = 1 to 62 do
-- Zero Out Position
posL= position_list()
shpsPR[i].position.controller= posL
shpsPR[i].position.controller.available.controller= position_xyz()
posL.setactive 2
posL.setname 1 "Zero"
posL.setname 2 "Animation"

-- Zero Out Rotation
rotL= rotation_list()
shpsPR[i].rotation.controller= rotL
shpsPR[i].rotation.controller.available.controller= euler_xyz()
rotL.setactive 2
rotL.setname 1 "Zero"
rotL.setname 2 "Animation"

Error Message:
-- Error occurred in i loop; filename: C:\Documents and Settings\guillaume.boucher\Desktop\zero out.ms; position: 272
-- Frame:
-- i: 62
-- rotL: undefined
-- posL: Controller:Position_List
-- called in zeroOutControllers(); filename: C:\Documents and Settings\guillaume.boucher\Desktop\zero out.ms; position: 665
-- Frame:
-- shpsPR: #($Shape_COM, $Shape_Shoulder_Right_FK, $Shape_Arm_Right_FK, $Shape_Elbow_Right_FK, $Shape_Hand_Right_FK, $Shape_Shoulder_Left_FK, $Shape_Arm_Left_FK, $Shape_Elbow_Left_FK, $Shape_Hand_Left_FK, $Shape_SpineBottom_FK, $Shape_SpineMiddle_FK, $Shape_SpineTop_FK, $Shape_Leg_Right_FK, $Shape_Calf_Right_FK, $Shape_Foot_Right_FK, $Shape_FootToes_Right_FK, $Shape_Leg_Left_FK, $Shape_Calf_Left_FK, $Shape_Foot_Left_FK, $Shape_FootToes_Left_FK, ...)
-- Unknown property: "pos" in undefined

01-21-2009, 09:48 PM
Never mind guys, everything is fine. Thanks everyone :)

CGTalk Moderation
01-21-2009, 09:48 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.