Imported objects use material editor materials

I've replaced my medit.mat

Im trying to import objects in a new max scene (with assigned materials) and have them use the material editor materials

My current script is:

mergeMAXFile "C:\\Users\\danc\\Documents\\3dsMaxDesign\\vpost\\brick.max" #select #AutoRenameDups #useSceneMtlDups

- but this checks the scene materials (which is empty)

Either this - or is there a way to have scene materials even though the scene is empty of geometry.

I've tried in startup a script I found here on scriptspot:

matLib = loadTempMaterialLibrary "C:\Users\danc\Desktop\medit.mat"
for mat in matLib do (
insMats = getClassInstances (classOf mat) target:sceneMaterials
for ref in insMats where ref.name == mat.name do replaceInstances ref mat
)

but the scene materials are still empty

any help appreciated

Comments

Comment viewing options

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

Allright...

Try this then:

mergeMAXFile "C:\\Users\\danc\\Documents\\3dsMaxDesign\\vpost\\brick.max" #select #AutoRenameDups #useSceneMtlDups

matLib = loadTempMaterialLibrary @"C:\Users\danc\Desktop\medit.mat"
objs = selection as array
omats = for obj in objs collect obj.material

for mat in matLib do
(
for ref in omats where ref.name == mat.name do replaceInstances ref mat
)

dan_cole's picture

Sadly no result

Sadly no result using the script - there are still duplicate materials.

Thanks for your continued help

Kameleon's picture

One other thing I noticed in

One other thing I noticed in the original post (in this thread), you forgot the @ before the "C:\Users\danc\Desktop\medit.mat" which makes a difference, can you try it again by correcting this line:

matLib = loadTempMaterialLibrary @"C:\Users\danc\Desktop\medit.mat" 

???

dan_cole's picture

Its changed colours

Its changed colours but aside from that nothing. 0 Like you said due to the fact the scene materials are empty

Kameleon's picture

Okay

Okay, I think I got it, but in that case, the first thing you were trying SHOULD work. Anyway, if you only have the material editor with your most used materials, that means they're only 24, not 32, right?

btw, your objects become selected when you import them, right?

We could do it another way, I'll post it later in the afternoon (work calls)!

Cheers.

dan_cole's picture

Correct

thanks for the help, really appreciated :)

Correct the objects are selected due to #select and yes 24 materials (I cant count!)

The reason I believe the import script doesn't work is because #useSceneMtlDups checks the scene materials only - and as the scene is empty of materials it brings it in unaware of the identical material in the editor.

Then at this stage when applying the material in the editor I get conflicting material names as I tried to explain in AREA ..

http://area.autodesk.com/forum/autodesk-3ds-max/autodesk-3ds-max--3ds-ma...

- That is why I arrived at somehow tweaking the loadTempMaterialLibrary script to force scene materials even though the scene in empty of geometry and assigned materials.

So yes I think somehow tweaking the mergeMAXFile script is the way forward to some how check the mtl editor for identical materials.

Have fun at work!

Kameleon's picture

Well, I'm still not sure what

Well, I'm still not sure what you want to do exactly and in what conditions, but if you are merging objects that have no materials applied, it will never work this way.

IF you are merging objects that HAVE materials applied but the materials in your SCENE are not APPLIED to any object and only reside in the MATERIAL EDITOR, this will also not work.

To have the merged objects materials checked agains the MATERIAL EDITOR slots, just replace :
insMats = getClassInstances (classOf mat) target:sceneMaterials
with
insMats = getClassInstances (classOf mat) target:mEditMaterials

and that should do it.

Cheers,
Artur Leao

dan_cole's picture

Phrased badly

Obviously I'm not very good at explaining as after posting on AREA a few months back no one understood there either what I was trying to accomplish.

In my workflow we regularly use the same objects and same materials.

I have set up a maxstart file (for layers only) (and no geometry)as well as created a mat files containing 32 of my most used mats and renamed this medit.mat

- now on boot max starts how I like with the material editor full of materials I regularly use.

Now the 'problem' begins when importing objects.

As an example I import a gutter - with an applied 'gutter black' material. This 'gutter black' material is also in my medit. But on import max checks the scene materials (which is empty) then uses the imported object material INSTEAD of the material with the same name in the editor. So now in the scene I have an applied 'gutter black' material and an identical 'gutter black' material in the editor which booted from the medit.

What I am trying to accomplish 1 way or another is to be able to import an object - have max check whether the material being used on the object is in the editor - then use that material if it is when imported.

- Hope this makes sense (probably not haha)

Thanks for your help

Dan

Comment viewing options

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