Home Technical Talk

Melscript - rename renderlayers and create one

polycounter lvl 11
Offline / Send Message
Alphavader polycounter lvl 11
Hey Guys -


iam on a little arrange script:

basically i want two things:

1. select a group called "camera - or static name"
2. select first subgroup
3. put these two selections in one renderlayer with the naming l1
4. redo everything until evey subgroup is in its own renderlayer

so l1 l2 l3 and so on

sturcture is: "camera - or static name" + "(select maingroup - manually)" = go to every subgroups and do steps above! (automatic)

here my code so far

//kill window if open

    if (`window -ex "RenderlyerScript"`)                  
        deleteUI "RenderlyerScript";     

	
		
	{		
		// create the window
		window "RenderlyerScript";
		
		// define the layout of controls added 
		// to the window.
		rowColumnLayout -numberOfColumns 1;

			// buttons
			button -w 100 -h 100 -backgroundColor .4 .9 .4 -label "put group in renderlayer" -command "rlayer";
		    button -w 100 -h 100   -label "rename renderlayers" -command "rename";
		    
		   //renderlayer
		   proc rlayer () {
		  
		    select -add CAMERA_LIGHTING ;
            createRenderLayer -name "l1" -number 1 -noRecurse `ls -selection`;
            select -add "group";
            }
           
           //renameLayer
		   proc rename() {
		  
		    select -add CAMERA_LIGHTING ;
            createRenderLayer -name "l1" -number 1 -noRecurse `ls -selection`;
            select -add "group";
            }
		    
	
		    
		columnLayout;
	
		

				scrollField -wordWrap true 
					-text  "Instructions:" -editable false;
		
					text -l "Renderlyer karl v0.1";
					
				
			
	

	
		showWindow;
	}	
	
	


it worked well when i select the subgroup manually - but i want it to be automatic.
is there some kind of "if - when - "



Thanks.

Also i want a rearrange naming in the renderlayer group.

So if i have l1 l2 l3 l4 l5 and so on - and i put l5 above l3 - i want that the script is rename every renderlayer
so it arranges back to the order l1 till l"end"

Some help would be nice !

