Home Coding, Scripting, Shaders

MEL - script not assigning material

polycounter lvl 5
Offline / Send Message
Pinned
jayantbhatt007 polycounter lvl 5
hi, I have created this little window so I can easily assign material to it. It's creating a material but not assigning material to the object.




 window;
   
            frameLayout -label "jayant";
            
            // add the other controls

flowLayout -columnSpacing 7 -w 50 -h 50;

 // create six symbol buttons with related mel command
 
symbolButton -w 40 -h 40 -image "blinn.svg" -command "shadingNode -asShader blinn";


 showWindow;

Replies

  • Bodizzz
    Options
    Offline / Send Message
    Bodizzz polycounter lvl 9
    hi, I have created this little window so I can easily assign material to it. It's creating a material but not assigning material to the object.




     window;
       
                frameLayout -label "jayant";
                
                // add the other controls

    flowLayout -columnSpacing 7 -w 50 -h 50;

     // create six symbol buttons with related mel command
     
    symbolButton -w 40 -h 40 -image "blinn.svg" -command "shadingNode -asShader blinn";


     showWindow;
    Hey, edited your code a little bit. Try this
    proc createMat(){
    	
    	
    	 string $sel[] = `ls -sl`; 
    	 string $myBlinn = `shadingNode -asShader blinn`; 
    	 select -r $sel; 
    	 hyperShade -assign $myBlinn;
    }
    window;
     
    frameLayout -label "jayant";
                
    
    flowLayout -columnSpacing 7 -w 50 -h 50;
    
     
    symbolButton -w 40 -h 40 -image "blinn.svg" -c "createMat()" ;
    
    
    showWindow;
    


  • jayantbhatt007
    Options
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    Bodizzz said:
    hi, I have created this little window so I can easily assign material to it. It's creating a material but not assigning material to the object.




     window;
       
                frameLayout -label "jayant";
                
                // add the other controls

    flowLayout -columnSpacing 7 -w 50 -h 50;

     // create six symbol buttons with related mel command
     
    symbolButton -w 40 -h 40 -image "blinn.svg" -command "shadingNode -asShader blinn";


     showWindow;
    Hey, edited your code a little bit. Try this
    proc createMat(){
    	
    	
    	 string $sel[] = `ls -sl`; 
    	 string $myBlinn = `shadingNode -asShader blinn`; 
    	 select -r $sel; 
    	 hyperShade -assign $myBlinn;
    }
    window;
     
    frameLayout -label "jayant";
                
    
    flowLayout -columnSpacing 7 -w 50 -h 50;
    
     
    symbolButton -w 40 -h 40 -image "blinn.svg" -c "createMat()" ;
    
    
    showWindow;
    

    hi thank you so much it is working like a charm but suppose I f I want to assign lambert material to the button  I have to replace  blinn as lambert in the above command If Im right see here.


    proc createMat(){

    string $sel[] = `ls -sl`; 

    string $myBlinn = `shadingNode -asShader lambert`; 

    select -r $sel; 

    hyperShade -assign $mylambert;

    }

    window;

     

    frameLayout -label "jayant";

                


    flowLayout -columnSpacing 7 -w 50 -h 50;


     

    symbolButton -w 40 -h 40 -image "blinn.svg" -c "createMat()" ;











    showWindow;




  • Bodizzz
    Options
    Offline / Send Message
    Bodizzz polycounter lvl 9
    Bodizzz said:
    hi, I have created this little window so I can easily assign material to it. It's creating a material but not assigning material to the object.




     window;
       
                frameLayout -label "jayant";
                
                // add the other controls

    flowLayout -columnSpacing 7 -w 50 -h 50;

     // create six symbol buttons with related mel command
     
    symbolButton -w 40 -h 40 -image "blinn.svg" -command "shadingNode -asShader blinn";


     showWindow;
    Hey, edited your code a little bit. Try this
    proc createMat(){
    	
    	
    	 string $sel[] = `ls -sl`; 
    	 string $myBlinn = `shadingNode -asShader blinn`; 
    	 select -r $sel; 
    	 hyperShade -assign $myBlinn;
    }
    window;
     
    frameLayout -label "jayant";
                
    
    flowLayout -columnSpacing 7 -w 50 -h 50;
    
     
    symbolButton -w 40 -h 40 -image "blinn.svg" -c "createMat()" ;
    
    
    showWindow;
    

    hi thank you so much it is working like a charm but suppose I f I want to assign lambert material to the button  I have to replace  blinn as lambert in the above command If Im right see here.


    proc createMat(){

    string $sel[] = `ls -sl`; 

    string $myBlinn = `shadingNode -asShader lambert`; 

    select -r $sel; 

    hyperShade -assign $mylambert;

    }

    window;

     

    frameLayout -label "jayant";

                


    flowLayout -columnSpacing 7 -w 50 -h 50;


     

    symbolButton -w 40 -h 40 -image "blinn.svg" -c "createMat()" ;











    showWindow;




    Yeah, also you can  add another button and procedure for lambert 
  • jayantbhatt007
    Options
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5

    sir suppose I'm creating a button for Lambert and changing the command  ( you've provided) it is automatically changing the command of Blinn material also. see my whole script the last one.

    at last after running the command both materials are working as a Lambert.


    PLEASE DONT MIND I'M SUPER NOOB.


  • jayantbhatt007
    Options
    Offline / Send Message
    jayantbhatt007 polycounter lvl 5
    //AUTHOR : Jayant bhatt.
    //don't modify , don't distribute.
    //works with maya 2017 and 2018

    //PP


    if ( `window -exists "nameWindow"` ) {
    deleteUI "nameWindow";
    }

    // create a window with a menu bar
    window -title "3DGhost" -menuBar true -w 220 -h 200 "nameWindow";

    // two frame layouts will be laid out in a columna
    columnLayout;
    {
        if ( `window -exists CgGhost` ) {
          deleteUI CgGhost;

    }



    // create a tearOff menu
    menu -label "File" -tearOff true;
    // add the menu items
    menuItem -label "New" -command "NewScene";
    menuItem -label "Open" -command "OpenScene";
    menuItem -label "Save" -command "SaveScene";
    // menuItem -divider true -command "SaveScene";
    menuItem -label "Quit" -command "quit";
    // add a help menu
    menu -label "Credit" -helpMenu true;
    menuItem -label "Jayant bhatt";
    // add a help menu
    menu -label "Windows" -helpMenu true;
        menuItem -label "Outliner" -command "OutlinerWindow";
    menuItem -label "Hypershde" -command "HypershadeWindow";
    menuItem -label "Preferences" -command "PreferencesWindow";
    menuItem -label "Hotkey Editr " -command "HotkeyPreferencesWindow";
    menuItem -label "PluginManagr" -command "PluginManager;";
    // add a help menu
    menu -label "Display" -helpMenu true;
    menuItem -label "HideSelected"  -command "HideSelectedObjects";
    menuItem -label "ShowAll"  -command "ShowAll";
    menuItem -label "Polycount"  -command "TogglePolyCount";
    menuItem -label "Joint Size"  -command "jdsWin";
    menuItem -label "Ik/Fk Js"  -command "ikfkjdsWin";
    menuItem -label "Ik Handle Size"  -command "ikHdsWin";
    // create a collapsible frame layout
    frameLayout -collapsable true -label "Shapes";
    // add the other controls
    flowLayout -columnSpacing 1 -w 220 -h 30;
        // create six symbol buttons with related mel command
    symbolButton -image "cube.xpm" -command "polyCube";
    symbolButton -image "sphere.xpm" -command "CreatePolygonSphere";
    symbolButton -image "plane.xpm" -command "CreatePolygonPlane";
    symbolButton -image "cylinder.xpm" -command "CreatePolygonCylinder";
    symbolButton -image "circle.xpm" -command "CreateNURBSCircle";
    symbolButton -image "text.xpm" -command "CreatePolygonType";
    setParent ..;
    columnLayout;
                // create some text
    text -label " cube    sphre   Plne   Cylndr  Circle    Text    ";
    setParent ..;
    setParent ..;
    // create a collapsible frame layout
    frameLayout -collapsable true -label "Lights";
    // add the other controls

    flowLayout -columnSpacing 7 -w 20 -h 25;

     // create six symbol buttons with related mel command
     
    symbolButton -w 30 -h 30 -image "ambientlight.png" -command "CreateAmbientLight";
    symbolButton -w 30 -h 30 -image "directionallight.png" -command "CreateDirectionalLight";
    symbolButton -w 30 -h 30 -image "pointlight.png" -command "CreatePointLight";
    symbolButton -w 30 -h 30 -image "spotlight.png" -command "CreateSpotLight";
    symbolButton -w 30 -h 30 -image "arealight.png" -command "CreateAreaLight";
    symbolButton -w 30 -h 30 -image "volumelight.png" -command "CreateVolumeLight";
    setParent ..;
    columnLayout;
                // create some text
    text -label " Amb       Dir     Point    spot    Area      Vol    ";
    setParent ..;
    setParent ..;
    // three frame layouts will be laid out in a column
    columnLayout;
    // create a collapsible frame layout
    frameLayout -collapsable true -label "Options";
    // define the layout of controls added 
    // to the window.
    columnLayout;
    // add the other controls
    flowLayout -columnSpacing 1 -w 220 -h 33;
    // create a couple of buttons
    symbolButton -w 35 -h 35 -image "buttonManip.svg" -command "CenterPivot";
    symbolButton -image "multiCut_NEX32.png" -command "dR_multiCutTool";
    symbolButton -image "detach.png" -command "DetachComponent";
    symbolButton -w 35 -h 35 -image "GateMask.png" -command "PolyCircularize";
    symbolButton -w 35 -h 35 -image "addCreateGeneric_100.png" -command "CombinePolygons";
    symbolButton -w 35 -h 35 -image "mergeConnections.png" -command "SeparatePolygon";
    setParent ..;
    columnLayout;
                // create some text
    text -label "  CPvt   MCtol  Dattch  Circ   Comb   Sept    ";
    setParent ..;
    setParent ..;
    flowLayout -columnSpacing 1 -w 220 -h 30;
    // create a couple of buttons
    symbolButton -w 35 -h 35 -image "bridge_NEX32.png" -command "performBridgeOrFill";
    symbolButton -w 35 -h 35 -image "bevel.png" -command "BevelPolygon";
    symbolButton  -w 35 -h 35 -image "bezCorner.png" -command "SoftPolyEdgeElements 0";
    symbolButton  -w 35 -h 35 -image "bezNormalSelect.png" -command "SoftPolyEdgeElements 1";
    symbolButton  -w 35 -h 35 -image "reverseSurface.png" -command "ReversePolygonNormals";
    symbolButton  -w 35 -h 35 -image "UV.png" -command "TextureViewWindow";
                        
                        
                        setParent ..;
                       
                       columnLayout;
                // create some text
    text -label " Brdge    Bvl      HEd     SEd    Nrevse   UV    ";
                        setParent ..;
                       setParent ..;
       setParent ..;
                            

    // create a collapsible frame layout
    frameLayout -collapsable true -label "Constraint";
    // add the other controls
    flowLayout -columnSpacing 10 -w 224 -h 32;


    symbolButton -w 30 -h 30 -image "edges_NEX.png" -command "toolPropertyWindow";

    symbolButton -w 30 -h 30 -image "hyper_s_ON.png" -command "manipMoveSetXformConstraint edge";

    symbolButton -w 30 -h 30 -image "hyper_s_OFF.png" -command "manipMoveSetXformConstraint none";


                       setParent ..;
                      
                                    
    // create a collapsible frame layout
    frameLayout -collapsable true -label "Constraint";
    // add the other controls
    flowLayout -columnSpacing 10 -w 224 -h 38;   
         
          proc createMat(){
    string $sel[] = `ls -sl`; 
    string $myBlinn = `shadingNode -asShader blinn`; 
    select -r $sel; 
    hyperShade -assign $myBlinn;
    }
                
     flowLayout -columnSpacing 7 -w 40 -h 38;
     
     symbolButton -w 40 -h 40 -image "blinn.svg" -c "createMat()" ;
     
     setParent ..;

     
      proc createMat(){
    string $sel[] = `ls -sl`; 
    string $lambert = `shadingNode -asShader lambert`; 
    select -r $sel; 
    hyperShade -assign $lambert;
    }
                
     flowLayout -columnSpacing 7 -w 40 -h 38;
     
     symbolButton -w 40 -h 40 -image "blinn.svg" -c "createMat()" ;
     


    showWindow;
    }
Sign In or Register to comment.