Notifications
Clear all

[Closed] MAX_Script_Help – > Creating Groups By Selection

Hey Everyone,

I am fairly new to MaxScript and I am working on creating a console of sorts. I have built a very crude GUI for some pretty basic actions. However I am stuck on a particular one that I just cant figure out.

Is there a way to create a button, that creates a group from a selection of objects in a scene? This is tricky because its the opposite of how it would normally get done. In other words,

Select a number of objects in the scene with “Rectangular selection region tool” then > run a script that automatically creates a group based on the selection. Would be awesome if it created a button, then it asks “what would you like to call this group?”

That way, whenever I need to recall that group I just press the newly created button.

The way I have this set up now, I select the group, copy and paste that selection from listener in a prebuilt set of code. I am trying to make it so the group is automatically created. =

on GrpPalletViper pressed do – input your selection for this group!
(
Select #($ViperLight005,
$ViperLight002,
$ViperLight004,
$ViperLight003,
$ViperLight,
$ViperLight001)
)

If you know how to do this please let me know, and thank you in advance!

11 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

my question is – do you want to know how to make a code that does do what you want? or … do you just want a code that does do it?

for example… there is a solution shown abode. i’m pretty sure it works. is it enough?

Try this:

try destroydialog GroupCreator catch()

fn getuserstring default:"Groupname" =
(
	RenameDialog = dotNetObject "MaxCustomControls.RenameInstanceDialog" default
	DialogResult = RenameDialog.Showmodal()
	dotnet.compareenums RenameDialog.DialogResult ((dotnetclass "System.Windows.Forms.DialogResult").OK)
	Outputstring = RenameDialog.InstanceName
	Outputstring
)

rollout GroupCreator "---"
(
	local mygroup
	
	button BTN_MakeGroup "Make Group"
	
	on BTN_MakeGroup pressed do
	(
		if mygroup == undefined then
		(
			mygroup = group selection name:(getuserstring default:"Groupname") select:true
		)
		else select mygroup
	)
)

createdialog GroupCreator

Note:
The dotnetdialog for renaming is originally not mine, i found it here on the forum iirc.

Hey guys,

Thanks for the quick reply!,

Heilandzack – So this is really close, however I realize I wasn’t being really clear on what I am trying to accomplish. I am not actually trying to build “Groups” I am trying to make a button that selects certain objects.

For example:

Select a number of objects in the scene with “Rectangular selection region tool” then > run a script that automatically creates a selection button based on the objects I have selected . That way, when I press the button that the script created, It will automatically select those objects.

This is what the final result would look like:

– Create a Scene with eight generic Standard free spot lights then run this script!

try(destroyDialog test)catch()

rollout test “Test” width:191 height:73
(
button btn1 “Grp1” pos:[11,10] width:50 height:50

button btn2 "Grp2" pos:[74,10] width:50 height:50

button btn5 "Deselect" pos:[135,9] width:50 height:50

on btn1 pressed do
(
	select #($Fspot003, $Fspot002, $Fspot007, $Fspot006)
)
on btn2 pressed do
(
	select #($Fspot004, $Fspot001, $Fspot005,$Fspot008)
)

on btn5 pressed do 
(
	clearSelection()
)

)

Createdialog Test

The problem here though is I have to manually input the selections into the script. I want to make a script that will input these selections based on what I have manually grabbed in the scene. I hope that makes sense.

Why you don’t use the Named Selection Set? You can create as many selSets as you want and won’t be limited by the UI of the script.

But:
-craete separate variable for each button. This variable will holds the selected objects.
-when you press the button the script will check if this variable is a collection of obejcts(an array). If it is not – put the selected objects to the variable. If the variable is an array – select all objects in this array.
You can add some visual feedback to tell you which button will select obejcts.


(
	try(destroyDialog test)catch()
	rollout test "Test" width:191 height:73
	(
		local grp1Arr = undefined
		local grp2Arr = undefined
		
		button btn1 "Grp1" pos:[11,10] width:50 height:50
		button btn2 "Grp2" pos:[74,10] width:50 height:50
		button btn5 "Deselect" pos:[135,9] width:50 height:50
		
		function StoreSelection =
		(
			if selection.count != 0 do
				arr = selection as array
		)
		
		on btn1 pressed do
		(
			if grp1Arr == undefined then
				grp1Arr = StoreSelection()
			else
				select grp1Arr
			
		)
		on btn2 pressed do
		(
			if grp2Arr == undefined then
				grp2Arr = StoreSelection()
			else
				select grp2Arr
			
		)
		on btn5 pressed do
		(
			clearSelection()
		)
	)
	Createdialog Test
)

