# Batch Converting Materials

**URL:** https://forum.highend3d.com/t/batch-converting-materials/45302
**Category:** Maya
**Tags:** mental-ray
**Created:** [May 16, 2009, 4:55am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302 "2009-05-16T04:55:33Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![toast--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/5f9b8f/32.png) [@toast--2](https://forum.highend3d.com/u/toast--2)
#### Post date: [May 16, 2009, 4:55am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/1 "2009-05-16T04:55:33Z")

</div>

Hi,

I bought one of those model packs - this one is about 100 different medium poly cars. Look great with default software render but I’m using Sun + Sky setup and of course mental ray and the result is that it looks quite terrible under these circumstances.

All these cars are in separate files and since there is a 100+ of them, this would be an utter waste of time to convert each file that contains 10 materials each on a hundred different files - my question is that is it possible to batch covert these files and convert all the blinn’s into mia\_materials somehow?

I’m not sure on where to start or how to do this.

---

<div class="post-metadata">

### Author: ![gmask](https://forum.highend3d.com/user_avatar/forum.highend3d.com/gmask/32/192_2.png) [@gmask](https://forum.highend3d.com/u/gmask)
#### Post date: [May 16, 2009, 3:31pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/2 "2009-05-16T15:31:06Z")

</div>

you’d have to write a mel script that would look at the shaders assigned and replace them with another shader

Are the shaders on each car named the same things?

---

<div class="post-metadata">

### Author: ![toast--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/5f9b8f/32.png) [@toast--2](https://forum.highend3d.com/u/toast--2)
#### Post date: [May 19, 2009, 7:05am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/3 "2009-05-19T07:05:32Z")

</div>

Sorry, thanks for replying.

They are all different names.

ie Alpha\_logo  
Alpha\_red  
then the next set is  
Audi\_logo  
Audi\_black etc… etc…

The only common denominator is that they are all phong materials. (I mentioned blinn in the first post, but I meant phong). Just wondering if it is possible.

I know Master Zap has released a script for max to convert ANY material to mia\_material, including vray textures. However 3DS only ![]()

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 19, 2009, 11:49am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/4 "2009-05-19T11:49:53Z")

</div>

heres a template make sure you make the .. any other mapping you need comes here… more suiting your needs, So tell maya what attribute maps what attribute in mia end. (dont have time to do it)

```auto
 
proc connectAndSet(string $original,string $target){
  $conn=`connectionInfo -sfd $original`;
  if ($conn!=""){
    connectAttr -force $conn $target;
  } else {
    connectAttr -force $original $target;
    disconnectAttr $original $target;
  }
}
 
proc convertPhongToMia(string $original){
  $target=`mrCreateCustomNode -asShader "" mia_material`;
  connectAndSet($original+".color",$target+".diffuse");
  //... any other mapping you need comes here...
 
  // a bit weak test should work for simple materials,
  // not used in special context
  $sg=`connectionInfo -dfs ($original+".outColor")`;
  if ($sg[0]!=""){
    $sgr=`match "[^.]*" ((string)$sg[0])`;
    connectAttr -force ($target+".outValue") ($sgr+".miMaterialShader");
    connectAttr -force ($target+".outValue") ($sgr+".miPhotonShader");
    connectAttr -force ($target+".outValue") ($sgr+".miShadowShader");
  }
  delete $original;
  rename $target $original;
}
 
 
 
 
for ($item in`ls -et phong`)
  convertPhongToMia($item);

```

---

<div class="post-metadata">

### Author: ![toast--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/5f9b8f/32.png) [@toast--2](https://forum.highend3d.com/u/toast--2)
#### Post date: [May 19, 2009, 12:53pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/5 "2009-05-19T12:53:44Z")

</div>

Have I told you how awesome you are Joojaa? Many thanks!

I’ll try and fill in the gaps, but this will save an unbelievable amount of time. Thanks again.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 19, 2009, 1:49pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/6 "2009-05-19T13:49:26Z")

</div>

Thank my no show up client, had a 20 minutes of spare time to spend on something useful ![]()

---

<div class="post-metadata">

### Author: ![toast--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/5f9b8f/32.png) [@toast--2](https://forum.highend3d.com/u/toast--2)
#### Post date: [May 20, 2009, 1:50pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/7 "2009-05-20T13:50:59Z")

