View Full Version : request: Object-color to diffuse color-script
buzzz3d 10-31-2008, 04:04 PM A have a number of scenes where a lot of objects have no material assigned but just an object color.
I have to find the object that have no material assigned, assign a seperate blinn material to each object en copy the object color to the diffuse color of the new material.
After a while this gets a bit tiring :)
I'm quite a max-script noob but is it possible to make a script for this and if so can someone point me in the right direction?
Thanks in advance.
|
|
Kameleon
10-31-2008, 04:17 PM
Will this do the trick?
for i in selection do
(
if i.material==undefined then
(
thecolor=i.wirecolor
themat=standardMaterial()
themat.name=i.name
themat.diffuse=thecolor
i.material=themat
)
)
Cheers!
Kramsurfer
10-31-2008, 06:31 PM
If you've many objects... I would use this.. the one above makes a new material for each object, this one makes a material only when needed and instances the material based on wirecolor via the name...
for SelObj in Selection do
(
if ( hasproperty SelObj #material ) then
if ( SelObj.material == undefined ) then
(
-- Creates name for material base on wirecolor
local tnMatName = ("ColorMat-" + (SelObj.wireColor as string ))
-- Makes an array of materials with same name, should only be one per scene
local IsInScene = for chkMat in SceneMaterials where (chkMat.name == tnMatName) collect chkMat
-- if array is empty make new material and assign, else apply material found in scene
if ( IsInScene.count == 0 ) then
SelObj.material = StandardMaterial name:tnMatName Diffusecolor:SelObj.wireColor
else
SelObj.material = IsInScene[1]
)
)
buzzz3d
11-01-2008, 09:01 PM
Thanks guys! Kameleons script works for me, excellent timesaver.
Kramsurfer, somehow I couldn't get your script to work but I'm probable doing something wrong. I saved the script as a .ms file, selected the objects without a material and executed the script by choosing Run maxscript ans selecting the .ms file.
If I'm doing something wrong please let me know. Thanks for your time!
Kramsurfer
11-02-2008, 07:13 PM
Sorry, I wrote it without access to 3dsmax to test it..
The first if shouldv'e been IsProperty instead of hasProperty...
for SelObj in Selection do
(
if ( isproperty SelObj #material ) then
if ( SelObj.material == undefined ) then
(
-- Creates name for material base on wirecolor
local tnMatName = ("ColorMat-" + (SelObj.wireColor as string ))
-- Makes an array of materials with same name, should only be one per scene
local IsInScene = for chkMat in SceneMaterials where (chkMat.name == tnMatName) collect chkMat
-- if array is empty make new material and assign, else apply material found in scene
if ( IsInScene.count == 0 ) then
SelObj.material = StandardMaterial name:tnMatName Diffusecolor:SelObj.wireColor
else
SelObj.material = IsInScene[1]
)
)
buzzz3d
11-02-2008, 07:17 PM
Thanks Keith. Don't have access to max at the moment but I'll try it first thing tomorrow!
Update: Tested the script and it workd like a charm now. Thanks!
CGTalk Moderation
11-02-2008, 07:17 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.