Message 1 of 3
how to add a face between two planes in a mesh?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a mesh made out of two planes stacked on top each other, and I want to create a new vertical face between these planes.
I selected 4 vertices, two on the top plane, two on the bottom one, in the counter-clockwise order. I wrote a python script that will create a new face, that will be added to the mesh, based on the selection, but it produces an error:
select -cl ;
select -r pPlane3.vtx[151] ;
select -tgl pPlane3.vtx[162] ;
select -tgl pPlane3.vtx[41] ;
select -tgl pPlane3.vtx[30] ;
import maya.cmds as cmds
def create_face_from_selected_vertices():
# Get selected vertices
selected_verts = cmds.ls(selection=True, flatten=True)
# Verify we have exactly 4 vertices selected
if len(selected_verts) != 4:
cmds.warning("Please select exactly 4 vertices (2 from top plane, 2 from bottom plane)")
return
try:
# Get the mesh name from the first selected vertex
mesh_name = selected_verts[0].split('.')[0]
# Get the vertex indices (the numbers after "vtx[" in the vertex names)
vert_pos = []
for v in selected_verts:
# Extract the vertex index from the name (e.g., "pPlane1.vtx[2]" -> 2)
#index = int(v.split('[')[-1].rstrip(']'))
#vert_indices.append(index)
vert_pos.append(cmds.pointPosition(v))
print(vert_pos)
# Create a new face using polyAppend with the append flag
cmds.polyAppend(
mesh_name,
append=vert_pos,
constructionHistory=True
)
# Print success message
print("Successfully created new face between selected vertices")
except Exception as e:
cmds.warning(f"Error creating face: {str(e)}")
# Execute the function
create_face_from_selected_vertices()
[[0.30000001192092896, 0.0, 0.30000001192092896], [0.30000001192092896, 0.0, 0.19999998807907104], [0.30000001192092896, 0.19127875566482544, 0.30000001192092896], [0.30000001192092896, 0.19127875566482544, 0.19999998807907104]]
# Warning: Error creating face: Need at least one "-ed" flag (edge number).
the documentation says that -ed flag should be avoided in Python, how to make this work?