Extract Surface - Python


I would like to create a Python script that extract one planar surfaces from a 3D object. I realized that ExtractSurface requires a “face_indices” parameter that is a list or a number of the face on the object but it does not allow to click on the required surface. How to select a required surface? Is there other method?

Hi @onrender,

you can use rs.GetObject() with subobjects=True to obtain an ObjRef class. From this you can get the picked Polysurface, it’s Id and the index of the picked surface which you can pass to rs.ExtractSurface() to extract it:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    message = "Pick surface to extract"
    obj_ref = rs.GetObject(message, rs.filter.surface, False, False, None, True)
    if not obj_ref: return
    ci = obj_ref.GeometryComponentIndex
    if ci.Index < 0: return
    obj_id = obj_ref.Object().Id
    srf_id = rs.ExtractSurface(obj_id, ci.Index, copy=False)
    if srf_id: rs.SelectObject(srf_id)


Many Thanks Clement.