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
Forum topic · Scripts Wanted
By CGA · 2014-09-11
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
.
miauu · 2014-09-14
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 · 2014-09-14
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 · 2014-09-14
Now works fine, I just add this string:
tempMatLib = loadMaterialLibrary"my material path"
.
miauu · 2014-09-14
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 · 2014-09-14
------------------------------
.
miauu · 2014-09-14
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 · 2014-09-14
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 · 2014-09-12
The Material Library will be already loaded, or the script have to load it from .mat file?
CGA · 2014-09-12
Yes, the Material Library will be already loaded, just need to find the object(geometry) by name and after put material.
.
miauu · 2014-09-12
What is the name of the material library?
CGA · 2014-09-12
New Library.mat
CGA · 2014-09-14
...