[Closed] For loop breaks code??
Hi all,
I'm still very very new with maxscript and I code on and off, so please bear with me.
I'm trying to do a simple script which creates a clone of some objects in an array and then aligns it to another object. However I notice when I append my array, it crashes max?? Works fine as long as I don't append my array??? What is causing the crash I can't figure it out??
Thanks
WallTypes = $Wall* as array
GuideMap = $Line* as array
-- append WallTypes $Door*
-- append WallTypes $Window*
for i = 1 to GuideMap.count do
(
print WallTypes[i]
-- print i
r = random 1 WallTypes.count
--
NewWall = instance WallTypes[r]
NewWall.transform = GuideMap[i].transform
)
)
You can’t append array with array. Only U can JOIN them.
In mxs help you can find very nice description of array values.
Try this way
WallTypes = join (join ($'Wall*' as array) ($'Door*' as array)) ($'Window*' as array)
GuideMap = $'Line*' as array
for i = 1 to GuideMap.count do
(
r = random 1 WallTypes.count
NewWall = instance WallTypes[r]
NewWall.transform = GuideMap[i].transform
)
why not? it’s OK to append an array, but the problem in our case is that we try to append a node collection. that’s what we can’t append.
and… we don’t have to cast node collection to array to join it with an array.
so the might look as:
join (join (join #() $wall*) $door*) $window*
there is another way to combine collections:
($wall* as array) + ($door* as array) + ($window* as array)
Thank you so much!!
I missed that completely! Should have double checked the max file, all I was looking for was append.
Really helped!
Now on to more problems I guess
Thanks!
Thanks Denis! I really need to brush up on my syntax, there is so many ways to do things…
Can I borrow your brain for a day…I promise I’ll give it back
Just curious, would it bother you to see someone take advantage of implicit type conversion and write the second example as:
$wall* as array + $door* + $window*
or maybe even (especially in cases where casting to array doesn’t work, like children array, multi-sub material, scenematerials and so on):
#() + $wall* + $door* + $window*
After all, it matches the first example much better.
the first way is better.
#1 it uses less memory
#2 it universally works for any collections including objectsets, pathname selections, selectionsets, children, … and of course just simple arrays.
No doubt about #1, anyway the #() + $wall* + $door* + $window* [font=Courier New][/font] form works for #2 just as well (and doesn’t look as LISPy ).