How to get a single MeshFace of a mesh


#1

Hi Steve
I can’t get to duplicate a single face of a mesh.

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def dd():
    rc,meshref=Rhino.Input.RhinoGet.GetOneObject("seleziona mesh face",False, Rhino.DocObjects.ObjectType.MeshFace  )
    rs.EnableRedraw(False)
    if rc!=Rhino.Commands.Result.Success: return 
    #rs.MessageBox(meshref)
    d=meshref.MeshCount()
    rs.MessageBox(d)
    mf=scriptcontext.doc.Objects.AddMesh(d) # i want get  a single MeshFace but return the mesh
    print mf
dd()

Any suggestions?
ciao Vittorio


(Giulio Piacentino) #2

Hi Vittorio

have a look if this is helpful.

import Rhino
import scriptcontext

def AskExtractMeshFace():
    rc, meshref = Rhino.Input.RhinoGet.GetOneObject("select mesh face", False, Rhino.DocObjects.ObjectType.MeshFace)
    if rc != Rhino.Commands.Result.Success: return
    
    #Rhino.DocObjects.ObjRef
    face_component_index = meshref.GeometryComponentIndex
    
    #Rhino.Geometry.ComponentIndex
    face_index = face_component_index.Index
    
    mesh = meshref.Mesh()
    face = mesh.Faces[face_index]
    
    new_mesh = Rhino.Geometry.Mesh()
    
    new_mesh.Vertices.Add(mesh.Vertices[face[0]])
    new_mesh.Vertices.Add(mesh.Vertices[face[1]])
    new_mesh.Vertices.Add(mesh.Vertices[face[2]])
    if face.IsQuad: new_mesh.Vertices.Add(mesh.Vertices[face[3]])
    
    if face.IsTriangle:
        new_mesh.Faces.AddFace(0,1,2)
    else:
        new_mesh.Faces.AddFace(0,1,2,3)
    
    mf=scriptcontext.doc.Objects.AddMesh(new_mesh) # this is a mesh with a single face. A single meshface does not have any "location"
    print mf
AskExtractMeshFace()

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


#3

Hi Giulio
Many thanks. The script is Ok
Ciao Vittorio