merging duplicate materials on import

merging duplicate materials on import

Craig_Lamorte
Advocate Advocate
3,838 Views
7 Replies
Message 1 of 8

merging duplicate materials on import

Craig_Lamorte
Advocate
Advocate

Hi,

 

Are there any commands that will merge duplicate materials on import? 

 

For example lets say I import test.mb which has a material "test_material".  Now if I import test.mb again, I am wanting it to check to see if there are any duplicate materials and if there are then it should use the "test_material" already in the scene on the second mesh that was imported.  So in the end I only have 1 "test_material" instead of 2.

0 Likes
3,839 Views
7 Replies
Replies (7)
Message 2 of 8

mspeer
Consultant
Consultant

Hi!

 

Check import options:

- Remove duplicate shading networks

0 Likes
Message 3 of 8

Craig_Lamorte
Advocate
Advocate

i did try that in cmds.file() command, setting removeDuplicateNetworks flag.  It did not work.  It still kept generating duplicate materials

0 Likes
Message 4 of 8

mspeer
Consultant
Consultant

Hi!

 

Does it work when using the UI, cause here it works fine.

New scene, simple cube, new material assigned...save.

New main scene,

1. Import cube-scene

2. Import cube-scene

Only one material in main scene

0 Likes
Message 5 of 8

Craig_Lamorte
Advocate
Advocate

Well I am not using the UI, so it doesn't matter.  This is being done all in code.

0 Likes
Message 6 of 8

RFlannery1
Collaborator
Collaborator

Try using the "removeDuplicateShadingNetworksOnImport" optionVar.

shadingNetworksOptVar = cmds.optionVar(q='removeDuplicateShadingNetworksOnImport')
cmds.optionVar(intValue=('removeDuplicateShadingNetworksOnImport', 1))
# Do file importing stuff here... cmds.file(extractedAssetPath, i=True, removeDuplicateNetworks=True, blahBlahBlah...) cmds.optionVar(intValue=('removeDuplicateShadingNetworksOnImport', shadingNetworksOptVar))

A word of caution.  This may not work 100% correctly for custom shaders.  We are using custom dx11 shaders and tried using this optionVar.  At first it seemed to work, but in some cases it would remove materials that weren't actually duplicates.  (I'm a bit fuzzy on the details.  The co-worker who found the issue is out of the office today.)

0 Likes
Message 7 of 8

Craig_Lamorte
Advocate
Advocate

Awesome thanks!  That worked, I will definitely do some extensive testing though to see if removes non duplicates.

 

I started to actually do this the long way by getting by comparing materials, and replacing with original and deleting old, but this way is much quicker.

 

0 Likes
Message 8 of 8

mspeer
Consultant
Consultant

Hi!

Also works with Python file command here.

0 Likes