I've been trying to get my head around some max script where I have a loop and I want to create and populate some arrays within the loop. I already have an array which I can use to name.
-- get all object names
Allobjects = for g in geometry collect g.name
-- get base object names
for a=1 to Allobjects.count do
(
s = filterString Allobjects[a] "z"
appendIfUnique NamesArray s[1]
)
for n=1 to NamesArray.count do
(
tempArray[n] = #()
for g in geometry do
(
if (findstring g.name NamesArray[n] !=undefined) do append tempArray[n] g
)
print tempArray[n]
)
I know that tempArray[n] = #() doesn't work but I thought it's pretty clear what I'm trying to do there.
The backstory:- I have a scene with objects that also have copies in it named in the following fashion aaaaaZ,aaaaaZ01,aaaaaZ02,bbbbbZ,bbbbbZ01,bbbbbZ02. Where aaaaaZ and bbbbbZ are different objects and things with 01, 02 are copies of the original objects. My objective is to have an array for each object which stores the object and it's copies.
So:
aaaaaArray = #(aaaaaZ,aaaaaZ01,aaaaaZ02...)
bbbbbArray = #(bbbbbZ,bbbbbZ01,bbbbbZ02...)
The array should contain the actual objects not just their names as I want to do further things with them later. I hope that's clear in what I'm trying to achieve.
PS the Z in the object name is there purely so it's easy to pick out the copies. Some of the object names will have numbers at the end so having a Z helps here.
Replies
The array contain the actual objects.
Cheers dude, that allowed me to access the objects quicker than the string filtering but I was after generating the array names dynamically. I'm not sure if that's possible so I managed to get around it by using a temporary array and filling that in a loop instead. It means I have to do a few more calculations each time it loops through but I can't see a way around it apart from maybe using execute which I didn't really want to do.
This is how I would do what you are trying:
this collects the stuff in the loop which matches the criteria after the 'where' clause into the array b.
I'd read that using execute should be avoided unless really necessary but I don't know the reasons why. I'm guessing performance.