【问题标题】:import a custom python script to maya将自定义 python 脚本导入到 Maya
【发布时间】:2018-08-17 01:17:08
【问题描述】:

我目前正在尝试将我的自定义脚本导入 Maya。我找到了这个example。我的目标是能够在外部编辑脚本,每次点击时重新加载。

我在 python 控制台中尝试了以下脚本,它似乎可以工作。不幸的是,当我单击 Maya 中的自定义按钮时,它给了我一些错误。

这是我在maya中自定义按钮的脚本

import sys
import os

def psource(module):

    file = os.path.basename( module )
    dir = os.path.dirname( module )

    toks = file.split( '.' )
    modname = toks[0]

    # Check if dirrectory is really a directory
    if( os.path.exists( dir ) ):

    # Check if the file directory already exists in the sys.path array
        paths = sys.path
        pathfound = 0
        for path in paths:
            if(dir == path):
                pathfound = 1

    # If the dirrectory is not part of sys.path add it
        if not pathfound:
            sys.path.append( dir )

    # exec works like MEL's eval but you need to add in globals()
    # at the end to make sure the file is imported into the global
    # namespace else it will only be in the scope of this function
    exec ('import ' + modname) in globals()

    # reload the file to make sure its up to date
    exec( 'reload( ' + modname + ' )' ) in globals()

    # This returns the namespace of the file imported
    return modname

# When you import a file you must give it the full path
psource( '/The/correct/path/to/my/script/import_test_model.py' )


import_test_model.main()

虽然这是我的自定义脚本

def main():
    print "funziona"
    return

if __name__ == "__main__":
    main()

这是我收到的错误消息

...
# When you import a file you must give it the full path
psource( '/Users/rostyslavkostyuk/Documents/developing/py_maya/import_test_model.py' )


import_test_model.main()

# Error: SyntaxError: file <string> line 1: invalid syntax # 

# Error: invalid syntax # 

# Error: invalid syntax # 

# Error: invalid syntax # 

【问题讨论】:

  • 这里没问题。我想你已经创建了一个按钮。能否提供按钮创建代码?
  • 我刚刚使用maya脚本编辑器文件选项卡的“保存到架子...”按钮来创建按钮。

标签: python-2.7 scripting maya


【解决方案1】:

我不知道是什么问题,但为了解决它,我只是删除了旧按钮,并创建了新按钮,然后它就开始工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 2022-06-21
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    相关资源
    最近更新 更多