def GetControlName(cls, control): ''' returns the name of the control as defined in the CONTROL_NAMES attribute for the part class ''' cons = listConnections(control.message, s=False, p=True, type='objectSet') for c in cons: typeClassStr = getAttr('%s._rigPrimitive.typeName' % c.node()) typeClass = RigPart.GetNamedSubclass(typeClassStr) if typeClass.CONTROL_NAMES is None: return str(control) idx = c[c.rfind('[') + 1:-1] try: name = typeClass.CONTROL_NAMES[idx] except ValueError: printErrorStr('type: %s control: %s' % (typeClass, control)) raise RigPartError("Doesn't have a name!") return name raise RigPartError("The control isn't associated with a rig primitive")
def setupDagProcMenu(): ''' sets up the modifications to the dagProcMenu script ''' dagMenuScript = r'C:\Program Files\Autodesk\Maya2011\scripts\others\dagMenuProc.mel' globalProcDefRex = re.compile( "^global +proc +dagMenuProc *\( *string *(\$[a-zA-Z0-9_]+), *string *(\$[a-zA-Z0-9_]+) *\)" ) dagMenuScriptLines = Path(dagMenuScript).read() dagMenuScriptLineIter = iter(dagMenuScriptLines) newLines = [] hasDagMenuProcBeenSetup = False for line in dagMenuScriptLineIter: newLines.append(line) globalProcDefSearch = globalProcDefRex.search(line) if globalProcDefSearch: parentVarStr, objectVarStr = globalProcDefSearch.groups() selHierarchyRex = re.compile( 'uiRes *\( *"m_dagMenuProc.kSelectHierarchy" *\)') #menuItem -label (uiRes("m_dagMenuProc.kDagMenuSelectHierarchy")) -c ("select -hierarchy " + $object); #if we're past the global proc definition for dagMenuProc start looking for the menu item to for line in dagMenuScriptLineIter: newLines.append(line) if 'menuItem' in line and selHierarchyRex.search(line): newLines.append('\t\t\tmenuItem -d 1;') newLines.append('\t\t\tpython( "import triggeredUI" );') newLines.append( """\t\t\tint $killState = python( "triggeredUI.buildMenuItems( '"+ %s +"', '"+ %s +"' )" );""" % (parentVarStr, objectVarStr)) newLines.append('\t\t\tif( $killState ) return;') hasDagMenuProcBeenSetup = True break if not hasDagMenuProcBeenSetup: printErrorStr("Couldn't auto setup dagMenuProc! AWOOGA!") return newScript = '\n'.join(newLines) evalMel(newScript)
def GetControlName( cls, control ): ''' returns the name of the control as defined in the CONTROL_NAMES attribute for the part class ''' cons = listConnections( control.message, s=False, p=True, type='objectSet' ) for c in cons: typeClassStr = getAttr( '%s._rigPrimitive.typeName' % c.node() ) typeClass = RigPart.GetNamedSubclass( typeClassStr ) if typeClass.CONTROL_NAMES is None: return str( control ) idx = c[ c.rfind( '[' )+1:-1 ] try: name = typeClass.CONTROL_NAMES[ idx ] except ValueError: printErrorStr( 'type: %s control: %s' % (typeClass, control) ) raise RigPartError( "Doesn't have a name!" ) return name raise RigPartError( "The control isn't associated with a rig primitive" )
def setupDagProcMenu(): ''' sets up the modifications to the dagProcMenu script ''' dagMenuScript = r'C:\Program Files\Autodesk\Maya2011\scripts\others\dagMenuProc.mel' globalProcDefRex = re.compile( "^global +proc +dagMenuProc *\( *string *(\$[a-zA-Z0-9_]+), *string *(\$[a-zA-Z0-9_]+) *\)" ) dagMenuScriptLines = Path( dagMenuScript ).read() dagMenuScriptLineIter = iter( dagMenuScriptLines ) newLines = [] hasDagMenuProcBeenSetup = False for line in dagMenuScriptLineIter: newLines.append( line ) globalProcDefSearch = globalProcDefRex.search( line ) if globalProcDefSearch: parentVarStr, objectVarStr = globalProcDefSearch.groups() selHierarchyRex = re.compile( 'uiRes *\( *"m_dagMenuProc.kSelectHierarchy" *\)' ) #menuItem -label (uiRes("m_dagMenuProc.kDagMenuSelectHierarchy")) -c ("select -hierarchy " + $object); #if we're past the global proc definition for dagMenuProc start looking for the menu item to for line in dagMenuScriptLineIter: newLines.append( line ) if 'menuItem' in line and selHierarchyRex.search( line ): newLines.append( '\t\t\tmenuItem -d 1;' ) newLines.append( '\t\t\tpython( "import triggeredUI" );' ) newLines.append( """\t\t\tint $killState = python( "triggeredUI.buildMenuItems( '"+ %s +"', '"+ %s +"' )" );""" % (parentVarStr, objectVarStr) ) newLines.append( '\t\t\tif( $killState ) return;' ) hasDagMenuProcBeenSetup = True break if not hasDagMenuProcBeenSetup: printErrorStr( "Couldn't auto setup dagMenuProc! AWOOGA!" ) return newScript = '\n'.join( newLines ) evalMel( newScript )
def write( self, objects, **kwargs ): type = self.getType() clipDict = api.writeExportDict( TOOL_NAME, VER ) clipDict[ kEXPORT_DICT_CLIP_TYPE ] = type clipDict[ kEXPORT_DICT_OBJECTS ] = objects clipDict[ kEXPORT_DICT_WORLDSPACE ] = False theClip = self.TYPE_CLASSES[ type ]() success = theClip.generate( objects, **kwargs ) if not success: printErrorStr( "Failed to generate clip!" ) return clipDict[ kEXPORT_DICT_THE_CLIP ] = theClip #write the preset file to disk self.pickle( clipDict ) #generate the icon for the clip and add it to perforce if appropriate icon = generateIcon( self ) #icon.asP4().add() printInfoStr( "Generated clip!" )
def write(self, objects, **kwargs): type = self.getType() clipDict = api.writeExportDict(TOOL_NAME, VER) clipDict[kEXPORT_DICT_CLIP_TYPE] = type clipDict[kEXPORT_DICT_OBJECTS] = objects clipDict[kEXPORT_DICT_WORLDSPACE] = False theClip = self.TYPE_CLASSES[type]() success = theClip.generate(objects, **kwargs) if not success: printErrorStr("Failed to generate clip!") return clipDict[kEXPORT_DICT_THE_CLIP] = theClip #write the preset file to disk self.pickle(clipDict) #generate the icon for the clip and add it to perforce if appropriate icon = generateIcon(self) #icon.asP4().add() printInfoStr("Generated clip!")
if not dirToSearch.isDir(): continue foundControlDir = False for f in dirToSearch.files( recursive=True ): if f.hasExtension( 'shape' ): if f.name().startswith( 'control' ): CONTROL_DIRECTORY = f.up() foundControlDir = True break if foundControlDir: break if CONTROL_DIRECTORY is None: printErrorStr( "Cannot determine the directory that contains the *.control files - please open '%s' and set the CONTROL_DIRECTORY variable appropriately" % Path( __file__ ) ) AX_X, AX_Y, AX_Z, AX_X_NEG, AX_Y_NEG, AX_Z_NEG = map( Axis, range( 6 ) ) DEFAULT_AXIS = AX_X AXIS_ROTATIONS = { AX_X: (0, 0, -90), AX_Y: (0, 0, 0), AX_Z: (90, 0, 0), AX_X_NEG: (0, 0, 90), AX_Y_NEG: (180, 0, 0), AX_Z_NEG: (-90, 0, 0) } class ShapeDesc(object): ''' store shape preferences about a control
continue foundControlDir = False for f in dirToSearch.files(recursive=True): if f.hasExtension('shape'): if f.name().startswith('control'): CONTROL_DIRECTORY = f.up() foundControlDir = True break if foundControlDir: break if CONTROL_DIRECTORY is None: printErrorStr( "Cannot determine the directory that contains the *.control files - please open '%s' and set the CONTROL_DIRECTORY variable appropriately" % Path(__file__)) AX_X, AX_Y, AX_Z, AX_X_NEG, AX_Y_NEG, AX_Z_NEG = map(Axis, range(6)) DEFAULT_AXIS = AX_X AXIS_ROTATIONS = { AX_X: (0, 0, -90), AX_Y: (0, 0, 0), AX_Z: (90, 0, 0), AX_X_NEG: (0, 0, 90), AX_Y_NEG: (180, 0, 0), AX_Z_NEG: (-90, 0, 0) }