Load Scene Materials with Unique Suffix in Listbox

Hello --

1- I want to create listbox to only load scenematerials with name plus suffix "CPT", "WD", etc.

2- double click : Apply material to object / objects selected.

3- create button to load selected material from listbox to material editor.

Thanks in advance!

rollout drop_roll "Drop Down List" width:162 height:170
(
 local obj_array = #()
	button updt "update" pos:[67,7] width:49 height:21
	listbox mat_dd "Objects :" pos:[13,13] width:136 height:10
 
	fn update_objs =
	( 
		mat_array = scenematerials 
		mat_dd.items = for i in mat_array collect i.name
	)
 
	on drop_roll open do
		update_objs()
	on updt pressed do
		update_objs() -- update list, if object has been deleted or added again in scene
	on mat_dd doubleClicked sel do
		select mat_array[i]
)
 
createDialog drop_roll

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

I hope that this tool contains all tree requests

;)

try(destroyDialog ::drop_roll)catch()
rollout drop_roll "Drop Down List"
(
	edittext et_prefix "Prefix:" pos:[5,5] fieldwidth:100 height:17 text:"CPT"
	button btn_upd "U" pos:[142,5] width:17 height:17 tooltip:"Update Listbox"
	listbox lb_scenemtls "Objects Materials:" pos:[5,24] width:152 height:10
	button btn_load "Load In M.E." pos:[5,178] width:152 height:18 tooltip:"Update Listbox"
	fn update_objs lbox:lb_scenemtls prx:et_prefix.text=
	( 
		lbox.items = if scenematerials.count == 0 then #() else
		(
			if (txt = et_prefix.text) == "" then for m in scenematerials collect m.name else 
				for m in scenematerials where substring m.name 1 txt.count == txt collect m.name
		)
	)
	on drop_roll open do update_objs()
	on btn_upd pressed do update_objs()
	on lb_scenemtls doubleClicked idx do
	(
		if selection.count == 0 then messageBox "Select some objects first!" title:"Warning" beep:off else
			selection.material = scenematerials[lb_scenemtls.selected]
	)
	on btn_load pressed do if lb_scenemtls.items.count != 0 and isKindOf lb_scenemtls.selected String do 
		meditmaterials[activeMeditSlot] = scenematerials[lb_scenemtls.selected]
)
createDialog drop_roll 162 200 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

xathletic01x's picture

Respect! Thank you :)

Respect! Thank you :)

barigazy's picture

...

If prefix not exists you will load by pressing "U" button all scene material or (if exists) materials with prefix.
Another suggestion:
When you need to work on selected objects always check selection count to avoid errors. You will see this in my code not only for objects but for other stuffs.
Cheers!

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.