使用基于setattr(“example”.outmesh)的当前选择更改“example”

2024-09-23 15:58:12 发布

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

我告诉自己,如果我能在网上查到这些问题,就永远不要问common sensenovice问题,而把问别人作为最后的手段。这可能是一个基本问题,但请务必启发我!你知道吗

我的代码:

obj = pm.ls (selection=True,sn=True,o=True)       # get selection = obj 
shapes = pm.listRelatives(obj)                    # get obj shapeNode name
cpmNode = pm.createNode('closestPointOnMesh')     # create 
closestPointOnMesh Node
pm.setAttr(shapes+".outMesh",cpmNode + ".inMesh") # setattr selection 
shapeNode to cpmNode inMesh

错误:

# Can only concatenate list (not "str") to list

我不明白pm.setAttr(shapes+".outMesh",cpmNode + ".inMesh")是怎么变成一个列表的。现在不是有字符串的命令吗?你知道吗

shapes放入pm.setAttr(shapes+".outMesh",cpmNode + ".inMesh")会给我带来错误,其中.outmesh是一个字符串?你知道吗

那么pm.setAttr(shapes+".outMesh",cpmNode + ".inMesh")是一个列表吗?你知道吗

如果给出下面的示例,我应该如何使当前选择shapeNode更改pCubeShape1

pm.setAttr("pCubeShape1.outMesh",cpmNode + ".inMesh")

Tags: totrueobjget错误listselectionshapes
1条回答
网友
1楼 · 发布于 2024-09-23 15:58:12

正如您所怀疑的,cmds.listRelatives返回的是一个列表,而不是一个字符串。这是因为变换可以包含多个形状。你知道吗

此外,不能使用setAttr将形状的outMesh连接到实用程序的inMesh。相反,您需要使用connectAttr。你知道吗

试试这个:

import pymel.core as pm

obj = pm.ls (selection=True,sn=True,o=True)
shapes = pm.listRelatives(obj, shapes=True, ni=True, type="mesh") # Use flags to narrow down the proper shape.
cpmNode = pm.createNode('closestPointOnMesh')
pm.connectAttr(shapes[0]+".outMesh",cpmNode + ".inMesh") # Use the first item in the shapes list.

相关问题 更多 >