</div>

Hey, understand what you mean about clients. heh.

So I tried this today - I was able to add in extra attributes for it to connect (works a treat) but there’s only one major thing that didn’t work.

The script seemed to be looking for a material called “phong1” for it to execute. Which of course couldn’t find anything.

So I renamed all the materials to phong1, phong2, phong3 sequentially etc.. etc… but the script seemed to only work on the first material called phong1. It would break after converting the first material. Am I missing a step? I don’t know if I’m doing it right.

I look into it - I think there needs to be something adjusted in this line because the script fails here.

$conn=`connectionInfo -sfd phong1.color`;

I’m trying to figure out MEL - I think I’ll add in a wildcard or something that selects all the materials.

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 20, 2009, 3:40pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/8 "2009-05-20T15:40:27Z")

</div>

My bad lik i said its a bit fast done. Change:

$conn=`connectionInfo -sfd phong1.color`;  
   
to:  
  
$conn=`connectionInfo -sfd ($original)`;

Its a bit of residue of how i tested it during developpment.

---

<div class="post-metadata">

### Author: ![toast--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/5f9b8f/32.png) [@toast--2](https://forum.highend3d.com/u/toast--2)
#### Post date: [May 20, 2009, 11:19pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/9 "2009-05-20T23:19:09Z")

</div>

Perfect, that did the trick - it runs flawlessly. Thanks ![]()

---

<div class="post-metadata">

### Author: ![kamikaze\_88](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/k/96bed5/32.png) [@kamikaze\_88](https://forum.highend3d.com/u/kamikaze_88)
#### Post date: [May 6, 2012, 3:26pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/10 "2012-05-06T15:26:35Z")

</div>

Hi Joojaa

Thanks for that script

I have a small problem though and my knowledge on scripting is bad.

I have changed your script a little bit so that it converts to mia\_material\_x instead (for adding bump maps(im not sure how to do a standard bump on the normal mia\_material))

My problem is that the material after I run the script, is connected to both shading groups. The objects that has the new material still has the old material’s shading group attached to it for the viewport. If I render it is fine, but it is green in the viewport. If I drag and drop the newly created shading group that was done in the script on the object, then everything seems fine.

Is there a way to remove the old shading group and have the newly created one assigned?

I also attached a screenshot if it may help

Here is the changed mel script:  
//----------------------------------------------  
proc connectAndSet(string $original,string $target){

$conn=`connectionInfo -sfd $original`;

if ($conn!=“”){

connectAttr -force $conn $target;

} else {

connectAttr -force $original $target;

disconnectAttr $original $target;

}

}

proc convertPhongToMia(string $original){

$target=`mrCreateCustomNode -asShader "" mia\_material\_x`;

connectAndSet($original+“.color”,$target+“.diffuse”);

//… any other mapping you need comes here…

// a bit weak test should work for simple materials,

// not used in special context

$sg=`connectionInfo -dfs ($original+".outColor")`;

if ($sg[0]!=“”){

$sgr=`match "[^.]*" ((string)$sg[0])`;

connectAttr -force ($target+“.message”) ($sgr+“.miMaterialShader”);

connectAttr -force ($target+“.message”) ($sgr+“.miPhotonShader”);

connectAttr -force ($target+“.message”) ($sgr+“.miShadowShader”);

}

delete $original;

rename $target $original;

}

for ($item in`ls -et phong`)

convertPhongToMia($item);

//------------------------------------------------------------------------------------

many thx in advance

Phil  
 ![](https://forum.highend3d.com/system/screenshots/309996/original/Capture.jpg?1336317994)

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 7, 2012, 12:54pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/11 "2012-05-07T12:54:04Z")

</div>

Yeah