Replies

  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    Can you provide a screenshot of your basic hierarchy? Also it sounds like you're going to be using a lot of for loops
  • Alphavader
    Options
    Offline / Send Message
    Alphavader polycounter lvl 11
    sure - here it is:
    i think about using two loops - one for the subgroups
    and on the other button one for the renaming

    yvpi5phc222.png
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    It looks like you have code for a window that comes up with buttons that run other procedures. Depending on those procedures, you might be able to just put them into the for loop and forgo the window entirely
    // stores current selection (main group)
    string $mainGroup[] = `ls -sl`;
    
    // lists all children (sub groups)
    string $subGroups[] = `listRelatives -c $mainGroup[0]`;
    
    // goes through each sub group 1 by 1 and performs any commands you write in (where "yourProcs" are)
    for ($i=0; $i<`size $subGroups`; ++$i) {
        select $subGroups[$i]
        yourProcs;
    }
    
  • Alphavader
    Options
    Offline / Send Message
    Alphavader polycounter lvl 11
    Thanks - now it says "// Error: line 33: No object matches name: subGroups[0] // "

    i dont want the select the subgroups manually - i just want to select the "maingroup"

    Here my progress:
    // buttons
    			button -w 100 -h 100 -backgroundColor .4 .9 .4 -label "Create Renderlayers from Maingroup" -command "rlayer";
    		    button -w 100 -h 100   -label "Autorename the Renderlayers" -command "rename";
    		    
    		   //renderlayer
    		   proc rlayer () {
    		       
    		  // stores current selection (main group)
                string $mainGroup[] = `ls -sl`;
    
                // lists all children (sub groups)
            string $subGroups[] = `listRelatives -c $mainGroup[0]`;
    
            // goes through each sub group 1 by 1 and performs any commands you write in (where "yourProcs" are)
                for ($i=0; $i<`size $subGroups`; ++$i) {
            select subGroups[$i];
           select -add CAMERA_LIGHTING ;
                createRenderLayer -name "l1" -number 1 -noRecurse `ls -selection`;
                select -add "group";
            
            }
    		  
    		    }
    
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    Hey, sorry about that error. My code was missing a big dumb dollar sign for a variable, haha!

    Here's a reformatted code with your buttons integrated into the FOR loop:
    // stores current selection (main group)
    string $mainGroup[] = `ls -sl`;
    
    // lists all children (sub groups)
    string $subGroups[] = `listRelatives -c $mainGroup[0]`;
    
    // goes through each sub group 1 by 1 and performs any commands you write in (where "yourProcs" are)
    for ($i=0; $i<`size $subGroups`; ++$i) {
        select $subGroups[$i];
        createRenderLayer -name ( "l" + ($i+1)) -number 1 -noRecurse "CAMERA_LIGHTING";
    }
    
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    So yeah, the window and the buttons were fine, but they weren't necessary. A couple of other things:

    Your two procs were doing the exact same thing. Not sure why.

    I would suggest avoiding naming procs that are also the same as Maya's default commands, such as rename. That'll give you all sorts of errors.

    A couple notes on the code:

    I basically placed the functionality of your buttons inside the for loop. In order to get each layer to be named incrementally, I used the for loop's counter $i. You can create alphanumeric ordered lists by combining strings and integer values by containing them inside parentheses. The reason for $i + 1 is because $i started on 0 instead of 1, and I was offsetting that.

    Hopefully this is what you were aiming for!
  • Alphavader
    Options
    Offline / Send Message
    Alphavader polycounter lvl 11
    thanks alot - i almost worked - but the layers only contain the
    Camera Setup not the subgroup stuff.
    I assume i have to add - select subgroup?

    The second button function is only a placeholder - but i renamed the function, thanks for the hint.
    // buttons
    			button -w 100 -h 100 -backgroundColor .4 .9 .4 -label "Create Renderlayers from Maingroup" -command "rlayer";
    		    button -w 100 -h 100   -label "Autorename the Renderlayers" -command "rname";
    		    
    		   //renderlayer
    		   proc rlayer () {
    		       
    		
    	    // stores current selection (main group)
            string $mainGroup[] = `ls -sl`;
    
        // lists all children (sub groups)
        string $subGroups[] = `listRelatives -c $mainGroup[0]`;
    
        // goes through each sub group 1 by 1 and performs any commands you write in (where "yourProcs" are)
        for ($i=0; $i<`size $subGroups`; ++$i) {
        select $subGroups[$i];
        createRenderLayer -name ( "l" + ($i+1)) -number 1 -noRecurse "CAMERA_LIGHTING";
        
    }
       
    		  
    		    }
             
               
               //renameLayer WORK IN PROGRESS
               proc rname() {
    		     $name=`ls -type renderLayer`;
    
    }
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    You can insert the following line into the for loop (at the end) to add the subgroups:
    editRenderLayerMembers -noRecurse ( "l" + ($i+1)) $subGroups[$i];
    
  • Alphavader
    Options
    Offline / Send Message
    Alphavader polycounter lvl 11
    hmm nope - the layers still only contain the stuff of the camera group
    not the stuff of the subgroup...

    (fixed a little spelling error of your script ;)
    // buttons
    			button -w 100 -h 100 -backgroundColor .4 .9 .4 -label "Create Renderlayers from Maingroup" -command "rlayer";
    		    button -w 100 -h 100   -label "Autorename the Renderlayers" -command "rname";
    		    
    		   //renderlayer
    		   proc rlayer () {
    		       
    		
    	    // stores current selection (main group)
            string $mainGroup[] = `ls -sl`;
    
        // lists all children (sub groups)
        string $subGroups[] = `listRelatives -c $mainGroup[0]`;
    
        // goes through each sub group 1 by 1 and performs any commands you write in (where "yourProcs" are)
        for ($i=0; $i<`size $subGroups`; ++$i) {
          
        select $subGroups[$i];
        createRenderLayer -name ( "l" + ($i+1)) -number 1 -noRecurse "CAMERA_LIGHTING";
         editRenderLayerMembers -noRecurse ( "l" + ($i+1)) $subGroups[$i];
        
        
                }
       
    		  
    		    }
    
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    Ah, sorry. I've been making mistakes all day. These darn fingers...

    So, my code works on my end. It creates a render layer and adds each subgroup to that render layer.

    So for instance, render layer L5 would contain CAMERA_LIGHTING and the lantern:lantern group. It doesn't need to go further than that, as anything contained inside of a group is also part of a layer.

    Is this what you wanted?
  • Alphavader
    Options
    Offline / Send Message
    Alphavader polycounter lvl 11
    //edit: i changed a bit - but it worked - thanks alot for your help!
Sign In or Register to comment.