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.
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.
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
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.
It doesn't error out or tell me my usage needs more arguments.... it simply tells me
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....
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");
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)
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)
Code:
# Error: addAttributesFromGroup: node [u'pSphereShape1'] not found. #
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 #
Comment