Convert phong to mia material

179 views Asked by At

I am trying to convert a phong material to mia material using this script i found

proc connectAndSet(string $original,string $target){
  $conn=connectionInfo -sfd ($BARK3);
  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");

  $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)

I am a total noob on mel scripting so i have no idea why its not working or how to fix it it is showing the folowing errors:

// Error:   $conn=connectionInfo -sfd ($BARK3); // 
// Error: Line 2.24: Invalid use of Maya object "connectionInfo". // 
// Error:   $conn=connectionInfo -sfd ($BARK3); // 
// Error: Line 2.36: "$BARK3" is an undeclared variable. // 
// Error:   if ($conn!=""){ // 
// Error: Line 3.13: "$conn" is an undeclared variable. // 
// Error:     connectAttr -force $conn $target; // 
// Error: Line 4.36: "$conn" is an undeclared variable. 

$BARK3 is the name of the material im trying to convert

1

There are 1 answers

0
Achayan On BEST ANSWER

// you need to define $BARK some where

proc connectAndSet(string $original,string $target, $BARK){
  // when you call mel function you need to use ` 
  $conn=`connectionInfo -sfd ($BARK)`;
  if ($conn!=""){
    connectAttr -force $conn $target;
  } else {
    connectAttr -force $original $target;
    disconnectAttr $original $target;
  }
}

....

$target=`mrCreateCustomNode -asShader "" mia_material`;
$BARK = "someNode";
connectAndSet($original+".color",$target+".diffuse", $BARK);