Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def run():
- updateSwitchControl()
- def remove():
- removeSwitchControl()
- def colorNodes():
- colorNodes()
- def setBypass():
- setBypass()
- def updateSwitchControl():
- approvedNodes = getApprovedNodes()
- controlNode = hou.pwd()
- nodeName = hou.pwd().name()
- prefixList = getPrefixes( controlNode )
- genControlNodeUI( controlNode )
- def getTypeAndPrefix( aNode, prefixList ):
- prefix = aNode.name().split( "_" )
- if prefix[0] not in prefixList:
- preFix = "Unsorted"
- else:
- preFix = prefix[0]
- renderNodes = [ "ieMantra", "ifd" ]
- brpNodes = [ "ieBundlePublisher" ]
- if aNode.type().name() in renderNodes:
- curType = "Renders"
- if aNode.type().name() in brpNodes:
- curType = "BRPs"
- if not aNode.type().name() in renderNodes and not aNode.type().name() in brpNodes :
- curType = "Sims"
- return curType, preFix
- def getPrefixes( controlNode ):
- approvedNodes = getApprovedNodes()
- prefixList = []
- prefixes = controlNode.parm( "prefixes" ).evalAsString()
- if prefixes:
- prefixList = prefixes.split( " " )
- else:
- for aNode in approvedNodes:
- prefix = aNode.name().split( "_" )
- if ( len( prefix ) > 1 ):
- prefixList.append( prefix[0] )
- prefixList = list( set( prefixList ) )
- return prefixList
- def getIdFromOutput( parentNode, childNode ):
- i = 0
- for input in childNode.inputs():
- if parentNode.name() == input.name():
- return{ "node":childNode, "connectionID":i }
- else:
- i += 1
- def removeSwitchControl():
- nodeCheck = 0
- approvedNodes = getApprovedNodes()
- for aNode in approvedNodes:
- origColor = hou.Color( [ aNode.parm( "orig_colorx" ).eval(), aNode.parm( "orig_colory" ).eval(), aNode.parm( "orig_colorz" ).eval() ] )
- aNode.setColor( origColor )
- templateGroup = hou.pwd().parmTemplateGroup()
- templateGroup.clear()
- hou.pwd().setParmTemplateGroup( templateGroup )
- def getFolderNames():
- return [ 'Renders', 'Sims', 'BRPs' ]
- def genControlNodeUI( controlNode ):
- approvedNodes = getApprovedNodes()
- templateGroup = controlNode.parmTemplateGroup()
- prefixList = getPrefixes( controlNode )
- rememberParms = []
- folderNames = getFolderNames()
- for folder in folderNames:
- for parm in templateGroup.parmTemplates():
- if parm.label() == folder:
- for folderParm in parm.parmTemplates():
- value = controlNode.parm( folderParm.name() ).eval()
- rememberParms.append( { "name":folderParm.name(), "value":value, "parm":folderParm } )
- templateGroup.remove( parm.name() )
- templateGroup.addParmTemplate( hou.FolderParmTemplate( folder.lower(), folder ))
- controlNode.setParmTemplateGroup( templateGroup )
- renderParms = {}
- simParms = {}
- brpParms = {}
- rparms = []
- sparms = []
- bparms = []
- unsortedCounter = 0
- for aNode in approvedNodes:
- curType, preFix = getTypeAndPrefix( aNode, prefixList )
- if curType == "Renders":
- rparms.append( {"prefix":preFix, "name":"%s_switch" %aNode.name(), "parm":hou.ToggleParmTemplate("%s_switch" %aNode, "%s" %aNode, disable_when="{ %s_off == 1 } { %s_%s_switch == 1 }" %(curType, curType, preFix), script_callback="hou.pwd().hdaModule().setBypass()", script_callback_language=hou.scriptLanguage.Python ) } )
- if curType == "Sims":
- sparms.append( {"prefix":preFix, "name":"%s_switch" %aNode.name(), "parm":hou.ToggleParmTemplate("%s_switch" %aNode, "%s" %aNode, disable_when="{ %s_off == 1 } { %s_%s_switch == 1 }" %(curType, curType, preFix), script_callback="hou.pwd().hdaModule().setBypass()", script_callback_language=hou.scriptLanguage.Python ) } )
- if curType == "BRPs":
- bparms.append( {"prefix":preFix, "name":"%s_switch" %aNode.name(), "parm":hou.ToggleParmTemplate("%s_switch" %aNode, "%s" %aNode, disable_when="{ %s_off == 1 } { %s_%s_switch == 1 }" %(curType, curType, preFix), script_callback="hou.pwd().hdaModule().setBypass()", script_callback_language=hou.scriptLanguage.Python ) } )
- if preFix == "Unsorted":
- unsortedCounter += 1
- if unsortedCounter > 0:
- prefixList.append( "Unsorted" )
- allParms = {}
- allParms.update( { "Renders": rparms } )
- allParms.update( { "Sims" : sparms } )
- allParms.update( { "BRPs" : bparms } )
- for folder in folderNames:
- for prefix in prefixList:
- prefixCounter = 0
- for aParm in allParms[ folder ]:
- if aParm[ "prefix" ] == prefix:
- prefixCounter = 1
- break
- if prefixCounter == 1:
- if controlNode.parm( "prefix_off" ).eval():
- hide = 0
- else:
- hide = 1
- prefixToggle = hou.ToggleParmTemplate( "%s_%s_switch" %(folder, prefix), "---- Off %s's ----" %prefix, is_hidden=hide, disable_when="{ %s_off == 1 }" %folder, script_callback="hou.pwd().hdaModule().setBypass()", script_callback_language=hou.scriptLanguage.Python )
- checkAndApplyTemplate( "%s_%s_switch"%( folder, prefix ), prefixToggle, controlNode, folder )
- for parm in allParms[ folder ]:
- if prefix in parm[ "prefix" ]:
- checkAndApplyTemplate( parm[ "name" ], parm[ "parm" ], controlNode, folder )
- if controlNode.parm( "prefix_off" ).eval() == 1:
- continue
- for setParm in rememberParms:
- if controlNode.parm( setParm[ "name" ] ):
- controlNode.setParms( { setParm[ "name" ] : setParm[ "value" ] } )
- setBypass()
- def getApprovedNodes():
- nodeTypes = [ "ifd", "alembic", "filmboxfbx", "geometry", "ieMantra", "fetch", "ieBundlePublisher" ]
- node = hou.pwd()
- approvedNodes = []
- for aNode in node.inputAncestors( include_ref_inputs=False ):
- if aNode.type().name() in nodeTypes:
- approvedNodes.append( aNode )
- return approvedNodes
- def checkAndApplyTemplate( checkFor, addThis, controlNode, curType ):
- templateGroup = controlNode.parmTemplateGroup()
- folderNames = getFolderNames()
- if templateGroup.find( checkFor ):
- templateGroup.replace( checkFor, addThis )
- else:
- templateGroup.appendToFolder( curType, addThis )
- controlNode.setParmTemplateGroup( templateGroup )
- def colorNodes():
- ieMantraColor = hou.Color( [ 0.6, 0.6, 1.0 ] )
- geoColor = hou.Color( [ 0.0, 0.53, 0.0 ] )
- brpColor = hou.Color( [ 0.2, 0, 0.4 ] )
- approvedNodes = getApprovedNodes()
- for aNode in approvedNodes:
- if aNode.parm("orig_colorx"):
- pass
- else:
- origColor = [aNode.color().rgb()[0], aNode.color().rgb()[1], aNode.color().rgb()[2] ]
- templateGroup = aNode.parmTemplateGroup()
- origColorParm = hou.FloatParmTemplate("orig_color", "OrigColor", 3, default_value=origColor, is_hidden=True)
- templateGroup.append(origColorParm)
- aNode.setParmTemplateGroup(templateGroup)
- renderNodes = [ "ieMantra", "ifd" ]
- brpNodes = [ "ieBundlePublisher" ]
- if aNode.type().name() in renderNodes:
- aNode.setColor( ieMantraColor )
- if aNode.type().name() in brpNodes:
- aNode.setColor( brpColor )
- if not aNode.type().name() in renderNodes and not aNode.type().name() in brpNodes:
- aNode.setColor( geoColor )
- curNode = hou.pwd()
- curNode.setColor( hou.Color( [ 0.8, 0.8, 0.8 ] ) )
- def setBypass():
- controlNode = hou.pwd()
- prefixList = getPrefixes( controlNode )
- approvedNodes = getApprovedNodes()
- for aNode in approvedNodes:
- curType, prefix = getTypeAndPrefix( aNode, prefixList )
- name = aNode.name()
- bypass = False
- if controlNode.parm( "%s_switch"%name ).eval() == 0 or controlNode.parm( "%s_off"%curType ).eval() == 1 or controlNode.parm( "%s_%s_switch"%( curType, prefix ) ).eval() == 1:
- bypass = True
- aNode.bypass( bypass )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement