[Closed] Stuck on simple array append
Hi all,
Apologies if this question is basic, but I am stuck and I don’t know why.
So I wanted to pass an array of objects to a function to attach them. I specifically want 3 objects so I want to append them manually however it does not seem to work. What have I missed??
The function is called clusterAttach
3 Objects are Sphere001 Sphere002 Sphere003
–create empty array
AttachArray = #()
–create button
button attach_btn “<” pos:[70,55]
–add button function
on attach_btnpressed do
(
append AttachArray $Sphere001 $Sphere002 $Sphere003
clusterAttach AttachArray
)
Any help appreciated.
append can have only two arguments: append <array> <value>
To append to array:
append AttachArray $Sphere001
append AttachArray $Sphere002
append AttachArray $Sphere003
Since you know the obejcts that will be attached, you don’t need to append them to an array.
--add button function
on attach_btnpressed do
(
AttachArray = #($Sphere001, $Sphere002, $Sphere003)
clusterAttach AttachArray
)
If you want to have all spheres in array then you can use
sphereArr = $Sphere* as array
the append function only takes 1 item at a time so that won’t work as is.
you can either use
append AttachArray $Sphere001
append AttachArray $Sphere002
append AttachArray $Sphere003
or do something more fancy like this.
src_objects= #($Sphere001, $Sphere002, $Sphere003)
for obj in src_objects do
(
print ("adding: " + obj.name)
append AttachArray obj
)
The above loops trough the src array and performs the inner loop for each item with ‘obj’ being the current item.
IF you want to add the current selection to the array try using this line in the code:
src_objects = selection as array
edit: Miauu beat me to it
Thanks so much, really appreciate it! I am lucky the maxscript community is friendly I get so stuck but there is always help!
Thanks for also showing me the other ways to approach this!
if you dont want to modify the original arrays, just add those arrays ( aka the “third” method )
arrayC = arrayA + arrayB
of course this uses more memory than join and is slower