Anyone want to help write a killer time-saving script?


#21

Alright hopefully this is the last time:

///Find and Delete All Contribution Maps
int $b;

for ($b=0; $b<300; $b++){
$con= ("passContributionMap"+($b+1));
if (isValidString($con, "^passContributionMap.*")==0)
{
delete $con;
}
else
{
}
}

In real life terms terms, if PassContributionMap(#) exists, then delete it. But nothing happens. :banghead: The passContributionMap1 I created in the scene to test is still there.

I’m sure it is probably some small mistake I’m making.


#22

Yes!!! I figured it out!


#23

Updated for Clarity:

/////////////////////////////////
// Material Matte Pass Creator //
/////////////////////////////////

// Written By Christopher Emerson
/// Special Thanks to Narann



//-----------------------------------------------------------------------
//  Remove From Previous Run
//-----------------------------------------------------------------------

///Find and Delete All Pre-Existing Contribution Maps
string $passContribMaps[] = `lsType passContributionMap`;
stringArrayRemoveAtIndex(size($passContribMaps)-1, $passContribMaps); //this remove the last entry: <done>
for($passContribMap in $passContribMaps) {
if (isValidString($passContribMap , "^passContributionMap.*")) {
     delete $passContribMap;
}
}

///Delete and Create New "Matte" Render Layer
renderLayerEditorDeleteLayer RenderLayerEditor Matte;
createRenderLayer -name "Matte" -number 1 -noRecurse `ls -selection`;

//-----------------------------------------------------------------------
// Declare Variables
//-----------------------------------------------------------------------

proc putincont( ) {
// Get the Selection of shading nodes
string $allShaders[]=`ls -sl`;
string $oneShader;

//declare the object array
string $objectsmove[];
clear $objectsmove;


//-----------------------------------------------------------------------
//  Place Objects from Shading Group inside Matte Layer
//-----------------------------------------------------------------------

for ($oneShader in $allShaders)
 		{
hyperShade -objects $oneShader;
select -tgl $objectsmove;
 

$objectsmove=`ls -sl`;  
 		}

editRenderLayerMembers -noRecurse Matte $objectsmove;

     }


/////////////////////////
// Begin Main For Loop //
/////////////////////////
proc mainloop( ) {         
int $i;
//Declair selected Materials
string $Material[] = `ls -sl`;
int $selSize = `size $Material`;

for ($i =0; $i <$selSize ; $i++){

//-----------------------------------------------------------------------
// Create "Matte_" Pass
//-----------------------------------------------------------------------
if(!`objExists ("Matte_"+$Material[$i])`)
	{
createNode -name ("Matte_"+$Material[$i]) renderPass;
setRenderPassType -type "MATTE" -n 1 ("Matte_"+$Material[$i]);		
	}

//-----------------------------------------------------------------------
//Define Associated Passes
//-----------------------------------------------------------------------

connectAttr -nextAvailable ("Matte.renderPass") ("Matte_"+$Material[$i]+".owner");

//-----------------------------------------------------------------------
//Declare Selection For Adding Objects to Contribution Maps
//-----------------------------------------------------------------------

hyperShade -objects ($Material[$i]+"SG");
$objects=`ls -sl`;

//-----------------------------------------------------------------------
//Create Contribution Maps
//-----------------------------------------------------------------------

renderLayerEditorCreateContMap RenderLayerTab Matte 0;


//-----------------------------------------------------------------------
/// Place Objects From Shaders into Contribution Maps
//-----------------------------------------------------------------------
//connectAttr -na nurbsSphere3.message passContributionMap3.dagObjects;

connectAttr -na ($objects[$i]+".message") ("passContributionMap"+($i+1)+".dagObjects");
onPassContributionMapChange;
select -clear;
clear($objects);

//-----------------------------------------------------------------------
///Connect Associated Passes to Contribution Maps
//-----------------------------------------------------------------------
connectAttr -nextAvailable ("Matte_"+$Material[$i]+".message") ("passContributionMap"+($i+1) +".renderPass");


}

///////////////////////
// End Main For Loop //
///////////////////////
}

putincont;
mainloop;

How To Use:

  1. Select All Materials you want to have Matte Passes for.
  2. Run Script.
  3. Render “Matte” Layer.
    (optional) - Set file output to EXR in Render Settings for easier selection in compositing.

Warnings and Setbacks

  • DO NOT select any of the initial shaders.
  • DO NOT Run script with no Materials selected.
  • Only Use With Materials, do not select geometry.

Things to Fix/Add, Help with this is More than welcome:

  • Fix Bug That Breaks Render Passes!!!
  • Make it so it only works with Materials.
  • Have it ignore 3 initial Shaders.
  • Add in global procedure so you can drop the script in the Mel folder and call it up.
  • Possibly have it automatically select all shaders instead of requiring the User to do so.

#24
for ($b=0; $b<300; $b++) {
  $con= ("passContributionMap"+($b+1));
  if (isValidString($con, "^passContributionMap.*")==1) {
   if ( `objExists $con`) {
     delete $con;
     }
    }
   }
  

Not very clean, use “lsType”!. Should be:

string $passContribMaps[] = `lsType passContributionMap`;
stringArrayRemoveAtIndex(size($passContribMaps)-1, $passContribMaps); //this remove the last entry: <done>
for($passContribMap in $passContribMaps) {
if (isValidString($passContribMap , "^passContributionMap.*")) {
     delete $con;
}
}

  • You get all nodes of type passContributionMap
  • You remove the last enter (<done>)
  • For each one in the array
  • You check if is name is valid
  • If it is you delete it

Read the documentation of each command you use, it will be very interesting for you!

:slight_smile:


#25

That’s the strangest thing, I just did a test render and even though all the materials are assigned correctly to the contribution Maps, the individual Matte’s don’t render correctly.

Let me know if you are having the same problems.

Edit: Oh, ok Narann, so that’s the correct way of doing it. Thanks for the example, I’ll make the changes.

Edit2: I tried moving a pass out of the “Passes Used By Contribution Map” in the Pass Render settings and got the following error:

// Error: There is no connection from 'Matteblinn1.message' to 'passContributionMap1.renderPass' to disconnect // 

Something strange is going on. It looks like it is connected, but the connection was obviously not entirely made.


#26

Alright, trying to isolate the problem. It’s not with the Matte creation (though I found a fix the connection problem as well).

I’m pretty sure it’s just Maya being extremely sensitive with the ordering. I need to re-write part of the script so it does each of these right after each other, no other commands inbetween:

If you create a nurbs sphere and type this in straight it works:

renderLayerEditorCreateContMap RenderLayerTab Matte 1;
connectAttr -na Matte.passContributionMap passContributionMap3.owner;
connectAttr -na nurbsSphere1.message passContributionMap3.dagObjects;
lsThroughFilter -na DefaultMaterialsAndShaderGlowFilter7 -sort byName -reverse false;
onPassContributionMapChange;

#27

Still having problems, I went back and cleaned up the code though so it’s much easier to understand what is going on.

See Here


#28

I’ve isolated the problem. It has to do with these lines:

//-----------------------------------------------------------------------
//Create Contribution Maps
//-----------------------------------------------------------------------

renderLayerEditorCreateContMap RenderLayerTab Matte 0;
//Alternative for fix, Matte 1; ??????

//-----------------------------------------------------------------------
///Make Mattte Layer owner of passContributionMap???
//-----------------------------------------------------------------------

connectAttr -na Matte.passContributionMap ("passContributionMap"+($i+1) +".owner");
///Not working

When you compare my code to what’s generated by Maya, you’ll Notice they use Matte = 1 and this .owner connection to the Matte. passContribution map. I have done neither of those things.

renderLayerEditorCreateContMap RenderLayerTab Matte 1;
connectAttr -na Matte.passContributionMap passContributionMap3.owner;
connectAttr -na nurbsSphere3.message passContributionMap3.dagObjects;

The problem is when I make either of those changes, I only get one passContributionMap created.


#29

I found out what the issue is. The problem is I have no idea what I’m doing wrong.

Create a Nurbs sphere in your scene and run this:

///Delete and Create New "Matte" Render Layer
renderLayerEditorDeleteLayer RenderLayerEditor Matte;
createRenderLayer -name "Matte" -number 1 -noRecurse `ls -selection`;

//Select Nurbs sphere
$objectsmove=`ls -sl`;
editRenderLayerMembers -noRecurse Matte $objectsmove;

/// Attach to Contribution Map
delete passContributionMap1;
renderLayerEditorCreateContMap RenderLayerTab Matte 0;
connectAttr -na nurbsSphere1.message passContributionMap1.dagObjects;
onPassContributionMapChange;

Then go into the Render Passes, create any type of Pass you want, and add it the the Matte Layer contribution. It Renders!

So what’s the problem? The objects need to be added to the Matte Layer before any contribution maps are made. I tested it. But no matter what I do, I can’t seem to get it right.

I’m thinking about trying to place the Objects from Shading Group inside Matte Layer in a command prior to placing the objects into the contribution map. I’m praying it will fix it. Anyone else have an idea as to what is wrong?


#30

Still trying to fix the bug. I’ll post some sample code again soon of what I’m trying to do to solve the problem.

In the meantime I found out there is something else I must know how to do for this to work. Either how to Rename an SG node to the Material name, or how to directly select the SG node from the Material. Anyone know how to do it?


#31

Figured the SG renaming out! I found this code in renameSG.mel included in Maya bonus tools. It needed some slight modification to allow it to work with Mental ray Materials, but here it is:

string $nodes[] = `ls -sl`;
	
	for ($node in $nodes){
		string $SGName[] = `listConnections -t "shadingEngine" $node`;
		string $newSGName = ($node + "SG");
		rename $SGName[0] $newSGName;
		}

:wink:


#32

So here is an update as I try to put the Objects in render layers just prior to Creating contribution maps, following the way that seems to work in Maya.

/////////////////////////////////
// Material Matte Pass Creator //
/////////////////////////////////

// Written By Christopher Emerson
/// Special Thanks to Narann


//-----------------------------------------------------------------------
//  Rename Material SG Nodes to Match Material Names
//-----------------------------------------------------------------------
string $nodes[] = `ls -sl`;
	
	for ($node in $nodes){
		string $SGName[] = `listConnections -t "shadingEngine" $node`;
		string $newSGName = ($node + "SG");
		rename $SGName[0] $newSGName;
		}


proc putincont( ) {
//-----------------------------------------------------------------------
//  Remove From Previous Run
//-----------------------------------------------------------------------

///Find and Delete All Pre-Existing Contribution Maps
string $passContribMaps[] = `lsType passContributionMap`;
stringArrayRemoveAtIndex(size($passContribMaps)-1, $passContribMaps); //this remove the last entry: <done>
for($passContribMap in $passContribMaps) {
if (isValidString($passContribMap , "^passContributionMap.*")) {
     delete $passContribMap;
}
}

///Delete and Create New "Matte" Render Layer
renderLayerEditorDeleteLayer RenderLayerEditor Matte;
createRenderLayer -name "Matte" -number 1 -noRecurse `ls -selection`;

//-----------------------------------------------------------------------
// Declare Variables
//-----------------------------------------------------------------------

// Get the Selection of shading nodes
string $allShaders[]=`ls -sl`;
string $oneShader;

//declare the object array
string $objectsmove[];
clear $objectsmove;

     }


/////////////////////////
// Begin Main For Loop //
/////////////////////////
proc mainloop( ) {         
int $i;
//Declair selected Materials
string $Material[] = `ls -sl`;
int $selSize = `size $Material`;

for ($i =0; $i <$selSize ; $i++){

//-----------------------------------------------------------------------
// Create "Matte_" Pass
//-----------------------------------------------------------------------
if(!`objExists ("Matte_"+$Material[$i])`)
	{
createNode -name ("Matte_"+$Material[$i]) renderPass;
setRenderPassType -type "MATTE" -n 1 ("Matte_"+$Material[$i]);		
	}

//-----------------------------------------------------------------------
//Define Associated Passes
//-----------------------------------------------------------------------

connectAttr -nextAvailable ("Matte.renderPass") ("Matte_"+$Material[$i]+".owner");

//-----------------------------------------------------------------------
//Declare Selection For Adding Objects to Contribution Maps and Layers
//-----------------------------------------------------------------------

///******** Testing

hyperShade -objects ($Material[$i]+"SG");
$objectsmove= `ls -sl`;
$objects=`ls -sl`;

//-----------------------------------------------------------------------
// Add Current Object to to Layer
//-----------------------------------------------------------------------

//////******************Problem Area******************///////

editRenderLayerMembers -noRecurse -q Matte $objectsmove;


//////******************Problem Area******************///////

//-----------------------------------------------------------------------
//Create Contribution Maps
//-----------------------------------------------------------------------

renderLayerEditorCreateContMap RenderLayerTab Matte 0;


//-----------------------------------------------------------------------
/// Place Objects From Shaders into Contribution Maps
//-----------------------------------------------------------------------

connectAttr -na ($objects[$i]+".message") ("passContributionMap"+($i+1)+".dagObjects");
onPassContributionMapChange;
clear($objects);

//-----------------------------------------------------------------------
///Connect Associated Passes to Contribution Maps
//-----------------------------------------------------------------------
connectAttr -nextAvailable ("Matte_"+$Material[$i]+".message") ("passContributionMap"+($i+1) +".renderPass");

}

///////////////////////
// End Main For Loop //
///////////////////////
}

putincont;
mainloop;


I’ve highlighted the part that I know is causing the problems. Think I’m doing something wrong with how I’m declaring the object to be placed in there.


#33

Got it working!!! :applause:

I found out Maya’s stupid Matte pass does not work with Mia Materials, so I did a simple Layer override and everything is perfect. It’s a small setback, but the results are well worth it.
I’m going to clean up the code a bit and release the first version probably later tonight or tomorrow.


#34

looking forward to it !


#35

Just adding to the thread =)

You could use buffers and milabels as well, but I’ve heard they’re slow

http://forums.cgsociety.org/showthread.php?f=87&t=690795
http://www.pixelcg.com/blog/?p=98
http://www.sigillarium.com/blog/lang/en/379/

Old-school way (create eons of surface shaders)

http://www.creativecrash.com/maya/downloads/scripts-plugins/rendering/misc/c/mat_obj_id_v01-mel--2


#36

I’ve had really bad experiences with Mat IDs and objects IDs. First, many compositing applications have bad integration, and second, edge artifacts are always an issue. Last it’s a pain to setup in Maya.

Anyways here is a preview, I’ll upload it tomorrow.

Easy as pie for the maya user and compositor alike, the way it should be. :smiley:


#37

Thank you for the hard work. Crispy. Looking forward to seeing the release of this matte pass creator script. :slight_smile:


#38

Your welcome, it’s been quite a long road. :slight_smile:

All Done!!

:buttrock:


#39

Seems to be interresting ^^ in the end :smiley:


#40

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.