Advertisement
yashpolke

DependencyManager

Nov 1st, 2016
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.48 KB | None | 0 0
  1. import sys
  2.  
  3. def run():
  4.     updateSwitchControl()
  5.    
  6. def remove():
  7.     removeSwitchControl()
  8.    
  9. def colorNodes():
  10.     colorNodes()
  11.    
  12. def setBypass():
  13.     setBypass()
  14.    
  15. def updateSwitchControl():
  16.     approvedNodes = getApprovedNodes()
  17.     controlNode   = hou.pwd()
  18.     nodeName      = hou.pwd().name()
  19.     prefixList    = getPrefixes( controlNode )
  20.     genControlNodeUI( controlNode )
  21.  
  22. def getTypeAndPrefix( aNode, prefixList ):
  23.     prefix = aNode.name().split( "_" )
  24.     if prefix[0] not in prefixList:
  25.         preFix = "Unsorted"
  26.     else:
  27.         preFix = prefix[0]
  28.        
  29.     renderNodes = [ "ieMantra", "ifd" ]
  30.     brpNodes    = [ "ieBundlePublisher" ]
  31.  
  32.     if aNode.type().name() in renderNodes:
  33.         curType = "Renders"
  34.     if aNode.type().name() in brpNodes:
  35.         curType = "BRPs"
  36.     if not aNode.type().name() in renderNodes and not aNode.type().name() in brpNodes :
  37.         curType = "Sims"
  38.     return curType, preFix
  39.  
  40. def getPrefixes( controlNode ):
  41.    
  42.     approvedNodes = getApprovedNodes()
  43.     prefixList = []
  44.     prefixes = controlNode.parm( "prefixes" ).evalAsString()
  45.    
  46.     if prefixes:
  47.         prefixList = prefixes.split( " " )
  48.     else:
  49.         for aNode in approvedNodes:
  50.             prefix = aNode.name().split( "_" )
  51.             if ( len( prefix ) > 1 ):
  52.                 prefixList.append( prefix[0] )
  53.         prefixList = list( set( prefixList ) )
  54.     return prefixList
  55.  
  56. def getIdFromOutput( parentNode, childNode ):
  57.  
  58.     i = 0
  59.     for input in childNode.inputs():
  60.         if parentNode.name() == input.name():
  61.             return{ "node":childNode, "connectionID":i }
  62.         else:
  63.             i += 1
  64.            
  65. def removeSwitchControl():
  66.     nodeCheck     = 0
  67.     approvedNodes = getApprovedNodes()
  68.     for aNode in approvedNodes:
  69.         origColor = hou.Color( [ aNode.parm( "orig_colorx" ).eval(), aNode.parm( "orig_colory" ).eval(), aNode.parm( "orig_colorz" ).eval() ] )
  70.         aNode.setColor( origColor )
  71.  
  72.     templateGroup = hou.pwd().parmTemplateGroup()
  73.     templateGroup.clear()
  74.     hou.pwd().setParmTemplateGroup( templateGroup )
  75.  
  76. def getFolderNames():
  77.     return [ 'Renders', 'Sims', 'BRPs' ]
  78.    
  79. def genControlNodeUI( controlNode ):
  80.     approvedNodes = getApprovedNodes()
  81.     templateGroup = controlNode.parmTemplateGroup()
  82.     prefixList    = getPrefixes( controlNode )
  83.    
  84.     rememberParms = []
  85.     folderNames   = getFolderNames()
  86.     for folder in folderNames:
  87.         for parm in templateGroup.parmTemplates():
  88.             if parm.label() == folder:
  89.                 for folderParm in parm.parmTemplates():
  90.                     value = controlNode.parm( folderParm.name() ).eval()
  91.                     rememberParms.append( { "name":folderParm.name(), "value":value, "parm":folderParm } )
  92.                 templateGroup.remove( parm.name() )
  93.         templateGroup.addParmTemplate( hou.FolderParmTemplate( folder.lower(), folder ))
  94.     controlNode.setParmTemplateGroup( templateGroup )
  95.        
  96.     renderParms = {}
  97.     simParms    = {}
  98.     brpParms    = {}
  99.  
  100.     rparms      = []
  101.     sparms      = []
  102.     bparms      = []
  103.  
  104.     unsortedCounter = 0
  105.     for aNode in approvedNodes:
  106.         curType, preFix = getTypeAndPrefix( aNode, prefixList )
  107.         if curType                 == "Renders":
  108.             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 ) } )
  109.         if curType                 == "Sims":
  110.             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 ) } )
  111.         if curType                 == "BRPs":
  112.             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 ) } )
  113.                
  114.         if preFix == "Unsorted":
  115.             unsortedCounter += 1
  116.         if unsortedCounter > 0:
  117.         prefixList.append( "Unsorted" )
  118.  
  119.     allParms = {}
  120.     allParms.update( { "Renders": rparms } )
  121.     allParms.update( { "Sims"   : sparms } )
  122.     allParms.update( { "BRPs"    : bparms } )
  123.    
  124.     for folder in folderNames:
  125.         for prefix in prefixList:
  126.            
  127.             prefixCounter = 0
  128.             for aParm in allParms[ folder ]:
  129.                 if aParm[ "prefix" ] == prefix:
  130.                     prefixCounter = 1
  131.                     break
  132.             if prefixCounter == 1:
  133.                 if controlNode.parm( "prefix_off" ).eval():
  134.                     hide = 0
  135.                 else:
  136.                     hide = 1
  137.                 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 )
  138.                 checkAndApplyTemplate( "%s_%s_switch"%( folder, prefix ), prefixToggle, controlNode, folder )
  139.                
  140.             for parm in allParms[ folder ]:
  141.                 if prefix in parm[ "prefix" ]:
  142.                     checkAndApplyTemplate( parm[ "name" ], parm[ "parm" ], controlNode, folder )
  143.             if controlNode.parm( "prefix_off" ).eval() == 1:
  144.                 continue
  145.     for setParm in rememberParms:
  146.         if controlNode.parm( setParm[ "name" ] ):
  147.             controlNode.setParms( { setParm[ "name" ] : setParm[ "value" ] } )
  148.            
  149.     setBypass()
  150.    
  151. def getApprovedNodes():
  152.     nodeTypes     = [ "ifd", "alembic", "filmboxfbx", "geometry", "ieMantra", "fetch", "ieBundlePublisher" ]
  153.     node          = hou.pwd()
  154.     approvedNodes = []
  155.     for aNode in node.inputAncestors( include_ref_inputs=False ):
  156.         if aNode.type().name() in nodeTypes:  
  157.             approvedNodes.append( aNode )
  158.     return approvedNodes
  159.        
  160. def checkAndApplyTemplate( checkFor, addThis, controlNode, curType ):
  161.     templateGroup = controlNode.parmTemplateGroup()
  162.     folderNames   = getFolderNames()
  163.    
  164.     if templateGroup.find( checkFor ):
  165.         templateGroup.replace( checkFor, addThis )
  166.     else:
  167.         templateGroup.appendToFolder( curType, addThis )
  168.     controlNode.setParmTemplateGroup( templateGroup )
  169.  
  170. def colorNodes():
  171.     ieMantraColor = hou.Color( [ 0.6, 0.6, 1.0 ] )
  172.     geoColor      = hou.Color( [ 0.0, 0.53, 0.0 ] )
  173.     brpColor      = hou.Color( [ 0.2, 0, 0.4 ] )
  174.     approvedNodes = getApprovedNodes()
  175.    
  176.     for aNode in approvedNodes:
  177.         if aNode.parm("orig_colorx"):
  178.             pass
  179.         else:
  180.             origColor = [aNode.color().rgb()[0], aNode.color().rgb()[1], aNode.color().rgb()[2] ]
  181.             templateGroup = aNode.parmTemplateGroup()
  182.             origColorParm = hou.FloatParmTemplate("orig_color", "OrigColor", 3, default_value=origColor, is_hidden=True)
  183.             templateGroup.append(origColorParm)
  184.             aNode.setParmTemplateGroup(templateGroup)
  185.            
  186.         renderNodes = [ "ieMantra", "ifd" ]
  187.         brpNodes    = [ "ieBundlePublisher" ]
  188.        
  189.         if aNode.type().name() in renderNodes:
  190.             aNode.setColor( ieMantraColor )
  191.         if aNode.type().name() in brpNodes:
  192.             aNode.setColor( brpColor )
  193.         if not aNode.type().name() in renderNodes and not aNode.type().name() in brpNodes:
  194.             aNode.setColor( geoColor )
  195.  
  196.     curNode = hou.pwd()
  197.     curNode.setColor( hou.Color( [ 0.8, 0.8, 0.8 ] ) )
  198.    
  199.  
  200. def setBypass():
  201.     controlNode   = hou.pwd()
  202.     prefixList    = getPrefixes( controlNode )
  203.     approvedNodes = getApprovedNodes()
  204.    
  205.     for aNode in approvedNodes:
  206.         curType, prefix = getTypeAndPrefix( aNode, prefixList )
  207.         name            = aNode.name()
  208.         bypass          = False
  209.        
  210.         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:
  211.             bypass      = True
  212.         aNode.bypass( bypass )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement