Пример #1
0
    def __init__(self,
                 mayaTypes,
                 dagMod=None,
                 dgMod=None,
                 manipError=True,
                 multi=False):
        self.multi = multi
        if not multi:
            mayaTypes = [mayaTypes]
        self.mayaTypes = mayaTypes

        if dagMod is None:
            dagMod = api.MDagModifier()
        if dgMod is None:
            dgMod = api.MDGModifier()
        self.dagMod = dagMod
        self.dgMod = dgMod

        self.dagGhosts = False
        self.dgGhosts = False
        #self.theMod = None

        self.manipError = manipError
        self.byMayaType = {}
        self.ghosts = set()
Пример #2
0
    def _buildMayaToApiInfo(self, mayaTypes):
        # Fixes for types that don't have a MFn by faking a node creation and testing it
        # Make it faster by pre-creating the nodes used to test
        dagMod = api.MDagModifier()
        dgMod = api.MDGModifier()

        # Put in a debug, because this can be crashy
        _logger.debug("Starting to create ghost nodes...")

        unknownTypes = set()

        for mayaType in mayaTypes:
            apiType = None
            if self.reservedMayaTypes.has_key(mayaType):
                apiType = self.reservedMayaTypes[mayaType]
            else:
                obj = _makeDgModGhostObject(mayaType, dagMod, dgMod)
                if obj:
                    apiType = obj.apiTypeStr()
                else:
                    unknownTypes.add(mayaType)
            if apiType is not None:
                self.mayaTypesToApiTypes[mayaType] = apiType

        # Put in a debug, because this can be crashy
        _logger.debug("...finished creating ghost nodes")

        if len(unknownTypes) > 0:
            _logger.warn(
                "Unable to get maya-to-api type info for the following nodes: %s"
                % ", ".join(unknownTypes))

        for mayaType, apiType in self.mayaTypesToApiTypes.iteritems():
            self.addMayaType(mayaType, apiType)
Пример #3
0
    def __exit__(self, exc_type, exc_value, traceback):
        try:
            if self.dagGhosts:
                self.dagMod.undoIt()
            if self.dgGhosts:
                self.dgMod.undoIt()
        except RuntimeError:
            stillExist = []
            for mayaType in self.ghosts:
                obj = self.byMayaType[mayaType]
                if obj is not None and api.isValidMObjectHandle(
                        api.MObjectHandle(obj)):
                    stillExist.append(obj)
            if stillExist:
                mfnDag = api.MFnDagNode()
                mfnDep = api.MFnDependencyNode()
                names = []
                for obj in stillExist:
                    if obj.hasFn(api.MFn.kDagNode):
                        # we need to delete the parent, since it will have
                        # created a parent transform too
                        mfnDag.setObject(obj)
                        mfnDag.setObject(mfnDag.parent(0))
                        names.append(mfnDag.partialPathName())
                    else:
                        mfnDep.setObject(obj)
                        names.append(mfnDep.name())
                print names
                #import maya.cmds as cmds
                # cmds.delete(names)

                mfnDag = api.MFnDagNode()
                dagMod = api.MDagModifier()
                dgMod = api.MDGModifier()

                delDag = False
                delDg = False

                for obj in stillExist:
                    if obj.hasFn(api.MFn.kDagNode):
                        # we need to delete the parent, since it will have
                        # created a parent transform too
                        mfnDag.setObject(obj)
                        dagMod.deleteNode(mfnDag.parent(0))
                    else:
                        dgMod.deleteNode(obj)
                if delDag:
                    dagMod.doIt()
                if delDg:
                    dgMod.doIt()