Select object by name & put material

Who can help? i need a script which will be able to select object by name and also put material by name from the material library

Thanks a lot

Comments

Comment viewing options

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

.

Try this.
The loaded material library must be set as current material library. Otherwise the script will not find the materials from the library.
Use the Refresh button when new objects are added to the scene or when the current material library is changed while the script is still running.

(
	global rol_TEST
	try (destroyDialog rol_TEST) catch()
 
	rollout rol_TEST "TEST"
	(
		local objsArr = objects as array
		local objsNameArr = for o in objsArr collect o.name
 
		dropdownList ddl1 " COLOR 1" pos:[16,17] width:114 height:40 items:#()
		dropdownList ddl7 " COLOR 2" pos:[176,17] width:114 height:40 items:#()
		dropdownList ddl8 " COLOR 3" pos:[336,16] width:114 height:40 items:#()
		dropdownList ddl9 " OBJECT1" pos:[16,80] width:114 height:40 items:objsNameArr
		dropdownList ddl10 " OBJECT2" pos:[176,80] width:114 height:40 items:objsNameArr
		dropdownList ddl11 " OBJECT3" pos:[336,80] width:114 height:40 items:objsNameArr
 
		GroupBox grp1 "" pos:[168,8] width:126 height:120
		GroupBox grp4 "" pos:[8,8] width:127 height:120
		GroupBox grp5 "" pos:[328,8] width:127 height:120
		button btn16 "OK" width:176 height:25 across:2
		button btn_refresh "REFRESH" width:176 height:25
 
		on btn16 pressed do
		(
			for i = 1 to objsNameArr.count do
			(
				case objsNameArr[i] of
				(
					(ddl9.selected): (objsArr[i].material = currentMaterialLibrary[ddl1.selection])
					(ddl10.selected): (objsArr[i].material = currentMaterialLibrary[ddl7.selection])
					(ddl11.selected): (objsArr[i].material = currentMaterialLibrary[ddl8.selection])
				)
			)
		)
 
		on btn_refresh pressed do
		(
			ddl1.items = ddl7.items = ddl8.items = (for m in currentMaterialLibrary collect m.name)
		)
 
		on rol_TEST open do
		(
			if currentMaterialLibrary.count != 0 then
			(
				objsArr = objects as array
				objsNameArr = for o in objsArr collect o.name
				ddl1.items = ddl7.items = ddl8.items = (for m in currentMaterialLibrary collect m.name)
			)	
			else
				messagebox "Current material library is empty" title:""
		)
	)
 
	createDialog rol_TEST height:180 width:460 pos:[1080,130] 
)
CGA's picture

....

Now works fine, I just add this string:
tempMatLib = loadMaterialLibrary"my material path"

miauu's picture

.

The reason for the error is that your current material library is empty. Using the loadMaterialLibrary makes the "my material path" library the current material library and the script works.

CGA's picture

 Thanks you for this script

Thanks you for this script but could you explain clearly why i got this message?

plz see attachment
http://s11.postimg.org/iqwc0jqar/image.jpg

CGA's picture

...

------------------------------

miauu's picture

.

If the name of the object is "yellow", which material with what name from the matLib have to be assigned to the object?

Or you want a script with an UI where you can put:
- name of the object
- name of the material to be assigned

Then the script will get the material by the name that you have entered and will assign it to all objects with givven name.

CGA's picture

...

i need UI like this:

try (destroyDialog ::rol_TEST) catch()

rollout rol_TEST "TEST"
(

dropdownList ddl1 " COLOR 1" pos:[16,17] width:114 height:40 items:#("RED", "GREEN", "BLUE")
dropdownList ddl7 " COLOR 2" pos:[176,17] width:114 height:40 items:#("RED", "GREEN", "BLUE")
dropdownList ddl8 " COLOR 3" pos:[336,16] width:114 height:40 items:#("RED", "GREEN", "BLUE")
dropdownList ddl9 " OBJECT1" pos:[16,80] width:114 height:40 items:#("OBJECT1", "OBJECT2", "OBJECT3")
dropdownList ddl10 " OBJECT2" pos:[176,80] width:114 height:40 items:#("OBJECT1", "OBJECT2", "OBJECT3")
dropdownList ddl11 " OBJECT3" pos:[336,80] width:114 height:40 items:#("OBJECT1", "OBJECT2", "OBJECT3")

GroupBox grp1 "" pos:[168,8] width:126 height:120
GroupBox grp4 "" pos:[8,8] width:127 height:120
GroupBox grp5 "" pos:[328,8] width:127 height:120
button btn16 "OK" pos:[144,141] width:176 height:25

)

createDialog rol_TEST height:180 width:460 pos:[1080,130]

BUT THE COLORS WILL BE TAKE FROM MAT LIBRARY AND THE NAMES OF GEOMETRY FROM THE SCENE

miauu's picture

.

The Material Library will be already loaded, or the script have to load it from .mat file?

CGA's picture

Yes, the Material Library will be already loaded

Yes, the Material Library will be already loaded, just need to find the object(geometry) by name and after put material.

miauu's picture

.

What is the name of the material library?

Comment viewing options

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