PDA

View Full Version : Maxscript (noob) question


MartinAndersen
05-15-2003, 12:00 AM
what is the smartest way to handle a lot of objects... like hide them all with script???

something like this?::


array myObjects ("obj1"," obj2"," obj3")

for myObjects +1 do myObjects hide




How do I do ??




dammit I'm not that hardcore scripter :thumbsdow !!!

Bobo
05-15-2003, 12:07 AM
Originally posted by MartinAndersen
what is the smartest way to handle a lot of objects... like hide them all with script???

something like this?::


array myObjects ("obj1"," obj2"," obj3")

for myObjects +1 do myObjects hide






Depends on where you get the objects from...

You can say

myObjects = #($Obj01,$Obj02,$Obj03 )
hide myObjects

If the names are accessible through a pattern, you can use wildcards like

hide $Obj*

Generally, you don't need to loop through arrays when the function you want to use (like Hide) is "Mappable" - in other words, it loops internally over all objects when the argument is a list or collection of objects...

The correct format of FOR loop would be

for i in myObjects do hide i

or

for i in $Obj* do hide i

You can create an array (for later usage) by using "collect" instead of "do".

myObjects = for i in $Obj* collect i

or

myObjects = $Obj* as array


There are 1000 ways to do things in MAXScript and all of them have their usage. :)

For example, you can filter objects by some property while collecting by using "where"

myObjects = for i in $Obj* where classof i == Box collect i

It will collect obly those objects with name "Obj*" that are boxes.


Please ask your questions if you have anything specific you want to achieve...

MartinAndersen
05-15-2003, 01:36 AM
Thanks alot bobo, there is always a better way to do things, than my way... hehe first my code looked like this:

hide $object01
hide $object02
hide $object03
hide $object03
hide $object04
hide $object05
hide....etc.

That is kind of a stupid way to do it... :applause:

So I can just start learning the best ways now :-)
This one is very good:

myObjects = #($Obj01,$Obj02,$Obj03 )
hide myObjects

Thanks a million times Bobo :thumbsup: :D

Kramsurfer
06-03-2003, 04:45 PM
$'Obj*'.ishidden=true

Will hide all objects with "Obj" as the first three characters of their name.

Enjoy
Keith Morrison

CGTalk Moderation
01-15-2006, 04:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.