代码在脚本编辑器中工作,但从命令lin运行时不起作用

2024-05-28 20:45:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将表达式结果导入maya文本对象,以用作平视显示。我的脚本在脚本编辑器中工作,但从命令行或从我的显示表达式调用时不起作用。如何更改此项以使其从命令行工作?在

import maya.cmds as cmds

# convert a string to hex values, separated by a space

typeNode = cmds.ls( selection=True )
type3d = cmds.listConnections(t='type')
typeValue = cmds.getAttr( 'tower_CON.Spin' )

valueList=list(str('{:3.2f}'.format(typeValue)))

hexVersion=""

for x in valueList:
    hexValue=x.encode("hex")
    hexVersion=hexVersion + hexValue + " " 

cmds.setAttr(str(type3d[0]) + ".textInput", hexVersion.rstrip(), type="string")

Tags: 命令行文本脚本string表达式typehexcmds
2条回答

很可能您缺少依赖项。运行:

pip install maya

从您的注释中的错误来看,您似乎正在尝试将模块作为函数运行。在

您可能需要将其保存在文件中:

import maya.cmds as cmds

def text_to_hud():
    # convert a string to hex values, separated by a space

    typeNode = cmds.ls( selection=True )
    type3d = cmds.listConnections(t='type')
    typeValue = cmds.getAttr( 'tower_CON.Spin' )

    valueList=list(str('{:3.2f}'.format(typeValue)))

    hexVersion=""

    for x in valueList:
        hexValue=x.encode("hex")
        hexVersion=hexVersion + hexValue + " " 

    cmds.setAttr(str(type3d[0]) + ".textInput", hexVersion.rstrip(), type="string")

然后在命令行中

^{pr2}$

你也可以按原样保存文件

import textToolHUD

它将运行一次,但依赖于在导入时运行的代码是不好的做法。在

相关问题 更多 >

    热门问题