[Closed] selection as array without opening groups?
Hi there, for my script (second one im writing) i need to turn my selection into an array, and after that those objects will be scattered. Now what i used is “selection as array”, but that takes all of the objects in groups as single objects, not keeping them together, so when you have 20 groups with in them 10 objects, you get 200 elements in the array, while id like only 20 to be in.
I hope someone can help me with this problem, i just dont get it anymore
here is a piece of my code:
sel = selection as array – selected objects put into array
fn compareFN a b = – function that gives the objects in the array random values, to –sort them in a random way
(
local d = (random 1 10) – (random 1 10)
case of
(
(d < 0.): -1
(d > 0.): 1
default: 0
)
)
qsort sel compareFN – all the objects in the array are sorted by random numbers
tel = sel.count – variable that gives the ammount of objects in the array
– the rest of the code will place the objects on a “grid” (comments in dutch)
for y = 1 to (tel/ValX)
do
(
for x = 1 to ValX
do
(
q = x + (ValX*y) – ValX – de losse objecten worden per stuk geselecteerd, tot de laatste lijn
sel[q].pos = [(AfstandX * x)+ OffsetX,(AfstandY * y)+ OffsetY,(AfstandZ * y)+ OffsetZ]
for q = (((tel/ValX) * ValX)+1) to tel -- de laatste lijn is soms niet vol, en word daarom appart geselecteerd
do
(
sel[q].pos = [(AfstandX * (q - (tel/valx * valx)))+ OffsetX,(AfstandY * (y+1))+ OffsetY,(AfstandZ * (y+1))+ OffsetZ]
)
)
)
Hi,
groups are considered as dummys.
so to collect only groups you could use:
[size=2]sel=for i in selection as array where classof i==dummy collect i
althoug this would also collect ‘real’ dummy objects
i don’t know of a way to distinguish between groups and dummy objects.
(although you could check against the name and remove all dummies with name: dummy*
else, attach the objects instead of grouping !
[/size]
True, you would then collect all dummy objects. You would also not collect any non-dummy objects, which may or may not be desired. Also, if there are any groups whose group head is not a dummy (possible only through maxscript), they would not be collected. A somewhat more robust expression would be the following:
sel = for o in selection where isGroupHead o or not isGroupMember o collect o
RH
Wow, that was fast
Thanks a lot, never would have made that up myself (yet).
Really thx a lot, this script has improved my workflow a lot