def __enter__(self):
        import maya.cmds as cmds

        for mayaType in self.mayaTypes:
            # check if an obj of the given type already exists in the scene, and
            # if so, use it
            madeGhost = False
            allObj = None
            if cmds.objExists(mayaType):
                allObj = cmds.ls(exactType=mayaType)
            if allObj:
                obj = api.toMObject(allObj[0])
            else:
                if mayaType in ApiCache.CRASH_TYPES:
                    # the two items in CRASH_TYPES are both manips...
                    if self.manipError:
                        raise ManipNodeTypeError
                    obj = None
                else:
                    obj = _makeDgModGhostObject(mayaType, self.dagMod, self.dgMod)
                if obj is not None:
                    self.ghosts.add(mayaType)
                    madeGhost = True

            if obj is not None:
                if (self.manipError
                    and (obj.hasFn( api.MFn.kManipulator )
                         or obj.hasFn( api.MFn.kManipContainer )
                         or obj.hasFn( api.MFn.kPluginManipContainer )
                         or obj.hasFn( api.MFn.kPluginManipulatorNode )
                         or obj.hasFn( api.MFn.kManipulator2D )
                         or obj.hasFn( api.MFn.kManipulator3D )
                         or obj.hasFn( api.MFn.kManip2DContainer)
                        )
                   ):
                    raise ManipNodeTypeError

                if madeGhost and not (self.dagGhosts and self.dgGhosts):
                    if obj.hasFn( api.MFn.kDagNode ):
                        self.dagGhosts = True
                    else:
                        self.dgGhosts = True
            self.byMayaType[mayaType] = obj

        # Note that we always create a "real" instance of the object by
        # calling doIt()... we used to not call doIt(), in which case
        # the mobject would actually still be queryable, but not in the
        # scene - thus the "ghost" obj - but this would create problems in
        # some cases - ie, if this was triggered during reference loading,
        # the objects would actually be entered into the scene... and
        # because we didn't call undoIt, they wouldn't get cleaned up
        if self.dagGhosts:
            self.dagMod.doIt()
        if self.dgGhosts:
            self.dgMod.doIt()
        if self.multi:
            return self.byMayaType
        else:
            return obj
Beispiel #2
0
def _buildMpxNamesToApiEnumNames(dummyClasses=None, dummyNodes=None):
    import pymel.api as api

    mpxNamesToEnumNames = {}
    with _DummyPluginNodesMaker(dummyClasses=dummyClasses, alreadyCreated=dummyNodes) as nodeMaker:
        for mpxCls, mayaNode in nodeMaker.nodes.iteritems():
            mobj = api.toMObject(mayaNode)
            mpxNamesToEnumNames[mpxCls.__name__] = mobj.apiTypeStr()
    return mpxNamesToEnumNames
Beispiel #3
0
def _buildMpxNamesToApiEnumNames(dummyClasses=None, dummyNodes=None):
    import pymel.api as api
    mpxToEnumNames = {}
    with _DummyPluginNodesMaker(dummyClasses=dummyClasses,
                                alreadyCreated=dummyNodes) as nodeMaker:
        for mpxCls, mayaNode in nodeMaker.nodes.iteritems():
            mobj = api.toMObject(mayaNode)
            mpxToEnumNames[mpxCls.__name__] = mobj.apiTypeStr()
    return mpxToEnumNames