def run(self, stepDict):

        self.cb_node = pm.scriptNode(st=1,
                                     beforeScript=BEFORE,
                                     afterScript=AFTER,
                                     n='swap_proxyCtl_cb_node',
                                     stp='python')
        pm.scriptNode(self.cb_node, executeBefore=True)

        self.connections(stepDict)
Esempio n. 2
0
def animInfoNode(create=True):
    '''
    Returns the MT_AnimationInfoNode, making it if it doesn't exist.
    '''

    animNode = None
    animNodes = ls('MT_AnimationInfoNode*')

    if len(animNodes) == 1:
        animNode = animNodes[0]
    elif not animNodes:
        if create:
            animNode = PyNode(
                scriptNode(name="MT_AnimationInfoNode",
                           scriptType=0,
                           sourceType=1))
        else:
            return None
    else:
        print("Multiple anim nodes found")
        for obj in animNodes:
            if simpleName(obj) == 'MT_AnimationInfoNode':
                return obj
        else:
            animNode = animNodes[0]

    _addSeqAttr(animNode)
    return PyNode(animNode)  # Recast to ensure SequenceNode api
    def __init__(self, snapKeys=True):
        #Makes sure that it doesnt create any duplicates
        self.fps = meleval("currentTimeUnitToFPS")
        try:
            self.scriptNode = pm.PyNode("AnimationRemapperScriptNode")
            self.scriptNode.before.set("pass")
        except:
            pm.scriptNode(n="AnimationRemapperScriptNode",
                          stp="python",
                          st=7,
                          bs="pass")
            self.scriptNode = pm.PyNode("AnimationRemapperScriptNode")

        if snapKeys:
            self.snapKeys()

        self.createUI()
Esempio n. 4
0
def installIKFK(ikList):
    from mayaLib.rigLib.utils import ikfkSwitch
    classDefinitionString = inspect.getsource(ikfkSwitch.IKFKSwitch)
    utilDefinitionString = inspect.getsource(util.getDriverDrivenFromConstraint)

    cmdList = []
    cmdList.append('import pymel.core as pm')
    cmdList.append(utilDefinitionString)
    cmdList.append(classDefinitionString.replace('util.', ''))

    cmdList.append('ikList = pm.ls(' + ','.join("'" + str(x) + "'" for x in ikList) + ')')
    cmdList.append('ikInstanceList = [IKFKSwitch(ik) for ik in ikList]')
    cmdList.append('ikScriptJobList = [i.addScriptJob() for i in ikInstanceList]')

    cmdString = '\n'.join(cmdList)
    pm.scriptNode(st=2, bs=cmdString, n='switch_IKFK', stp='python')

    print 'INSTALLED IKFK SWITCH!'
