Python: preselected mesh face or edge

Hi, I am working on some mesh tools in python and have not found any ways to handle preselected mesh edges or faces, Is it possible?


below allows preselection of mesh faces from multiple meshes:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def GetMeshFaces():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select mesh faces")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshFace
    go.SubObjectSelect = True
    go.EnablePreSelect(True, True)
    get_rc = go.GetMultiple(1, 0)
    if not go.CommandResult() == Rhino.Commands.Result.Success: return
    if get_rc == Rhino.Input.GetResult.Object:
        for objref in go.Objects():
            print "Mesh Id:", objref.ObjectId
            print "Face Index:", objref.GeometryComponentIndex.Index
if __name__=="__main__":

To get mesh edges in the same way, just change the GeometryFilter:

go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshEdge


1 Like

Thanks, I feared I had to use Rhino Common… :slightly_smiling:

It’s a Common problem :stuck_out_tongue_winking_eye:


Do not fear Rhino Common. Once you start using it, its a big timesaver in many situations.
You can start working with geometry without ever adding it to the document.
So no worries about ‘garbage’ collection or undo trouble.

I admit that custom object selections like the example above are overwhelming and easy to want to keep away from.
However as per example here, it’s this type of customization Rhino Common has to offer in addition to pre-canned script-syntax methods.


1 Like

Oh, and here I hoped I didn’t need to invest more time into more complex programming, I have spent enough hours as it is :wink: My mind can handle it, but my memory can’t… it’s stuffed up there!