Home Technical Talk

[Maya] Various Mel scripts questions

greentooth
Offline / Send Message
Froyok greentooth
Hi polycounters ! 0/

Since a few hours (maybe more) I'm trying to learn and make a custom tool for Maya and my workflow.
I have already programmed in C++ in the past, so the Mel language is not so hard to understand for me.

The hard part is to find the name of the various function inside maya, but even with that, I still have some problems:

----
Currently, I'm trying to applying a shader on an object selected in the scene.
When my script start, I create my shaders like this :
global string $shaderRetopo; //red retopo shader
    global string $shaderHighpoly; //blue high poly shader

    //setup shaders
    $shaderRetopo   =    `shadingNode -asShader -shared -name "sh_Retopo" phong`;
    setAttr($shaderRetopo+".transparency")     -type double3 0.25 0.25 0.25; //must be done just after, or we need to reselect the shader before
    setAttr($shaderRetopo+".color")     -type double3 0.5 0.0 0.0;
    
    $shaderHighpoly =    `shadingNode -asShader -shared -name "sh_Highpoly" lambert`;
    setAttr($shaderHighpoly+".transparency")     -type double3 0.25 0.25 0.25;
    setAttr($shaderHighpoly+".color")     -type double3 0.4 0.5 0.8;
This is the easiest part for me.
Now, even if I try to understand as much I can, I can't figure out how to select the last object in my current selection and apply the shader on it.

I have tested this :
global proc froApplyShader(int $input)
{
    global string $shaderRetopo;
    global string $shaderHighpoly;
    string $temp = "";
    
    if($input == 1) //apply red shader
    {
        $temp = $shaderRetopo+"SG";
    }
    else //apply blue shader
    {
        $temp = $shaderHighpoly+"SG";
    }
    
    sets -e -forceElement $temp;
}
But in maya a get an error, it looks like my variable are empty, even if the shaders are well created in the hypershade.


----
My second attemp is to change the current component mode on the last selected object, i have tried this :
global proc froChangeSelectMode(int $input)
{
    string $select[] = `ls -sl`;
    int $mxSel = `size($select)`;

    //select -cl; //clear selection 
    
    //change mode on the last selected object
    if($input == 4)
        doMenuComponentSelection($select[$mxSel], "meshComponents");
    else if ($input == 3)
        doMenuComponentSelection($select[$mxSel], "facet");
    else if ($input == 2)
        doMenuComponentSelection($select[$mxSel], "edge");
    else if ($input == 1)
        doMenuComponentSelection($select[$mxSel], "vertex");
    else
        select -r $select[$mxSel]; //classic select, object mode
}
But it's not working and I can't get why.



Any help will be greatly rewarded with my eternal gratitude! :)

Replies

  • MiAlx
    Options
    Offline / Send Message
    MiAlx polycounter lvl 10
    Hmm not sure but for the last one maybe try this:

    doMenuComponentSelection($select[$mxSel] + ", edge");

    But im not 100% sure, try it out and tell me :)
  • Froyok
    Options
    Offline / Send Message
    Froyok greentooth
    Unfortunately, it's not working.
    I have also tested $select[$mxSel].name .
    In both case it give me a syntax error.
  • bk3d
    Options
    Offline / Send Message
    bk3d polycounter lvl 5
    $Sel = `ls -sl -fl`;
    select $Sel[`size $Sel` -1];


    since the array starts at 0, to select the last object you have to subtract 1 from the size of the array.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Froyok wrote: »
    Unfortunately, it's not working.
    I have also tested $select[$mxSel].name .
    In both case it give me a syntax error.

    mel doesnt do dot syntax just as an fyi. bk3d has it.
  • Froyok
    Options
    Offline / Send Message
    Froyok greentooth
    Thanks a lot guys ! With your help it's now working ! :)

    I'm trying now to acheving something more complex.
    I would like to change a little the way of how maya select object.
    My purpose is when a vertex is selected and I try to move it, I would like to duplicate it.
    I know hot to do this, what I don't know is of to make the difference between the middle click&drag and the left click&drag.
    It's possible to change the way of how Maya handle this ?
    By default maya move directly move the last selection that you have to you mouse pinter when you use the middle mouse button.
  • bk3d
    Options
    Offline / Send Message
    bk3d polycounter lvl 5
    Not sure what your asking.. are you asking how to duplicate a vertex or an object?
    If its an object and you have a vertex selected. you can get the object name with `ls -hl`.

    also a better board might be on CGTalk. on the Mel thread.
  • Froyok
    Options
    Offline / Send Message
    Froyok greentooth
    No, no, I know how to duplicate it, what I don't know if it's possible to change the mouse hotkey ? Particularly the middle click of the mouse.

    I will try CGTalk then. :)
  • happyprince_40
    Hi everyone..,
    can any one help me to make a mel script which by clicking on the button does the below all at once..

    1. creates a new layer with the selected objects with a specified name (for ex : dummy layer) .

    ----> for each and every object in the master layer has its own shader and one alpha map in their shader transparency slot.

    2. after creating the dummy layer, it should automatically replace its shader with surface shader and should connect its respecitve alpha map in the surface shader out transparency slot.

    Thanks in advance..
  • happyprince_40
    Hi everyone..,
    can any one help me to make a mel script which by clicking on the button does the below all at once..

    1. creates a new layer with the selected objects with a specified name (for ex : dummy layer) .

    ----> for each and every object in the master layer has its own shader and one alpha map in their shader transparency slot.

    2. after creating the dummy layer, it should automatically replace its shader with surface shader and should connect its respecitve alpha map in the surface shader out transparency slot.

    Thanks in advance..
  • Froyok
    Options
    Offline / Send Message
    Froyok greentooth
    I think mapping your own topic instead of spamming this one will be more effective.

    Maya do a feedback of your command in the script editor window. I'm pretty sure you will found what you want. Simply look in it what happen when you make a new layer, etc.
  • dproeder
    Options
    Offline / Send Message
    dproeder polycounter lvl 5
    Froyok wrote: »
    I think mapping your own topic instead of spamming this one will be more effective.

    Maya do a feedback of your command in the script editor window. I'm pretty sure you will found what you want. Simply look in it what happen when you make a new layer, etc.

    How 68.956% of all scripts are made.
Sign In or Register to comment.