[Python] sub object selection is not trimmed

Hi,

I was looking at this thread:

I tried using the scripts but something gets messed up.
When I extract the face and try to create a surface out of it the trim information is not passed on to the resulting surface.

This is what I do:

# get_brep_face.py
# created by Helvetosaur Mar 2014
# modified and adapted by zooid Mar 2019

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def GetOnlyBrepFace():
    msg="Select a surface or Brep face to offset"
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt(msg)
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
    go.GeometryAttributeFilter=Rhino.Input.Custom.GeometryAttributeFilter.SubSurface
    go.SubObjectSelect = True
    go.AcceptNothing(False)
    
    if go.Get()!=Rhino.Input.GetResult.Object: return
    objref = go.Object(0)
    objrefsurf = objref.Surface()
    print objrefsurf
    if objrefsurf is not None:
        tmp_surf = sc.doc.Objects.AddSurface(objrefsurf)
        rs.UnrollSurface(surface_id=tmp_surf,explode=False,following_geometry=None,absolute_tolerance=None,relative_tolerance=None)
        rs.DeleteObject(tmp_surf)
        
    else:
        return
    #etc
    
GetOnlyBrepFace()

BrepFace:

Result:
image

Is there a way to pass on the trim information as well?

I see now there is a class BrepTrim,
I can extract the so called BrepTrim from the Brep.

But in Rhino.Geometry.Brep.Trim() I need an interval. How can I use the information from BrepTrim in order to trim a surface created from a sub-surface of a brep? :thinking:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def SubObjectSelect():
    obj_ref = rs.GetObject(message="Bla", filter=rs.filter.curve, preselect=False, subobjects=True)
    if obj_ref:
        #print "Surface:", obj_ref.Surface()
        print "Selection Point:", obj_ref.SelectionPoint()
        objrefsurf = obj_ref.Surface()
        #border = rs.DuplicateEdgeCurves(obj_ref)
        trim = obj_ref.Trim()

Hi @ivelin.peychev,
Surfaces can’t store trimming information, that’s what breps are for. So instead of converting to a surface in your “get”, if you want to keep the trims convert to brep instead und unroll that brep

1 Like

Good idea @lando.schumpich, but doesn’t really work properly. See my breps are Polysurfaces. Imagine a plate and thickness. If I use brep obj_ref.Brep() then in the unroll command each sub-part of this brep is passed. As a result I don’t just get one object unrolled but all of them. Which is not what I need.

I tried using also obj_ref.Face() to get the face out of the brep. But when adding the object to the doc with sc.doc.Objects.AddBrep(the_face) it throws an error that it’s a Face and not a Brep. If I try to add it as a surface I again get the untrimmed one.

# select_subobjects.py
# created by clement Mar 2014
# modified and adapted by zooid Mar 2019
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def SubObjectSelect():
    obj_ref = rs.GetObject(message="Bla", filter=rs.filter.surface, preselect=False, subobjects=True)
    if obj_ref:
        #print "Surface:", obj_ref.Surface()
        print "Selection Point:", obj_ref.SelectionPoint()
        #objrefsurf = obj_ref.Surface()
        #objrefbrep = obj_ref.Brep()
        objrefbrep = obj_ref.Face()
        
        #trim = obj_ref.Trim()
        #print trim
        #trim_obj = sc.doc.Objects.AddSurface(trim)
        if objrefbrep is not None:
            #tmp_surf = sc.doc.Objects.AddSurface(objrefsurf)
            tmp_brep = sc.doc.Objects.AddBrep(objrefbrep)
            rs.UnrollSurface(surface_id=tmp_brep,explode=False,following_geometry=None,absolute_tolerance=None,relative_tolerance=None)
            rs.DeleteObject(tmp_brep)
            
        else:
            return
if __name__=="__main__":
    SubObjectSelect()

image

and this:

# select_subobjects.py
# created by clement Mar 2014
# modified and adapted by zooid Mar 2019
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def SubObjectSelect():
    obj_ref = rs.GetObject(message="Bla", filter=rs.filter.surface, preselect=False, subobjects=True)
    if obj_ref:
        #print "Surface:", obj_ref.Surface()
        print "Selection Point:", obj_ref.SelectionPoint()
        #objrefsurf = obj_ref.Surface()
        objrefbrep = obj_ref.Brep()
        #objrefbrep = obj_ref.Face()
        
        #trim = obj_ref.Trim()
        #print trim
        #trim_obj = sc.doc.Objects.AddSurface(trim)
        if objrefbrep is not None:
            #tmp_surf = sc.doc.Objects.AddSurface(objrefsurf)
            tmp_brep = sc.doc.Objects.AddBrep(objrefbrep)
            rs.UnrollSurface(surface_id=tmp_brep,explode=False,following_geometry=None,absolute_tolerance=None,relative_tolerance=None)
            rs.DeleteObject(tmp_brep)
            
        else:
            return
if __name__=="__main__":
    SubObjectSelect()

results in this:

Perhaps Unroll isn’t what I need at all since it requires a surface not a Brep (polysurface). But I still don’t know how to Squish using RhinoCommon :smiley:
And on top of all scripting the Squish command is a pain.

hey @ivelin.peychev,
Unroll is exactly what you need for flat surfaces :wink:

have a look at this (rough) codesample, especially at the unroller class:
https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Unroller.htm

import Rhino
import scriptcontext as sc

def subSurfaceSelectUnroll():
    
    # set up getter
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Sub select a brep face")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface
    # get
    go.Get()
    # test if success
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return go.CommandResult()
        
    # get geometry (is brepface)
    brepFace = go.Object(0).Geometry()
    # get parent
    brepParent = brepFace.Brep
    # extract face from brepParent faces list (preserves trims)
    brepTrimmed = brepParent.Faces.ExtractFace(brepFace.FaceIndex)
    
    # create instance of unroller class, with trimmed face as input
    unroller = Rhino.Geometry.Unroller(brepTrimmed)
    # unroll
    arrBrepUnrolled, arrCurveUnrolled, arrPointUnrolled, arrTextDotUnrolled = unroller.PerformUnroll()
    
    # add to doc
    for brep in arrBrepUnrolled:
        sc.doc.Objects.AddBrep(brep)
        
if __name__ == "__main__":
    subSurfaceSelectUnroll()
1 Like

Wow, thanks a lot @lando.schumpich,

McNeel:
brep.Faces.ExtractFace() is nowhere to be found in the API browser inside the PythonEditor.
How could one even know such method exists?

Update:
Ok, I retract my previous statement.
But how could one know it’s here:

image

image