如何从Maya中启动Nuke?

时间:2017-08-22 19:29:01

标签: python maya mel nuke

我似乎在这里做了一些不正当的事情,我对这是什么感到茫然。我试图从Maya中启动The Foundry NUKE,当我尝试时,我得到与未找到的模块有关的错误。但是,如果我在常规命令行上加载Nuke,它会加载完美的。似乎与Maya的Python解释器相关的东西无法找到这个模块?我似乎无法找到它......

更新#1:我甚至尝试过做一些Nuke插件,DLL,lib的sys.path.appends,并在所有这些之前加入dirs无济于事......

更新#2:我重新安装了我的Python并验证它是64位。还检查了我的Maya和Nuke版本是64位。我也试过以下内容......在Maya之外打开一个普通的Python命令提示符,通过os.system调用加载Nuke,它可以工作。只有在Maya中对Nuke执行os.system调用时才会导致导入此_socket模块时出现问题。当检查Maya正在加载的_socket模块时,我得到:

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

让我相信Maya的Python正在加载这个_socket的差异版本,那么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 个答案:

答案 0 :(得分:2)

我认为你可以使用内置的子进程来像这样调用nuke

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

我认为你从不使用mel.eval(“system / whatever”),因为你从python中尝试,已经有python有许多内置的方法来处理系统命令,比如子进程,命令等。

更新

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)

答案 1 :(得分:0)

您应该在Python脚本中运行system MEL命令。为此,您需要使用带有字符串参数的mel.eval方法(string in string)。 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

如果您仍然遇到从Maya中启动NUKE的问题,请尝试在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库中的一个错误,或者它是init.py内容中的一个问题。