VRay Subdivision

This script will go through all your selected meshes in your scene and add or delete a subdivision tag. There is a window to set all your normal subdivision settings and check boxes.  There is also a tab that will add or delete rounded edges to your selected objects and you can set the round edge radius.

To Run: Select the objects you want to add subdivision or rounded edges to then run the script.

#VRay Subdivision and Rounded Edges for Maya version 2.0.0
#Bryanna London www.bryannalondon.com
#!/usr/bin/env python
#UPDATED for VRay 2.4 and later

#Adds Vray Subdivision tag to all selected geo. You can also
#Add the vray rounded edges tag to all selected geo.
import maya.cmds as cmds
import maya.mel as mel

#define quiered values as empty list
#this will get rid of variable not defined error
queriedValues=[]

#delete window if a window already exisits
if cmds.window('subdWindow', exists=True):
    cmds.deleteUI('subdWindow')

#Create my GUI
def createGUI():
    #window layout
    subdWindow= cmds.window('subdWindow',title="Add SubDivisions", rtf=True)
    tabs = cmds.tabLayout(innerMarginWidth=8, innerMarginHeight=3)

    child1 = cmds.columnLayout(adjustableColumn= True, rowSpacing= 3)
    cmds.optionMenu('mapBorders', label='Map Borders')
    cmds.menuItem( label='Internal')
    cmds.menuItem( label='None' )
    cmds.menuItem( label='All' )
    cmds.checkBox('renderSubD',label= "Render as SubD", value=True)
    cmds.checkBox('genStaticGeo', label= "Generate Static Geo", value=False)
    cmds.checkBox('overrideGlobal',label= "Overide Global Settings On", value=True)
    cmds.checkBox('viewDepend', label = "View Dependent On", value=True)
    cmds.checkBox('catmull', label = "Classic Catmull Clark", value=False)
    cmds.intFieldGrp('edgeLength',numberOfFields=1, label="Edge Length", value1=1)
    cmds.intFieldGrp('maxSubD',numberOfFields=1, label='Max SubD', value1=4)
    cmds.rowColumnLayout(numberOfRows = 1)
    cmds.button( label='SUBD ON', width= 112, command=('meshSelection()'))
    cmds.button( label='SUBD OFF', width= 112, command=('subDOff()'))
    cmds.setParent('..')
    cmds.columnLayout()
    cmds.button( label='Close', width= 224, command=('cmds.deleteUI(\"' + subdWindow + '\", window=True)'))
    cmds.setParent('..')
    cmds.setParent('..')

    child2 = cmds.columnLayout(adjustableColumn= True, rowSpacing= 3)
    cmds.floatFieldGrp('roundEdgeRadius',numberOfFields=1, label="Round Edge Radius", precision= 3, value1=.02)
    cmds.rowColumnLayout(numberOfRows = 1)
    cmds.button( label='ROUND EDGES ON', width = 112, command=('addRoundedEdges()'))
    cmds.button( label='ROUND EDGES OFF', width = 112, command=('offRoundedEdges()'))
    cmds.setParent('..')
    cmds.columnLayout()
    cmds.button( label='Close', width= 224, command=('cmds.deleteUI(\"' + subdWindow + '\", window=True)'))
    cmds.setParent('..')
    cmds.setParent('..')

    cmds.tabLayout( tabs, edit=True, tabLabel=((child1, 'SubD'), (child2, 'Round Edges')) )
    cmds.showWindow('subdWindow')

#Query Values inputed in GUI for Subdivision tab
def queryValues():

   x= cmds.intFieldGrp('edgeLength',query=True, value=True)
   y= cmds.intFieldGrp('maxSubD', query=True, value=True)

   z= int(cmds.checkBox('renderSubD', query = True, value = True))
   a= int(cmds.checkBox('genStaticGeo', query=True, value=True))
   b= int(cmds.checkBox('overrideGlobal', query=True, value=True))
   c= int(cmds.checkBox('viewDepend', query = True, value = True))
   e= int(cmds.checkBox('catmull', query = True, value = True))

   #query option menu
   selectedMenuItem = cmds.optionMenu('mapBorders', query = True, value = True)
   #print selectedMenuItem

   if selectedMenuItem == 'Internal':
      menuValue = 1

   if selectedMenuItem == 'None':
       menuValue = 0

   if selectedMenuItem == 'All':
       menuValue = 2
   #query checkboxes
   queriedValuesZ, queriedValuesA, queriedValuesB, queriedValuesC, queriedValuesE = z, a, b, c, e
   #query intFieldGrp
   queriedValuesX,queriedValuesY = x, y

   #print and return values from GUI
   #print queriedValuesX + queriedValuesY, queriedValuesZ, queriedValuesA, queriedValuesB, queriedValuesC, queriedValuesE, menuValue
   return queriedValuesX[-1],queriedValuesY[0], queriedValuesZ, queriedValuesA, queriedValuesB, queriedValuesC, queriedValuesE, menuValue

