ScriptSpot

Forum topic · General Scripting

help with script

By lucky_lowell · 2011-10-14

Description

In part of my script I am trying to find all the groups in the scene.

So as a novice I've tried this.
I open up the max file and pick one of the groups I have
In the listener I type in the following

classof $
ObjectSet --get back this

I then try this but it doesn't seem to work.
I'm looking for a list of names I can populate a dropdown list

sceneGroups = for obj in geometry
where classof obj == ObjectSet
collect obj
#() --get back this

sceneGroups.count
0 --get back this

I have been through the Maxscript reference but can't find the proper syntax.
any ideas?
thanks Lowell

Comments (7)

tassel · 2011-10-18

Ok, something like this? Anubis, do you have a nicer way to do this?? :D


try(destroyDialog GroupSelector)catch()
 
rollout GroupSelector "Lazy Group Selector"
(
	button btn_UpdateGroups "Update" Width:150 height:25 align:#center
	group "Select Group:"
		(
			dropdownlist DD_Group "" items:#()
		)
	
	local allObj = #()
	local Groups_Array = #()
		
	fn Update_Groups =
         (
			allObj = objects -- as array
			Groups_Array = for i in allObj where (isGroupHead i and isValidNode i) collect i -- as string
			DD_Group.items = for i in allObj where (isGroupHead i and isValidNode i) collect i.name -- as string
        )
       
	on GroupSelector open do Update_Groups()
	on DD_Group selected i do select Groups_Array[i]
	on btn_UpdateGroups pressed do Update_Groups()
 )
 
createDialog GroupSelector

RE: Anubis, do you have a nicer way to do this?? :D

Anubis · 2011-10-19

Hey, you did it well ;) If you ask for tips... I think that storing all objects not necessary, and as you loop in objects collection - you can omit isValidNode as well.

local Groups_Array = #()

fn Update_Groups =
(
	Groups_Array = for o in objects where isGroupHead o collect o
	DD_Group.items = for o in Groups_Array collect o.name
)

tassel · 2011-10-19

Ahh.. Thank you for the information Anubis :)

to continue...

lucky_lowell · 2011-10-19

I added this line to create a copy of the selection

maxOps.cloneNodes (getNodeByName DD_Group.selected) cloneType:#copy newNodes:&nnl

I get a copy of the group incremented by one digit.

Now I would like to rename it. but again the syntax eludes me.

this is killing me..
I thought I would try this... but its no good.
theCopy = maxOps.cloneNodes (getNodeByName DD_Group.selected) cloneType:#copy newNodes:&nnl

theCopy.name = "new_name"

thanks for your help

Anubis · 2011-10-19

Renaming objects is a large subject (with "many faces", you know ;) ), so better open new thread and describe there in details what exactly your renaming would like.

Something like this?select

tassel · 2011-10-14

Something like this?


select (for o in selection where isValidNode o AND isGroupHead o collect o)

EDIT: Ahh.. Sorry, Did not read your post properly the first time

Here is an Example:


rollout Dropdownlist "Choose Group"
(
dropDownList dl_Dropdownlist "Choose Group" items:(for i in selection where (isGroupHead i) collect i.name as string)
)

createdialog Dropdownlist witdh:220

Just change

for i in selection

with

for i in objects

if you want it to select all objects in scene.

Ray,Sweet website. Thanks

lucky_lowell · 2011-10-17

Ray,
Sweet website. Thanks for replying. The behavior I'm getting is close but not complete. I only get an item in this drop down list if its preselected. Otherwise nothing.
thanks
Lowell

I changed the line from selection to objects and it works fine thanks again.

rollout Dropdownlist "Choose Group"
(
dropDownList dl_Dropdownlist "Choose Group" items:(for i in objects where (isGroupHead i) collect i.name as string)
)

createdialog Dropdownlist witdh:220