```auto
proc connectAndSet(string $original,string $target){
    $conn=`connectionInfo -sfd $original`;
    if ($conn!=""){
        connectAttr -force $conn $target;
    } else {
        connectAttr -force $original $target;
        disconnectAttr $original $target;
    }
}
 
proc convertPhongToMia(string $original){
   $target=`mrCreateCustomNode -asShader "" mia_material_x`;
 
   connectAndSet($original+".color",$target+".diffuse");
   //#... any other mapping you need comes here...
   //# a bit weak test should work for simple materials,
   //# not used in special context
    $sg=`connectionInfo -dfs ($target+".message")`;
    $sgr=`match "[^.]*" ((string)$sg[0])`;
    $sg0=`connectionInfo -dfs ($original+".outColor")`;
    $sgr0=`match "[^.]*" ((string)$sg0[0])`;
    sets -e -forceElement $sgr `sets -q $sgr0`;
    delete $original;
    rename $sgr $sgr0;
    rename $target $original;
}
 
for ($item in`ls -et phong`)
    convertPhongToMia($item);

```

but perhaps mia\_material\_x\_layers would be better?

---

<div class="post-metadata">

### Author: ![kamikaze\_88](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/k/96bed5/32.png) [@kamikaze\_88](https://forum.highend3d.com/u/kamikaze_88)
#### Post date: [May 8, 2012, 11:05am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/12 "2012-05-08T11:05:12Z")

</div>

Awesome thanks Joojaa !

I will give this a try, and what are mia\_material\_x\_layers for mostly?&nbsp; For compositing?

---

<div class="post-metadata">

### Author: ![kamikaze\_88](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/k/96bed5/32.png) [@kamikaze\_88](https://forum.highend3d.com/u/kamikaze_88)
#### Post date: [May 8, 2012, 11:35am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/13 "2012-05-08T11:35:36Z")

</div>

Hi Joojaa,

Just wanted to say thanks again, I tested it and it works perfectly 🙂

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [May 8, 2012, 2:08pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/14 "2012-05-08T14:08:12Z")

</div>

> > what are mia\_material\_x\_layers for mostly?&nbsp; For compositing?

Yeah, it allows you to split out the individual parts of the miamaterials shader to separate files (this is allways useful even if you dont use the layers, the pennalty is minimal). But yeah theres a upconvert button inside the AEtemplate that can do the conversion even at a later date.

---

<div class="post-metadata">

### Author: ![craigee](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/c/90db22/32.png) [@craigee](https://forum.highend3d.com/u/craigee)
#### Post date: [April 20, 2013, 5:40pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/15 "2013-04-20T17:40:49Z")

</div>

I tried to modify this script to use Arnold shaders, the aiStandard in Maya 13.5 w/ MtoA. I didn’t quite get there. This script will make one arnold shader and then quit. The shader it makes has no shading group and is not assigned to the geo. Anyone have some friendly advice on this? One more strange thing I noticed that might be related is that when you create a new aiStandard shader it doesn’t create a shading group until you assign it to geo.

Here is the script w/ only mods being changing shader to aiStandard and mapping color to color:

* * *

proc connectAndSet(string $original,string $target){

$conn=`connectionInfo -sfd $original`;

if ($conn!=“”){

connectAttr -force $conn $target;

} else {

connectAttr -force $original $target;

disconnectAttr $original $target;

}

}

proc convertPhongToMia(string $original){

$target=`mrCreateCustomNode -asShader "" aiStandard`;

connectAndSet($original+“.color”,$target+“.color”);

//#… any other mapping you need comes here…

//# a bit weak test should work for simple materials,

//# not used in special context

$sg=`connectionInfo -dfs ($target+".message")`;

$sgr=`match "[^.]*" ((string)$sg[0])`;

$sg0=`connectionInfo -dfs ($original+".outColor")`;

$sgr0=`match "[^.]*" ((string)$sg0[0])`;

sets -e -forceElement $sgr `sets -q $sgr0`;

delete $original;

rename $sgr $sgr0;

rename $target $original;

}

for ($item in`ls -et phong`)

convertPhongToMia($item);

---

<div class="post-metadata">

### Author: ![emil-moldo](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/e/bb73d2/32.png) [@emil-moldo](https://forum.highend3d.com/u/emil-moldo)
#### Post date: [November 6, 2014, 10:44am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/16 "2014-11-06T10:44:28Z")

</div>

Hi there and please help

ToastI modifi this script and works fine for me, i have a same problem like I just want to chage from phong to lambert.

