是否可以将文本查询到 Maya UI 中的文本字段中,以便与长连续行相比,在每个对象后面显示新行?
我想在文本字段中显示一系列顶点,每个顶点都在自己的行上,而不是一个长的连续行。使其很难阅读并且不美观。漂亮与功能同样重要。
这是我到目前为止所拥有的,但我似乎无法在每个顶点之后以新行显示。
import maya.cmds as cmds
def get_selected_vertices():
# Get selected vertices
selected_vertices = cmds.ls(selection=True, flatten=True)
# Get world positions of selected vertices
vertex_positions = [cmds.pointPosition(vertex, world=True)
for vertex
in selected_vertices]
return vertex_positions
def display_selected_verts(*args):
# Get selected vertices and their positions
vertex_positions = get_selected_vertices()
# Clear existing text field content
cmds.textField("vertexTextField", edit=True, text="")
# Display vertex positions in the text field
for pos in vertex_positions:
cmds.textField("vertexTextField", edit=True, insertText=str(pos) + "\n")
#def create_ui():
# Create UI window
cmds.window(window_name, title="Selected Vertices Display", widthHeight=(300, 200))
cmds.columnLayout(adjustableColumn=True)
# Create text field to display selected vertex positions
cmds.text(label="Selected Vertices Positions:")
cmds.textField("vertexTextField", editable=False, height=100, width = 10)
# Create button to display selected vertices
cmds.button(label="Display Selected Vertices", command=display_selected_verts)
cmds.showWindow()
另一位不和谐的艺术家向我展示了光明。 textField 仅设计用于处理单行。我需要的是能够处理多行并且能够滚动的东西。所以有一个名为scrollField的命令,它允许多行和滚动的能力。
我刚刚将textField更改为scrollField,该工具就起作用了。