示例#1
0
    def onSelectionChange( self ):
        '''
        Function called by the scripted event in componentsGUI().
        Updates the componentGUI whenever the user selects a different object.
        '''
        selList = cmds.ls( selection=1, long=True )
        if not self.selectedLockActive:
            clearLayout( self.componentsLayout )
            if len( selList ) == 1:
                shortName = selList[0].split( '|' )
                selName = shortName[ len(shortName)-1 ]
                self.selectedLabel.setText( selName )
                self.SELECTED_OBJECT_LONGNAME = selList[0]
                componentsClassList = Components.getComponents( self.SELECTED_OBJECT_LONGNAME )
                
                # Add the component node GUI widgets to the component section.
                if componentsClassList is not None:
                    for nodeName in componentsClassList:
                        component = componentsClassList[ nodeName ]
                        nodeName = nodeName
                        componentClass = Components.str_to_class( component )
                        componentGui = componentClass( component ).componentGui( nodeName, parent=self )
                        self.componentsLayout.addWidget( componentGui )
                        

            elif len( selList ) > 1:
                if not self.selectedLockActive:
                    self.SELECTED_OBJECT_LONGNAME = None
                    self.selectedLabel.setText( 'select only one module bit' )
            else:
                if not self.selectedLockActive:
                    self.SELECTED_OBJECT_LONGNAME = None
                    self.selectedLabel.setText( 'nothing selected' )
示例#2
0
def writeModuleXML( inRootObjectName, inModuleType, inModuleName ):
    '''
    Function for writing module xml.
    
    @param inRootObjectName: String. Name of module root object.
    @param inModuleType: String. Type of module. This determines which sub-folder the XML is saved.
    @param inModuleName: String. Name of the module XML file.
    '''
    # Get list of the module hierarchy. Root is always first
    hierarchyList = NodeUtility.getFrameRootAllChildren( inRootObjectName )
    hierarchyList.insert( 0, inRootObjectName )
    
    # START: Writing XML
    xmlLines = []
    xmlLines.append( '<data>' )
    
    for item in hierarchyList:        
        # BIT INFO
        itemName = getObjectShortName( item )        
        itemParent = NodeUtility.cleanParentFullName( item )
        itemMatrix = TransformUtility.getMatrix( item, 'matrix' )
        itemPosition = TransformUtility.getMatrixTranslation( itemMatrix, OpenMaya.MSpace.kTransform )        
        itemRotation = TransformUtility.getMatrixRotation( itemMatrix, 'eulerVector' )
        
        # START: Bit
        xmlLines.append( '\t<bit name=\"{0}\" parent=\"{1}\">'.format( itemName, itemParent ) )        
        xmlLines.append( '\t\t<plug name=\"translateX\">{0}</plug>'.format( itemPosition.x ) )
        xmlLines.append( '\t\t<plug name=\"translateY\">{0}</plug>'.format( itemPosition.y ) )
        xmlLines.append( '\t\t<plug name=\"translateZ\">{0}</plug>'.format( itemPosition.z ) )    
        xmlLines.append( '\t\t<plug name=\"rotateX\">{0}</plug>'.format( math.degrees(itemRotation.x) ) )
        xmlLines.append( '\t\t<plug name=\"rotateY\">{0}</plug>'.format( math.degrees(itemRotation.y) ) )
        xmlLines.append( '\t\t<plug name=\"rotateZ\">{0}</plug>'.format( math.degrees(itemRotation.z) ) )
        
        # SHAPE
        itemShape = NodeUtility.getDagPath( itemName ).child( 0 )
        depFn = OpenMaya.MFnDependencyNode( itemShape )
        shapeType = depFn.typeName()
        if shapeType.find( 'gl' ) != -1:
            itemShapeName = cmds.listRelatives( itemName, shapes=True, fullPath=True )[0]
            # Start shape
            xmlLines.append( '\t\t<shape name=\"{0}\">'.format( shapeType ) )
            
            # Get the shape's local position and scale.
            for attr in cmds.listAttr( itemShapeName, channelBox=True ):
                types = NodeUtility.getAttrTypes( itemShapeName, attr )
                aPlug = NodeUtility.getPlug( itemShapeName, attr )
                xmlLines.append( '\t\t\t<plug name=\"{0}\" attrType=\"{1}\" attrDataType=\"{2}\">{3}</plug>'.format( attr, types[0], types[1], NodeUtility.getPlugValue(aPlug) ) )
            
            # Get the shape's custom attributes.
            for attr in cmds.listAttr( itemShapeName, multi=True, keyable=True ):
                
                types = NodeUtility.getAttrTypes( itemShapeName, attr )
                
                if attr.find( '[' ) is not -1:
                    # Special case handle array attributes. The [] needs to be removed so we can get
                    # the base name for the attribute. From there we can then loop through it's children.
                    # First we get the connection since these plugs won't return a value, but rather a
                    # connected node.
                    connection = NodeUtility.getNodeAttrSource( itemShapeName, attr )
                    bitChildren = cmds.listRelatives( itemName, type='transform', children=True, fullPath=True )
                    for child in bitChildren:
                        childSplit = child.split('|')
                        if childSplit[-1] == connection[0]:
                            plugValue = child
                    
                    # Now we get the compound attribute's name by removing the index brackets.
                    attrSplit = attr.split('[')
                    attr = attrSplit[0]
                else:
                    aPlug = NodeUtility.getPlug( itemShapeName, attr )
                    plugValue = NodeUtility.getPlugValue( aPlug )
                    
                
                if types[0] is not False:
                    xmlLines.append( '\t\t\t<plug name=\"{0}\" attrType=\"{1}\" attrDataType=\"{2}\">{3}</plug>'.format( attr, types[0], types[1], plugValue ) )
            # End shape
            xmlLines.append( '\t\t</shape>' )
            
        # BIT COMPONENTS
        print 'item: {0}'.format( item )
        bitComponents = components.getComponents( item )
        for comp in bitComponents:            
            # Component info
            compName = ''.join(i for i in comp if not i.isdigit())

            # Start component.
            xmlLines.append( '\t\t<component name=\"{0}\">'.format( compName ) )
            
            compSettings = NodeUtility.getModuleComponentSettings( comp )
            for attr in compSettings:
                types = NodeUtility.getAttrTypes( comp, attr )
                
                # Special case message plugs.
                if types[1] == 'message':
                    messageValues = NodeUtility.getAttrMessageValue( comp, attr )
                    if isinstance( messageValues, unicode ):
                        plugValue = messageValues
                    elif isinstance( messageValues, list ):
                        plugValue = None
                else:
                    aPlug = NodeUtility.getPlug( comp, attr )
                    plugValue = NodeUtility.getPlugValue( aPlug )
                xmlLines.append( '\t\t\t<plug name=\"{0}\" attrType=\"{1}\" attrDataType=\"{2}\">{3}</plug>'.format( attr, types[0], types[1], plugValue ) )
    
            xmlLines.append( '\t\t</component>' )
        # END: Bit
        xmlLines.append( '\t</bit>' )
        
    # END: Writing XML
    xmlLines.append( '</data>' )
    
    # Create the file
    startingDirectory = getPresetPath( FRAME_PRESETS_PATH )
    filePath = '{0}{1}'.format( startingDirectory, inModuleType )
    fileName = '{0}.xml'.format( inModuleName )

    newfile = file( os.path.join( filePath, fileName ), 'w')      
    for i in xmlLines:
        newfile.write( i+'\n' )
    newfile.close()