Esempio n. 5
0
def facialScriptNode():
    def connectBS():
        try:
            if not pm.ls('RootBS') and not pm.ls('EyeDeformBS'):
                pm.select('facial',r=True)
                pm.select("*_face_grp_skinDeform",add=True)
                pm.blendShape(name='RootBS',w=[(0,1),], automatic=True)
                pm.select('eyeDeform',r=True)
                pm.select("*_eye_grp_skinDeform",add=True)
                pm.blendShape(name='EyeDeformBS',w=[(0,1),], ar=True)
        except:
            print 'Cant connect BS'
    def unConnectBS():
        try:
            pm.delete('RootBS')
            pm.delete('EyeDeformBS')
        except:
            'cant delete RootBS and EyeDeformBS'
    initNode = pm.scriptNode( st=2, bs='connectBS()', n='script', stp='python')
    pm.scriptNode(initNode, e=True, afterScript='unConnectBS()', stp='python'
    return initNode 
Esempio n. 6
0
 def make_node(self):
     ''' '''
     if self.scene_settings:
         if self.node_exists():
             if self.verbose:
                 lcUtility.Utility.lc_print("{} node already exists".format(
                     self.node_name))
         else:
             pm.scriptNode(
                 n=self.node_name,
                 scriptType=2,
                 stp='python',
                 afterScript=
                 '''try:\n    import lct.src.core.lcUtility as lcUtility\n    lcUtility.Utility.close_all_open_tools()\nexcept:\n    Pass'''
             )
             node = pm.PyNode(self.node_name)
             node.addAttr('configuration', dataType='string')
             self.update()
             if self.verbose:
                 lcUtility.Utility.lc_print("created {} node".format(
                     self.node_name))
Esempio n. 7
0
def setCachePath():
    '''{'del_path':'Cache/setCachePath()',
'icon':':/createCache.png',
'usage':'$fun()',
}
'''
    return
    #check cacheSetsq Node existing
    if not pm.objExists('cacheSetSQ'):
        cacheSetNode = pm.scriptNode(n='cacheSetSQ', st=1, bs='//')
    else:
        cacheSetNode = pm.PyNode('cacheSetSQ')

    projDir = cmds.workspace(q=1, rootDirectory=1)

    scriptStr = ""

    dynG = pm.ls(exactType="dynGlobals")

    if dynG and dynG[0].useParticleDiskCache.get():
        dynPath = dynG[0].cacheDirectory.get()
        dynPath = re.sub(projDir, "", dynPath)
        scriptStr = 'setAttr -type "string" ' + str(
            dynG[0]) + ".cacheDirectory " + "\"" + dynPath + "\";" + "\n"

    cacheNodes = pm.ls(exactType="cacheFile")
    if cacheNodes:
        for cacheNode in cacheNodes:
            attrPath = cacheNode.cachePath.get()
            if not re.search(projDir, attrPath):
                print str(cacheNode) + "file path no in data folder"
            else:
                attrPath = re.sub(projDir, "", attrPath)
                scriptStr = scriptStr + 'setAttr -type "string" ' + str(
                    cacheNode) + ".cachePath " + "\"" + attrPath + "\";" + "\n"

    pm.scriptNode(cacheSetNode, e=True, bs=unicode(scriptStr))
    print "Current project: " + str(projDir)
Esempio n. 8
0
def _ScriptNodeExists(scriptNodeName, isBefore):
    """
    Returns True if the given script node already exists within the Maya scene, False otherwise. 
    
    :param scriptNodeName: Name of the script node (string)
    :param isBefore: True if it's a 'before' event script node, False if it's an 'after' event script node. 
    """
    kwargs = {"query": True}
    if isBefore:
        kwargs["beforeScript"] = True
    else:
        kwargs["afterScript"] = True

    try:
        scriptString = pm.scriptNode(scriptNodeName, **kwargs)
        if scriptString:
            return True
        else:
            return False
    except:
        return False
Esempio n. 9
0
    def createScriptNode(self):
        '''Creates a unique script node which remap file in bundles scripts'''
        self.status.setProcess('CreateScriptNode')
        self.status.setMaximum(0)
        self.status.setValue(0)
        script = None
        try:
            script = filter(
                lambda x:
                (x.st.get() == 1 and x.stp.get() == 1 and x.before.get().strip(
                ).startswith('#ICE_BundleScript')),
                pc.ls('ICE_BundleScript', type='script'))[0]
        except IndexError:
            sceneLoadScripts = filter(
                lambda x: (x.st.get() in [1, 2] and x.stp.get(
                ) == 1 and x.before.get().strip().startswith(
                    'import pymel.core as pc') and not x.after.get()),
                pc.ls('script*', type='script'))
            if sceneLoadScripts:
                script = sceneLoadScripts[0]

        if script:
            script.before.set(mapFiles)
            script.st.set(1)
            script.rename('ICE_BundleScript')
        else:
            script = pc.scriptNode(name='ICE_BundleScript',
                                   st=1,
                                   bs=mapFiles,
                                   stp='python')
        try:
            util.createReconnectAiAOVScript()
        except Exception as e:
            self.status.warning('cannot create reconnect script: %s' % e)

        return script
Esempio n. 10
0
def createReconnectAiAOVScript():
    return pc.scriptNode(name='reconnectAiAOV',
                         bs=reconnectAiAOVScript,
                         stp='mel',
                         st=1)
Esempio n. 11
0
import pymel.core as pm


'''
def _displayModeChanged():
    """ Event fired when the display mode is changed in Maya (wireframe etc.)
    """
    currentPanel = cmds.getPanel(withFocus=True)
    modelPanels = cmds.getPanel(type='modelPanel')
    if currentPanel in modelPanels:
        # The currently focussed panel is a viewport (as expected)
        displayMode = cmds.modelEditor(currentPanel, q=True, displayAppearance=True)
        wireFrame = displayMode == 'wireframe'
        if wireFrame:
            print "User changed diaply mode to wireframe"
        else:
            print "User changed diaply mode to non-wireframe"

import maya.cmds as cmds
print "Turning off hypershade swatches because Andres is awesome!"
cmds.renderThumbnailUpdate(False)
'''
scriptNodeName = 'aw_turnOffHypershade_SCRIPTNODE'
if not pm.objExists(scriptNodeName):
	cmd = 'import maya.cmds as cmds\nprint \"Turning off hypershade swatches because Andres is awesome!\"\ncmds.renderThumbnailUpdate(False)'
	node = pm.scriptNode( st=1, bs=cmd, n=scriptNodeName)
	pm.setAttr((node+'.sourceType'), 1)
Esempio n. 12
0
def AddScriptNodesIfNecessary(moduleReference, sceneSetupMethod, frameUpdateMethod, sceneCloseMethod):
    """
    Adds auto-generated script nodes to the Maya scene if they don't already exist.
    
    Adds nodes to:
    - run a method when when Maya scene opens (e.g. to restore PySwarm state from a previous save file).
    - run a method when the frame changes the Maya scene (e.g. during playback, to read & then update the scene).
    - run a method when the Maya scene is closed (e.g. to save PySwarm state to a file).
    
    :param moduleReference: module object containing the given methods (i.e. needs to be imported to run them).
    :param sceneSetupMethod: should be a bound method (within 'moduleReference') to be run when Maya scene opens.
    :param frameUpdateMethod: bound method to run when Maya frame updates within the scene.
    :param sceneCloseMethod: bound method to run when the Maya scene closes.
    """
    swarmControllerModuleName = moduleReference.__name__
    modulePath = os.path.dirname(os.path.dirname(moduleReference.__file__))
    moduleHandle = "__%s_IMPORT_FOR_SCRIPTNODE_UPDATES__" % pi.PackageName().upper()
    headerPadding = "#" * len(pi.PackageName())
    scriptHeaderString = (
        "####################%s########################\n"
        "# Auto-generated by %s, please do not edit!! #\n"
        "####################%s########################\n\n" % (headerPadding, pi.PackageName(), headerPadding)
    )

    if not _ScriptNodeExists("pySwarmOnSceneOpen", True):
        pathString = 'import sys\nif("%s" not in sys.path): sys.path.append("%s")' % (modulePath, modulePath)
        importString = (
            'if("%s" not in globals()): globals()["%s"] = '
            '__import__("%s", globals(), locals(), ["%s"], -1)'
            % (moduleHandle, moduleHandle, swarmControllerModuleName, swarmControllerModuleName)
        )
        sceneOpenNode = pm.scriptNode(
            name="pySwarmOnSceneOpen",
            beforeScript=(
                "%s%s\n%s\n%s.%s()"
                % (scriptHeaderString, pathString, importString, moduleHandle, sceneSetupMethod.__name__)
            ),
            scriptType=2,
            sourceType="python",
        )
        pm.evalDeferred(importString)

        LogDebug('Added scene-open script node "%s" to Maya scene.' % sceneOpenNode)

    if not _ScriptNodeExists("pySwarmOnFrameUpdate", True):
        frameUpdateNode = pm.scriptNode(
            name="pySwarmOnFrameUpdate",
            beforeScript=("%s%s.%s()" % (scriptHeaderString, moduleHandle, frameUpdateMethod.__name__)),
            scriptType=7,
            sourceType="python",
        )

        LogDebug('Added frame-update script node "%s" to Maya scene.' % frameUpdateNode)

    if not _ScriptNodeExists("pySwarmOnSceneClose", False):
        sceneCloseNode = pm.scriptNode(
            name="pySwarmOnSceneClose",
            afterScript=("%s%s.%s()" % (scriptHeaderString, moduleHandle, sceneCloseMethod.__name__)),
            scriptType=2,
            sourceType="python",
        )

        LogDebug('Added scene-close script node "%s" to Maya scene.' % sceneCloseNode)
Esempio n. 13
0
try:
    pm.delete('facialRigScript')
except:
    pass
connectBSCommand = '''
import pymel.core as pm
try:
    if not pm.ls('RootBS') and not pm.ls('EyeDeformBS'):
        pm.select('facial',r=True)
        pm.select("*_face_grp_skinDeform",add=True)
        pm.blendShape(name='RootBS',w=[(0,1),], automatic=True)
        pm.select('eyeDeform',r=True)
        pm.select("*_eye_grp_skinDeform",add=True)
        pm.blendShape(name='EyeDeformBS',w=[(0,1),], ar=True)
except:
    print 'Cant connect BS'
'''
unConnectBSCommand = '''
try:
    pm.delete('RootBS')
    pm.delete('EyeDeformBS')
except:
    'cant delete RootBS and EyeDeformBS'
'''
initNode = pm.scriptNode(name='facialRigScript',
                         st=2,
                         bs=connectBSCommand,
                         n='script',
                         stp='python')
pm.scriptNode(initNode, e=True, afterScript=unConnectBSCommand, stp='python')
import pymel.core as pm

script = ['import pymel.core as pm',
          'if pm.objExists("bristle_pad_FOLLICLE"):',
          '\tif not pm.PyNode("propCleanserBrush_bristles_GRP").translateX.isConnected():',
          '\t\tpm.parentConstraint("bristle_pad_CONNECT", "propCleanserBrush_bristles_GRP")'
          ]

pm.python('\n'.join(script))
pm.scriptNode(bs="\n".join(script), stp='python', st=7, n='bristleAttach_SCRIPTNODE')

'''
#execute the scriptnode code:
import pymel.core as pm
pm.scriptNode('bristleAttach_SCRIPTNODE',eb=True)
'''