How can`t convert the Ambient Color, not just the color ? please help.

[b]proc connectAndSet(string $original,string $target){  
&nbsp; $conn=`connectionInfo -sfd ($original)`;  
&nbsp; if ($conn!=“”){  
&nbsp;&nbsp;&nbsp; connectAttr -force $conn $target;  
&nbsp; } else {  
&nbsp;&nbsp;&nbsp; connectAttr -force $original $target;  
&nbsp;&nbsp;&nbsp; disconnectAttr $original $target;  
&nbsp; }  
}

proc convertPhongToMia(string $original){  
&nbsp; $target=`mrCreateCustomNode -asShader "" lambert`;  
&nbsp; connectAndSet($original+“.color”,$target+“.color”);  
&nbsp; //… any other mapping you need comes here…

// a bit weak test should work for simple materials,  
&nbsp; // not used in special context  
&nbsp; $sg=`connectionInfo -dfs ($original+".outColor")`;  
&nbsp; if ($sg[0]!=“”){  
&nbsp;&nbsp;&nbsp; $sgr=`match "[^.]*" ((string)$sg[0])`;  
&nbsp;&nbsp;&nbsp; connectAttr -force ($target+“.outColor”) ($sgr+“.surfaceShader”);  
&nbsp; }  
&nbsp; delete&nbsp; $original;  
&nbsp; rename $target $original;  
}

for ($item in`ls -et phong`)  
&nbsp; convertPhongToMia($item);[/b]

&nbsp;

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [November 7, 2014, 1:17pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/17 "2014-11-07T13:17:23Z")

</div>

Do you mean mib\_illum\_lambert? Or mayas lambert shader?

if mib\_illum\_lambert just add:

```auto
connectAndSet($original+".ambientColor",$target+".ambient");

```

in the additional mappings section.

Anyway your in luck i dont frequent often and the thread is 5 years old.

---

<div class="post-metadata">

### Author: ![rusty\_vs](https://forum.highend3d.com/user_avatar/forum.highend3d.com/rusty_vs/32/1361_2.png) [@rusty\_vs](https://forum.highend3d.com/u/rusty_vs)
#### Post date: [December 9, 2015, 4:03am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/18 "2015-12-09T04:03:00Z")

</div>

Hi, I saw ur post , I have the same problem but sort of change… I have a huge file with mia\_material\_x\_passes and mia\_material\_x shaders and want to convert them to alsurface shader of arnold… can u please give me a script for it.

---

<div class="post-metadata">

### Author: ![mmlihi](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mmlihi](https://forum.highend3d.com/u/mmlihi)
#### Post date: [June 14, 2018, 2:26am UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/19 "2018-06-14T02:26:32Z")

</div>

This code saved my ass, it is so super helpfull! Thank you 1000 times 😄

---

<div class="post-metadata">

### Author: ![joe-deng](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/3be4f8/32.png) [@joe-deng](https://forum.highend3d.com/u/joe-deng)
#### Post date: [May 12, 2020, 7:29pm UTC](https://forum.highend3d.com/t/batch-converting-materials/45302/20 "2020-05-12T19:29:05Z")

</div>

hey sorry to bring the old topic…  
I am trying to use this template to convert VRayMtl to lambert and got this error on line 12  
// Error: line 12: Too many arguments. Expected 0, found 1. //

```
proc connectAndSet(string $original, string $target){
    $conn = `connectionInfo -sfd $original`;
    if ($conn != ""){
        connectAttr -force $conn $target;
    } else {
        connectAttr -force $original $target;
        disconnectAttr $original $target;
    }
}

proc convertVrayToLambert(string $original){
    $target = `shadingNode -asShader "" lambert`;

    connectAndSet($original + ".color", $target + ".color");
    // ... any other mapping you need comes here...
    // a bit weak test should work for simple materials,
    // not used in special context
    $sg = `connectionInfo -dfs ($target + ".message")`;
    $sgr = `match "[^.]*" ((string)$sg[0])`;
    $sg0 = `connectionInfo -dfs ($original + ".outColor")`;
    $sgr0=`match "[^.]*" ((string)$sg0[0])`;
    sets -e -forceElement $sgr `sets -q $sgr0`;
    //delete $original;
    rename $sgr $sgr0;
    rename $target $original;
}

for ($item in `ls -et VRayMtl`)
    convertVrayToLambert($item);

```

any idea?  
Thanks you!
