Notifications
Clear all

[Closed] Automated Material Editing

Not sure… But I do know, if I don’t trap it they’ll brake it somehow…

Hehe, I understand, better safe than sorry.

Thanks for all the ideas!

Marco,

I tried editing the Macroscript and adding the modified line you had… it evaluates just fine but the result is still that ALL objects get the material modification instead of just the selected ones. There must be more that needs to be added beyond that first line.

For example, in my current scene I have ground objects and building objects. I select all the ground objects and execute the script and all seems fine. But when I go to test render… the complain dialog says it can’t find the opacity maps for the building objects (which should have been unaffected).

Thanks again.

could you post up the whole script you’re using so we can look at it… thanks

Here’s what I’m currently using:

macroScript Macro3
	category:"DragAndDrop"
	toolTip:""
(
	 
	(
	 mats= for o in selection WHERE o.material != undefined collect o.material
	 for m in mats do
	 (
	  Diff=m.diffuseMap
	  if classof Diff == bitmapTexture do
	  (
	   d=Diff.fileName
	   o=GetfileNamePath d + GetfileNameFile d + ".gif"
	   Opa =  bitmapTexture filename:o
	   m.opacityMap = Opa
	   m.diffuseMap.coords.blur = 0.5
	   m.opacityMap.coords.blur = 0.0
	  )
	 )
	)
)

Thanks!

Well the script is correctly collecting the materials from the selection as far as I can tell. However if the ground objects use the same material as the building objects, then the script will affect both, since in max several objects can have an instance of the same material.

If that is the case then the script should create a copy of the material and assigning it to the selection, and then modifying those copies.

Let’s see if I can explain this better.

I have 100 building objects and 100 ground objects in the scene. Each has a unique material. Each material name matches the object name. So ‘building001’ object has ‘building001’ material, etc.

If (before using the script) I examine one object of each type… the material of the ground objects have a single, diffuse map and the building objects also only have a single, diffuse map.

I select the ground objects only.

I run the script.

I re-examine the materials. BOTH the ground and building objects now have an opacity map added to their materials.

So it seems that not only the selected objects are being affected. Not sure why since I’m clueless when it comes to scripting.

Thanks!

Hmmmm. OK, I was doing something wrong.

Marco, your script modification DOES work… Thanks!

Here’s what I don’t understand. The previous script I have been using, I had dragged it to a toolbar and had been clicking it as a button. So when I wanted to add Marco’s modification, I simply right-clicked on the button and chose Edit Macroscript. I edited the script and then chose Save and closed the editor window. And then I clicked the button again to run the script. This produced the results I described earlier… selected AND unselected objects got their materials modified.

But when I dragged the code to the toolbar (and a new button was made) and then clicked this button… I got the proper results where ONLY the selected objects had their materials modified.

Why did this happen? Shouldn’t ‘Edit Macroscript’ have worked? Perhaps there was some other change I missed when editing the macroscript by hand?

Thanks again!

Hehe, besides changing the script, you needed to re-evaluate it. Scripts need to be evaluated before they can be used (somewhat like how most programs need to be compiled before they can be run), dragging the code to the toolbar does that automatically. Restarting max also forces a re-evaluation of all scripts.

Ahhhh… so I was saving it but because I was not re-starting MAX it wasn’t getting re-evaluated upon startup. And since I wasn’t re-evaluating manually… it was still using the old script and not the new.

Thanks again!

Page 2 / 3