Announcement

Collapse
No announcement yet.

Converting Vray MEL to Python

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting Vray MEL to Python

    I've been going back through the Vray toolkit I made for myself and trying to convert it from the original MEL into Python

    I am having trouble with the formatting since I am trying to copy from web examples of Python which rarely have Vray specific command examples.

    So, for instance I have a standard apply Vray Subdivision to all items selected (avoiding the menu repeats). ANother that adds oth SubD and disp control etc etc. A remove all script and so on.


    Here is the add Vray SubD In it's MEL form. It also applies the settings at the bottom.

    Code:
    string $mySelection[]= `listRelatives  -shapes`;
    
    print $mySelection;
    
    for ($object in $mySelection){
        
        vray addAttributesFromGroup $object vray_subdivision 1;
        vrayAddAttr $object vraySubdivEnable;
        vrayAddAttr $object vraySubdivUVsAtBorders;
        vrayAddAttr $object vraySubdivUVs;
        vrayAddAttr $object vrayStaticSubdiv;
        vray addAttributesFromGroup $object vray_subquality 1;
        vrayAddAttr $object vrayOverrideGlobalSubQual;
        vrayAddAttr $object vrayViewDep;
        vrayAddAttr $object vrayEdgeLength;
        vrayAddAttr $object vrayMaxSubdivs;
    
        vray addAttributesFromGroup $object vray_displacement 1;
        vrayAddAttr $object vrayDisplacementNone;
        vrayAddAttr $object vrayDisplacementType;
        vrayAddAttr $object vrayDisplacementAmount;
        vrayAddAttr $object vrayDisplacementShift;
        vrayAddAttr $object vrayDisplacementKeepContinuity;
        vrayAddAttr $object vrayEnableWaterLevel;
        vrayAddAttr $object vrayWaterLevel;
        vrayAddAttr $object vray2dDisplacementResolution;
        vrayAddAttr $object vray2dDisplacementPrecision;
        vrayAddAttr $object vray2dDisplacementTightBounds;
        vrayAddAttr $object vray2dDisplacementFilterTexture;
        vrayAddAttr $object vray2dDisplacementFilterBlur;
        vrayAddAttr $object vrayDisplacementUseBounds;
        vrayAddAttr $object vrayDisplacementMinValue;
        vrayAddAttr $object vrayDisplacementMaxValue;
    
    setAttr ($object+".vrayMaxSubdivs") 4;
    setAttr ($object+".vrayEdgeLength") 4.0;
    
    }
    
    print("Applied All Vray SubDivision");
    So I am trying to begin converting this to Python...

    Right off I am having trouble with the commands usage, arguments, what belongs in quotes, and ordering. Mainly because I don't see many example usages like you can get in the MEL or Python pages at Autodesk.

    Code:
    import maya.cmds as mc
    
    
    mySel = mc.listRelatives(s=True)
    print mySel
    
    
    for i in mySel:
        mc.vray("addAttributesFromGroup", mySel[i], "vray_subdivion", 1)
        mc.vray("AddAttr", mySel[i], "vraySubdivEnable")
        mc.vray("AddAttr", mySel[i], "vraySubdivUVsAtBorders")
        mc.vray("AddAttr", mySel[i], "vraySubdivUVs")
        mc.vray("AddAttr", mySel[i], "vrayStaticSubdiv")
        mc.vray("addAttributesFromGroup", [i], "vray_subquality", 1)
        mc.vray("AddAttr", mySel[i], "vrayOverrideGlobalSubQual")
        mc.vray("AddAttr", mySel[i], "vrayViewDep")
        mc.vray("AddAttr", mySel[i], "vrayEdgeLength")
        mc.vray("AddAttr", mySel[i], "vrayMaxSubdivs")

    Now, there is usage examples for Vray addAttributesFromGroup, but there isn't for simply Vray AddAttr.

    In some places I found usage examples that don't look for =True or False.

    Like this. From https://github.com/BigRoy/mayaVrayCommandDocs/wiki

    Code:
    vray("addAttributesFromGroup", node, attrGroup, state)
    But when I use just this line (note I changed the =True to 1 and put the vray_subdivision in quites)... instead of the whole loop.

    Code:
    import maya.cmds as mc
    
    
    mySel = mc.listRelatives(s=True)
    print mySel
    
    for i in mySel:
        mc.vray("addAttributesFromGroup", mySel[i], "vray_subdivion", 1)
    It doesn't error out or tell me my usage needs more arguments.... it simply tells me


    Code:
    # Error: addAttributesFromGroup: node [u'pSphereShape1'] not found. #
    So, my Python formatting isn't correct of course. I'm either not formatting the Vray commands in brackets/quotes, commas, correctly. OR the way it is applying the shape node into the brackets is incorrect.

    Thanks. I've done quite a few conversions of my old MEL scripts into Maya simply following usage examples and just need some Vray specific help.


    ---EDIT---- OK I changed the [i] to mySel[i] for the iterations. But now it is telling me....
    Code:
    list indices must be integers, not unicode #
    Last edited by Intuition; 18-02-2016, 01:01 PM.
    ------
    KC

  • #2
    Hah ok I figured it out..

    I had a spelling error and then was also misusing the array/list by placing my whole variable "mySel" instead of the for loop variable "i" for the object. This works.
    Code:
    import maya.cmds as mc
    
    for i in mySel:
        mc.vray("addAttributesFromGroup", i, "vray_subdivision", 1)
        mc.vray("addAttributesFromGroup", i, "vray_subquality",1) 
        mc.vray("addAttributesFromGroup", i, "vray_displacement", 1)
    Last edited by Intuition; 19-02-2016, 02:57 AM.
    ------
    KC

    Comment


    • #3
      Ok I can't seem to figure out the correct formatting for set a Vray attribute though

      Code:
      mc.setAttr (i,"vrayMaxSubdivs", 12)
      mc.setAttr (i, "vrayEdgeLength", 0.001)
      It gives me either an indentation error OR that the attribute doesn't exist.
      ------
      KC

      Comment


      • #4
        The Maya help says you should do:

        Code:
        mc.setAttr (i+".vrayMaxSubdivs", 12)
        V-Ray/PhoenixFD for Maya developer

        Comment


        • #5
          DOh, Thank you.

          .....of course, my MEL adds the two together in brackets, why didn't I see that?
          ------
          KC

          Comment

          Working...
          X