#query round edges tab
def queryRoundEdge():

    d= cmds.floatFieldGrp('roundEdgeRadius', query=True, value=True)
    queriedValuesD = d
    #print queriedValuesD
    return queriedValuesD[0]
#have quiered values run the queryValues definition then print the outputed variables values
#Put all selected meshes in a string
#For all selected meshes turn on VRay subdivisions and SubD Quality
#If there is nothing selected give a warning
#this definition will run when Execute is selected
def meshSelection():

    queriedValuesX,queriedValuesY, queriedValuesZ, queriedValuesA, queriedValuesB, queriedValuesC, queriedValuesE, menuValue = queryValues()
    #print queriedValuesX
    #print queriedValuesY
    #print queriedValuesZ
    #print queriedValuesA
    #print queriedValuesB
    #print queriedValuesC
    #print queriedValuesE
    #print menuValue

    mesh = ''
    meshes = cmds.ls(selection = True, dag = True, lf = True, visible=True, type = 'mesh')

    if cmds.ls(sl=True):

        for mesh in meshes:

            mel.eval('vray addAttributesFromGroup %s vray_subdivision 1' % mesh)
            mel.eval('vray addAttributesFromGroup %s vray_subquality 1' % mesh)
            cmds.evalDeferred("cmds.setAttr('%s.vrayPreserveMapBorders', %s)" %(mesh, menuValue))
            cmds.evalDeferred("cmds.setAttr('%s.vraySubdivEnable', %s)" %(mesh, queriedValuesZ))
            cmds.evalDeferred("cmds.setAttr('%s.vrayStaticSubdiv', %s)" %(mesh, queriedValuesA))
            cmds.evalDeferred("cmds.setAttr('%s.vrayOverrideGlobalSubQual', %s)" %(mesh, queriedValuesB))
            cmds.evalDeferred("cmds.setAttr('%s.vrayViewDep', %s)"%(mesh, queriedValuesC))
            cmds.evalDeferred("cmds.setAttr('%s.vrayClassicalCatmark', %s)" %(mesh, queriedValuesE))
            cmds.evalDeferred("cmds.setAttr('%s.vrayEdgeLength',%s )"%(mesh, queriedValuesX))
            cmds.evalDeferred("cmds.setAttr('%s.vrayMaxSubdivs',%s)"%(mesh, queriedValuesY))

    else:

        cmds.confirmDialog(title='Confirm', message='Nothing Selected. Nothing Done.' , button =['Ok'])

#Off button command to turn the Subdivision tags
#For all meshes selected turn the subdivisions tags off
#this will run if the Turn SubD Off button is selected
def subDOff():

    objects = cmds.ls(selection = True, dag = True, lf = True, visible=True, type = 'mesh')

    if cmds.ls(sl=True):

        for ob in objects:

            mel.eval('vray addAttributesFromGroup %s vray_subdivision 0' % ob)
            mel.eval('vray addAttributesFromGroup %s vray_subquality 0' % ob)

    else:

        cmds.confirmDialog(title='Confirm', message='Nothing Selected. Nothing Done.' , button =['Ok'])

#Add Rounded  Edges
def addRoundedEdges():

    queriedValuesD = queryRoundEdge()
    print queriedValuesD

    selectedObj = cmds.ls(selection = True, dag = True, lf = True, visible=True, type = 'mesh')

    if cmds.ls(sl=True):

        for sel in selectedObj:

            mel.eval('vray addAttributesFromGroup %s vray_roundedges 1' % sel)
            cmds.evalDeferred("cmds.setAttr('%s.vrayRoundEdgesRadius',%s)"%(sel, queriedValuesD))

    else:

        cmds.confirmDialog(title='Confirm', message='Nothing Selected. Nothing Done.' , button =['Ok'])

#Turn off Rounded Edges

def offRoundedEdges():

    offObjects = cmds.ls(selection = True, dag = True, lf = True, visible=True, type = 'mesh')

    if cmds.ls(sl=True):

        for offObj in offObjects:

            mel.eval('vray addAttributesFromGroup %s vray_roundedges 0' % offObj)

    else:

        cmds.confirmDialog(title='Confirm', message='Nothing Selected. Nothing Done.' , button =['Ok'])

#Show the GUI
createGUI()

© 2016 Bryanna London

Advertisements