Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Ok instead of array

Ok instead of array

Anonymous
Not applicable
335 Views
5 Replies
Message 1 of 6

Ok instead of array

Anonymous
Not applicable
I am trying to filter a group of objects by a modifier name but when I try to collect the loop as an array, it gives me an "ok" instead of an array.

here's the line:

for o in objects do for m in o.modifiers where m.name == "universalUVW" collect o

please if someone can throw some light there I would really appreciate it.

I tryed to refine it eaven further by filtering first the modifier class and then the name but that didn't work either, just out of curiosity, if someone knows why this isn't working, please tell me.
Tank you.

for o in objects do for m in o.modifiers where classof m == UVWunwrap do for i in m where i.name == "universalUVW" collect o

Thank you.
0 Likes
336 Views
5 Replies
Replies (5)
Message 2 of 6

Steve_Curley
Mentor
Mentor
Several "problems" with that as it stands.

To collect with a for you need an array (collection variable) to collect into, e.g.

myList = for o in objects where <whatever> collect o

Secondly, you have a nested loop so any collection created in the inner loop will overwrite the collection created in the previous iteration. If the last object does not have a <specified type of modifer> then the collection will be empty.

Finally, don't do it by Name - modifiers can be renamed (by the user) and so will fail the test and not be included in the collection.

Try this.


uv = #()
for o in objects do
(
tmp = for m in o.modifiers where ((classof m) == Unwrap_UVW) collect m
join uv tmp
)
print uv

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 6

Anonymous
Not applicable
Thank you very much for your response, I am really new to scripting, so I hope you don't mind if I ask you a couple of questions:

1) when I say "do print o" instead of "collect o" in

for o in objects do for m in o.modifiers where m.name == “universalUVW” collect o

it will print all of the objects, but in "collect" it says that it can't convert "ok" to an array, do you know why doesn't it gives me an array instead of ok?

2) what is a specified type of modifer?

3)in the line
" tmp = for m in o.modifiers where ((classof m) == Unwrap_UVW) collect m join uv tmp"

how can I do if I have more than one unwrap in some objects and I just want to pick the ones with the name “universalUVW”?

I hope I'm not abusing of your time with this questions, I would appreciate a lot if you could help me with this.

thank you very much.
0 Likes
Message 4 of 6

Anonymous
Not applicable
for o in objects where \
(for m in o.modifiers where m.name == “universalUVW” collect m).count > 0 collect o

Basically, the inner loop checks every modifier in the current object o by name and if the name matches, it collects it.
Once all modifiers have been collected, the outer loop uses the boolean value produced by the comparison of the resulting modifiers array's count with 0 - if there was at least one modifier with that name, the result is true and the object o gets collected by the outer loop!

As you had it, the outer loop was perfoming a FOR o in objects DO() loop and wasn't collecting anything. The inside loop was collecting the object for each modifier that matches the name, but the final result wasn't an array because you were just DOing and not COLLECTING with the outer loop...

Also note that saying

... where matchPattern m.name pattern:"universalUVW" collect ...

will allow you to perform a case-insensitive test, and the pattern matching tends to be really fast, too. Also, it would allow you to do wildcard patterns if you even need to find modifiers by partial name specification like "universal*" ... Just an idea.

Hope this helps...
0 Likes
Message 5 of 6

Anonymous
Not applicable
Tank you very much, this was of great help, now I understand perfectly what was happening.
0 Likes
Message 6 of 6

Steve_Curley
Mentor
Mentor
Sorry I didn't get back to you earlier - real fife (and different timezones) got in the way.

Bobo:- thanks for the explanation 🙂

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes