我正在编写一个脚本,以在给定特定矢量的情况下更改由拉伸命令创建的顶点的位置。但我找不到获取新生成的顶点/面/边的方法。
我尝试在public class TestController: Controller
{
[HttpGet("{param1}/{param2}")]
public string MethodWithGet(string param1, string param2)
{
return interalgetmethodcall(param1, param2);
}
[HttpPost("{param1}/{param2}")]
public string MethodWithPost(string param1, string param2,[FromBody] dynamic datafrombody)
{
return interalpostmethodcall(param1, param2, datafrombody.toString());
}
}
或cmds.getAttr('polyExtrudeFace1')
的查询模式下查找,但是找不到正确的属性/标志来获取所需的内容。
答案 0 :(得分:1)
我不确定是否有很好的方法来获取新的拉伸组件ID,但是如果您有工具来获取before状态,则可以轻松找到它。 另一种方法是停用每个构造节点,一个接一个地启用polyExtrudeFace并填充一个dic,然后重新启用所有内容。 这是一个在拉伸对象上选择最新顶点的示例:
'''
This script only work on the last polyExtrudeFace and on vertex
'''
# get the object
sel = cmds.ls(sl=True, o=True)
# get the extrude nodes, useful to create a dic with all polyExtrudeFace new component ids
extrudenodes = [e for e in cmds.listHistory(sel) if cmds.nodeType(e) == 'polyExtrudeFace']
#current vtx count
current_vtx_nb = cmds.polyEvaluate(sel, v=1)
# disable a polyExtude
cmds.setAttr("{}.nodeState".format(extrudenodes[0]), 1)
# get the previous number
previous_vtx_nb = cmds.polyEvaluate(sel, v=1)
# re-enable it
cmds.setAttr("{}.nodeState".format(extrudenodes[0]), 0)
# get the range
nb = current_vtx_nb - previous_vtx_nb
mrang = [current_vtx_nb-nb,current_vtx_nb]
# recreate the vtx s3election
out = ['{}.vtx[{}]'.format(sel[0], i) for i in range(*mrang)]
# select the vertex
cmds.select(out)
编辑:
这是建筑物字典循环的示例:
import maya.cmds as cmds
'''
This script build the vertices data loop
'''
class Counter:
idCounter = 0
def __init__(self):
Counter.idCounter += 1
def loopIncSel():
'relaunch the command to loop throught all key of the dic'
if sorted(dataExtrude.keys()):
count = Counter().idCounter % len(dataExtrude.keys())
k = dataExtrude.keys()[count]
cmds.select(dataExtrude[k])
# get the object
sel = cmds.ls(sl=True, o=True)
# get the extrude nodes, useful to create a dic with all polyExtrudeFace new component ids
extrudenodes = [e for e in cmds.listHistory(sel) if cmds.nodeType(e) == 'polyExtrudeFace']
# dic data :
dataExtrude = {}
for n in extrudenodes:
cmds.setAttr("{}.nodeState".format(n), 1)
# reverse the processus to re-enable,
# note that if there is node in between creating vertices and faces, it won't work
for n in extrudenodes[::-1]:
# get the previous number
previous_vtx_nb = cmds.polyEvaluate(sel, v=1)
# re-enable it
cmds.setAttr("{}.nodeState".format(n), 0)
#current vtx count
current_vtx_nb = cmds.polyEvaluate(sel, v=1)
# get the range
nb = current_vtx_nb - previous_vtx_nb
mrang = [current_vtx_nb-nb,current_vtx_nb]
# recreate the vtx s3election
dataExtrude[n] = ['{}.vtx[{}]'.format(sel[0], i) for i in range(*mrang)]
# select the vertex
# cmds.select(dataExtrude['polyExtrudeFace3'])
loopIncSel()
答案 1 :(得分:0)
在网格上应用cmds.polyExtrudeFacet
时,Maya将自动选择新面。知道了这一点,很容易将面部组件转换为新的顶点:
cmds.polySphere(name="pSphere1") # Create a sphere to test with.
cmds.polyExtrudeFacet("pSphere1.f[10]") # Extrude a random face.
sel = cmds.polyListComponentConversion(cmds.ls("*.f[*]", sl=True), fromFace=True, toVertex=True) # Convert faces to verts. Filter `ls` to only get face selections.
cmds.select(sel) # Select the newly created vertexes.