[Closed] material change by name
[b].diffuse[/b] is not a material, it is actually a color. It is the color applied to the object when no map exists. You actually want "meditMaterials[i].diffuseMap = noMaterial()"
While testing your code, I had lots of issues with referencing the materials array using a string, so I'd recommend, rather then using "sName", use "i"
meditMaterials[sName][#materialList].diffuseMap = Bitmaptexture fileName:"E:\3dsmax9\maps\uvtex.png"
Should read
meditMaterials[i].baseMaterial.diffusemap = (Bitmaptexture fileName:"E:\3dsmax9\maps\uvtex.png")
meditMaterials[sName][#materialList][#Maps][#Diffuse_Color__Map__1__uvtex_png].alphaSource = 2
I’m sorry, but I have no idea what it is you are trying to achieve, but it does not work for.
This section…
meditMaterials[sName][#materialList][#Shader_Basic_Parameters].ambient = color 0 0 255
meditMaterials[sName][#materialList][#Shader_Basic_Parameters].diffuse = color 0 0 255
Should read
meditMaterials[i].materialList[2].ambient = color 0 0 255
meditMaterials[i].materialList[2].diffuse = color 0 0 255
Again, it could just be that I'm missing parts of the code that will help make the rest run, but this is what I did to get it to work
I know I am a total noob at this but these scripts must be written. Please understand it is imperitive that only certain materials must be affected by name. Thus when I am looking for materials with “input” only those will be affected. I need to change them to composite but it seems impossible to change the .name to an integer as it seems that this:
meditMaterials[m] = compositematerial () –change to composite materials
requires an integer. (unable to convert standard type: integer)
even with this code it fails and gives me the same error
[i] if (findstring meditMaterials.name “input”) == 1 then
(
meditMaterials = compositematerial () –change to composite materials
)
or this[i]
if (findstring meditMaterials[i].name “input”) == 1 then
(
–Get the material name for easier use…
local m = meditMaterials[i] as integer
meditMaterials[m] = compositematerial () –change to composite materials
)
[/i] ————————————————————————————–
The job of the script is to change materials from other people’s scene’s and have a certain render output. So these materials have specific names set up by the artist. This is why I am constantly trying to weed out materials by name. So in this piece of code only certain materials are changed to a composite.
the other materials that do no have “input” in the name have to be checked for this
This peice of code runs after the above[i]
else if meditMaterials.opacity < 100 then – is there transparency in materials???
( some code)
unknown property: “opacity” in compositematerial:Composite
Its not a composite material but a Standard Material so I do not understand why I am getting this error. Here is the code.
for i = 1 to meditMaterials.count do
(
-- looking for any named materials with the word "input"
if (findstring meditMaterials[i].name "input") == 1 then
(
-- Get the material name for easier use...
local m = meditMaterials[i] as integer
meditMaterials[i] = compositematerial () --change to composite materials
----get uvtexture and put in main slot of composite materials
meditMaterials[i].baseMaterial.diffusemap = (Bitmaptexture fileName:"E:\3dsmax9\maps\uvtex.png")
----------------------------------------------------------------
meditMaterials[i].materialList[2] = Standardmaterial () --setting up the added layer
--added layer is blue
meditMaterials[i].ambient = color 0 0 255
meditMaterials[i].diffuse = color 0 0 255
)
else if meditMaterials[i].opacity < 100 then -- is there transparency in other materials???
(
meditMaterials[i].opacity = 0 --if so make 100% transparent
)
else if meditMaterials[i].reflectionMapEnable == on then --is their reflection mapping?
(
if meditMaterials[i].opacity == 100 then --check for no transparency, for transparency takes presidence
(
meditMaterials[i].reflectionMapAmount = 100 --make reflection 100%
)
)
)
please understand I have to change materials by name, and only certain ones.
I think perhaps there is a completely circuitous way of doing this, maybe I can somehow isolate the “input” materials, perhaps even rename them as 0001 0002 and pass that as an integer I dunno.
Join the club!
[i]local m = meditMaterials[i] as integer [/i]
I know this won't work, material can not be converted to an interger, it just isn't possible, it would like saying "person as car"...makes no sense...
--------------------------------------------------------------------------------------
[i]
[i] else if meditMaterials.opacity < 100 then – is there transparency in materials???
( some code)unknown property: "opacity" in compositematerial:Composite Its not a composite material but a Standard Material so I do not understand why I am getting this error. Here is the code.
How do you know what they are? You're assuming that they are standard materials, when they may not be! Hence you are getting an error
You need to perform a check as to what type of material you are dealing with.
if (classof meditMaterials[i]) == Standardmaterial then (
-- Now you have a standard material
)
I've updated the main section of the code and corrected some additional mistakes. I also noticed that when you change the material, the name is also reset, so I reapply it at the end of the if block...
for i = 1 to meditMaterials.count do
(
-- looking for any named materials with the word "input"
if (findstring meditMaterials[i].name "input") == 1 then
(
-- Get the material name for easier use...
[b]local sName = meditMaterials[i].name[/b]
[b]/** This will bite you the back end **/
--local m = meditMaterials[i] as integer[/b]
meditMaterials[i] = compositematerial () --change to composite materials
----get uvtexture and put in main slot of composite materials
meditMaterials[i].baseMaterial.diffusemap = (Bitmaptexture fileName:"E:\3dsmax9\maps\uvtex.png")
----------------------------------------------------------------
meditMaterials[i].materialList[2] = Standardmaterial () --setting up the added layer
--added layer is blue
[b] /** This will bite you the back end... **/
/** Composite material does not have an ambient or diffuse slot... ****/
--meditMaterials[i].ambient = color 0 0 255
--meditMaterials[i].diffuse = color 0 0 255
/** BUT, the standard material you just applied does! **/
meditMaterials[i].materialList[2].ambient = color 0 0 255
meditMaterials[i].materialList[2].diffuse = color 0 0 255
-- Reset the material name...
meditMaterials[i].name = sName
[/b] )
)
please understand I have to change materials by name, and only certain ones.
Yeah, I think we got that part ;)
ed:
I should also point out that you can name the composite material when you create it:
meditMaterials[i] = compositematerial name:meditMaterials[i].name
:applause:OH MAH GAWD:applause:
The forum will not let me increase your rep. unless I increase somebody else’s. Thanks for being so understanding. I totally forgot I could do this
[i]local sName = meditMaterials[i].name
{make some changes}
meditMaterials.name = sName >>then apply the changes after. Everything works!
Except unlike previous scripts this doesnt change any of the materials that are applied to objects in the scene. I even choose the eyedropper from one of the objects and it returned as input001 – but no composite. While input001, 002 and 003 in the Materials lib. have been changed. I even tried the Update Active Material. hrmm…I will scour the reference to find something.
Ah i got it. this works. Put Material to Scene. Now I just have to find a function for that, perhaps this can be used. But I am not using it right. >>[b]UpdateMtlEditorBrackets/b
That’s okay, everyone knows I’m an idiot ( lol )
[i]local sName = meditMaterials[i].name {make some changes} meditMaterials[i].name = sName[/i] >>then apply the changes after. Everything works! Except unlike previous scripts this doesnt change any of the materials that are [i]applied[/i] to objects in the scene. I even choose the eyedropper from one of the objects and it returned as input001 - but no composite. While input001, 002 and 003 in the Materials lib. [i]have been[/i] changed. I even tried the Update Active Material. hrmm...I will scour the reference to find something. Ah i got it. this works. Put Material to Scene. Now I just have to find a function for that, perhaps this can be used. But I am not using it right. >>[b][b]UpdateMtlEditorBrackets[/b][/b]()
The bad news is, I think you will need to reapply the materials to the objects…this thought is straight off the top of my head
Shane
Yeh thats exactly it, is there a way to not manually reapply materials to the objects? I’ve been looking for a function that does Put Materials to Scene in the reference but found nothing.
I gotta tell ya, this forum rocks! :buttrock:
This is the solution that I’ve been able find…
-- Grab a reference to the current material
local mOld = meditMaterials[1]
local sName = mOld.name
-- Create our new material
local mNew = (compositematerial name:sName)
-- Do everything you were before, just act on the mNew instead...
mNew.materialList[2] = Standardmaterial () --setting up the added layer
mNew.materialList[2].ambient = color 0 0 255
mNew.materialList[2].diffuse = color 0 0 255
-- And the magic solution!
[b]replaceInstances mOld mNew[/b]
While I would sincerly like to take credit, it just wouldn’t be right, this is where I found the solution…
http://forums.cgsociety.org/showthread.php?f=98&t=482548&highlight=update+material
Shane
Yes!!! thats It! Whoo hoo!! (now hopefully I wont have to write any scripts for a couple of weeks).
Bixel, I thought you were going to change your script to work on scene materials and not medit materials. The way it is now, if you have a material in the scene that isn’t in the editor, it won’t get changed.
Actually the entire script handles the scenematerials as well, its basically the above with medit swtiched out with scene. Now all I have to do is write a script to check all objects in the scene without any materials applied to them – ie. no textures.
If you really want to thank me, feed back into the community. You might think you’re a noob now (I still think I am), but you might just have the answer some one else is looking for. So when you become more confident, try helping some others out. I would consider it payment in full
Shane