代码之家  ›  专栏  ›  技术社区  ›  Zak44

如何从Maya中启动Nuke?

  •  2
  • Zak44  · 技术社区  · 7 年前

    我似乎在做一些不恰当的事情,我对此感到目瞪口呆。我正试图从Maya内部启动Foundry NUKE,当我尝试时,发现与未找到的模块相关的错误。但如果我在常规命令行上加载Nuke,它会加载得非常好。似乎与Maya的Python解释器相关的东西无法找到此模块?我好像找不到。。。

    更新#1:我甚至试过做一些系统。路径Nuke插件、DLL、lib和include dirs的附录在所有这些之前都没有用。。。

    更新#2:我已经重新安装了Python,并验证它是64位的。还检查了我的64位Maya和Nuke版本。我也试过以下方法。。。在Maya外部打开普通Python命令提示符,通过操作系统加载Nuke。系统调用和它的工作。这只是在做操作系统的时候。在Maya中对Nuke的系统调用表明,它在导入此\u套接字模块时出现问题而失败。当检查Maya正在加载的套接字模块时,我得到:

    import _socket
    print _socket.__file__
    C:\Program Files\Autodesk\Maya2016\Python\DLLs\_socket.pyd
    

    这让我相信Maya的Python正在加载这个_套接字的diff版本,然后是什么Nuke,那里出了什么问题。

    C:\Program Files\Nuke9.0v8\Nuke9.0.exe
    Traceback (most recent call last):
        File "C:/Program Files/Nuke9.0v8/plugins/init.py", line 22, in <module>
          import nukescripts.ViewerProcess
        File "C:/Program Files/Nuke9.0v8/plugins\nukescripts\__init__.py", line 22, in <module>
          from nukeprofiler import *
        File "C:/Program Files/Nuke9.0v8/plugins\nukescripts\nukeprofiler.py", line 2, in <module>
            import socket
        File "C:\Python27\lib\socket.py", line 47, in <module>
            import _socket
    ImportError: DLL load failed: The specified module could not be found.
    C:/Program Files/Nuke9.0v8/plugins/init.py : error interpreting this plugin
    

    from PySide import QtCore, QtGui
    import maya.cmds as cmds
    import os, sys
    #import subprocess
    
    
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(314, 216)
            sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
            Dialog.setSizePolicy(sizePolicy)
            self.blastBtn = QtGui.QPushButton(Dialog)
            self.blastBtn.setGeometry(QtCore.QRect(110, 130, 75, 23))
            self.blastBtn.setObjectName("blastBtn")
    
            self.blastBtn.clicked.connect(self.RunPlayblast)
    
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Playblast & Nuke Me", None, QtGui.QApplication.UnicodeUTF8))
            self.blastBtn.setText(QtGui.QApplication.translate("Dialog", "Blast", None, QtGui.QApplication.UnicodeUTF8))
    
    
        def RunPlayblast(self):
            cmds.playblast(fmt="qt", f="myMovie.mov", fo=True)
            self.RunNuke()
    
        def RunNuke(self):
            nukeExe = r'C:\Program Files\Nuke9.0v8\Nuke9.0.exe'
            myTemplate = r'B:\home\nukePBTemplate.nk'
    
            os.system('"'+nukeExe+'" -x ' +myTemplate)
    
            #command = nukeExe+" -x "+myTemplate
            #subprocess.Popen(command)
    
    if __name__ == '__main__':
        app = QtGui.QApplication.instance() 
        Dialog = QtGui.QDialog()
        blastMe = Ui_Dialog()
        blastMe.setupUi(Dialog)
        Dialog.show()
        app.exec_()
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   Achayan    7 年前

    import subprocess
    nukeProcess = subprocess.Popen(["C:/Program Files/Nuke9.0v8/Nuke9.0.exe", "-x", "B:/home/nukePBTemplate.nk"])
    

    import subprocess, os
    newEnv = os.environ.copy()
    newEnv["PYTHONPATH"] = newEnv["PATH"] + "/local/share/python/2.7/libs"
    nukeProcess = subprocess.Popen(["C:/Program Files/Nuke9.0v8/Nke9.0.exe", "-x", "B:/home/nukePBTemplate.nk"], env=newEnv)
    
        2
  •  0
  •   Andy Jazz    7 年前

    你应该跑 system Python脚本中的MEL命令。为此,您需要使用 mel.eval eval 命令是为用户提供一种执行MEL命令或程序的方式,该命令或程序只能在运行时确定。

    import maya.mel as mel
    
    def RunNuke(self):  
        mel.eval('system "/Applications/Nuke10.5v5/Nuke10.5v5.app/Contents/MacOS/Nuke10.5v5 --nc --nukex"')
    

    我在macOS(而不是Windows)上运行非商业版本的NUKEX,它可以工作。

    代码的完整版本应如下所示:

    from PySide import QtCore, QtGui
    import maya.cmds as cmds
    import os, sys
    import maya.mel as mel
    
    class Ui_Dialog(object):
    
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(314, 216)
            sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Preferred)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth( Dialog.sizePolicy().hasHeightForWidth() )
            Dialog.setSizePolicy(sizePolicy)
            self.blastBtn = QtGui.QPushButton(Dialog)
            self.blastBtn.setGeometry(QtCore.QRect(110, 130, 75, 23))
            self.blastBtn.setObjectName("blastBtn")
            self.blastBtn.clicked.connect(self.RunPlayblast)
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Playblast & Nuke Me", None, QtGui.QApplication.UnicodeUTF8))
            self.blastBtn.setText(QtGui.QApplication.translate("Dialog", "Blast", None, QtGui.QApplication.UnicodeUTF8))
    
        def RunPlayblast(self):
            cmds.playblast(fmt="qt", f="myMovie.mov", fo=True)
            self.RunNuke()
    
        def RunNuke(self):
            mel.eval('system "/Applications/Nuke10.5v5/Nuke10.5v5.app/Contents/MacOS/Nuke10.5v5 --nc --nukex "')
    
    if __name__ == '__main__':
        app = QtGui.QApplication.instance() 
        Dialog = QtGui.QDialog()
        blastMe = Ui_Dialog()
        blastMe.setupUi(Dialog)
        Dialog.show()
        app.exec_()
    

    enter image description here

    safe mode :

    import maya.mel as mel
    
    def RunNuke(self):  
        mel.eval('system "C:\Program Files\Nuke9.0v8\Nuke9.0.exe" --safe --nc --nukex')
    

    阅读: Launching NUKE and HIERO in safe mode

    如果它仍然不起作用,我认为这是Python库中的一个bug,或者是init内容中的一个问题。py。