Hey Miauu

I really like this option, if I understand it correctly the action would be. ” Select the objects in the scene, then press the button” <- the button saves whatever is selected as the variable and then plays it back whenever pressed.

In this scenario it would be very beneficial for the button to ask “what would you like to name this button” (referring to the selection of objects that have just been selected)

Now, how the heck would you program that? I am way way too green, but I am learning. = )

1 Reply
(@miauu)
Joined: 11 months ago

Posts: 0

Something like this:


(
	try(destroyDialog test)catch()
	rollout test "Test" width:191 height:83
	(
		local grp1Arr = undefined
		local grp2Arr = undefined
		local curBtn = undefined
		
		button btn1 "Grp1" pos:[11,10] width:50 height:50
		button btn2 "Grp2" pos:[74,10] width:50 height:50
		button btn5 "Deselect" pos:[135,9] width:50 height:50
		edittext et_btnName "" text:"" bold:true readOnly:true
		
		function StoreSelection =
		(
			if selection.count != 0 do
				arr = selection as array
		)
		function SetButtonName btn: =
		(
			et_btnName.readOnly = false
			curBtn = btn
			setFocus et_btnName
		)
		
		on et_btnName entered txt do
		(
			curBtn.text = txt
			et_btnName.text = ""
			et_btnName.readOnly = true 
		)
		
		on btn1 pressed do
		(
			if grp1Arr == undefined then
			(
				grp1Arr = StoreSelection()				
				SetButtonName btn:btn1
			)
			else
				select grp1Arr
			
		)
		on btn2 pressed do
		(
			if grp2Arr == undefined then
			(
				grp2Arr = StoreSelection()
				SetButtonName btn:btn2
			)
			else
				select grp2Arr
			
		)
		on btn5 pressed do
		(
			clearSelection()
		)
	)
	Createdialog Test
)

When you press the button the text field will become editable and you ca write the name of the button directly after pressing the button. No need to click in the text field. When you press the ENTER key to set the new name to the button the text field will become non editable.
But, with this method you can’t store new obejcts to already used button. You can add
on btn1 rightClick do
to clear the variable that holds the obejcts for the clicked button and then to be able with lefr click on the button to store new obejcts.

I still think that the NamedSelectionSet is a better solution. You can have the UI as separate window and much more options. The named selectionsets are saved with the scene and so on.

Hey Miauu

Woah, this is perfect! I know it seems like a weird way to do things, but this coincides with how lighting programming works. So from that point of view its a much more organic transition from lighting console to 3Ds GUI.

I have a few other interesting problems I need solved as well. I will start a new thread as I continue to work on this project.

Thank you!

try (destroydialog CollectSelSet) catch()
rollout CollectSelSet "Collect SelSet" width:204
(
	edittext selset_name_ed "Selection Set Name:" labelOnTop:on fieldwidth:190 align:#left offset:[-5,0]
	button collect_bt "Collect" width:190 align:#left offset:[-5,4] \
		tooltip:"Add Selection To Selection Set
 + CTRL	 - Replace"
	
	on collect_bt pressed do undo "Collect SelSet" on 
	(
		if (name = selset_name_ed.text) != "" do
		(
			nodes = selection as array
			if (selectionSets[name] == undefined) or keyboard.controlpressed then selectionSets[name] = nodes
			else
			(
				selectionSets[name] = join nodes selectionSets[name]
			)
		)
	)
)
createdialog CollectSelSet
1 Reply
(@miauu)
Joined: 11 months ago

Posts: 0

I’ve thought to offer him a solution with editText field and listbox. He can select the objects, enter the name, hit Enter and in the listbox will appear the newly created selSet. Then: doubleclick the desired name in the listbox to select the objects, rightclick to remove from the list. But, it seems the he prefers to use buttons.

finally i would cool to have ‘full service’ (list, add, remove, rename, find, etc.). but currently it would be too advenced.

list is cool, but its most problem is reverse setup – when selset added, deleted, renamed, etc. not in the tool, or/and undo/redo related to selsets was happened

1 Reply
(@miauu)
Joined: 11 months ago

Posts: 0

That’s why I prefer the built-in NamedSelectionSets.