+ Reply to Thread
Results 1 to 7 of 7

Thread: Extract faces from a Brep

  1. #1

    Extract faces from a Brep

    Hi all- I am messing with a script that involves removing faces from a brep. At the moment, the way I am doing this works but seems a little clunky- there must be a better way: I identify all the faces in the original brep that I want to extract and and duplicate them, and add them to the document. Then I duplicate all the other (non-extracted) faces in the original and join into a new brep, add that to the document, and then delete the original brep.
    This works in most cases, even if it is not the most efficient, but where it falls down is when some faces are bad-- so far, bad faces are not duplicated and that throws the rest of the script off.

    Any ideas?

    thanks, Pascal

  2. #2
    I don't know how to select faces of a brep, but if you can figure out their index in the Rhino.Brep.Faces list then you can use:

    Rhino.Geometry.Collection.BrepFaceList.RemoveAt()

    This seems to work here:

    Code:
    import rhinoscriptsyntax as rs
    import scriptcontext as sc
    import Rhino
    
    
    brep = rs.GetObject('pick brep')
    
    rBrep = rs.coercerhinoobject(brep)
    
    #to check face list
    for face in rBrep.Geometry.Faces:
        print face
        
    
    #remove a face from the face list
    rBrep.Geometry.Faces.RemoveAt(1)
    
    #make a new brep by duplicating the original but now has 1 face deleted
    newRBrep = rBrep.DuplicateBrepGeometry()
    
    print 'CHANGE'#just to break lists
    
    #to check face list of new brep...should be -1
    for face in newRBrep.Faces:
        print face
        
    #this replaces the original brep in the document with the new on without the face
    sc.doc.Objects.Replace(brep, newRBrep)
    
    #redraw views
    rs.Redraw()

  3. #3
    Hi, thanks a lot- that is what I was looking for. And yet I am not sure I can use it in this script because, as far as I can see, only one face at a time can be removed- I have a list of indices and I want to remove them all but of course each one I remove rearranges the indices in the brep so that after the first one, the wrong faces are removed. Sigh.

    Also, now I see there is an ExtractFace method, which may help simplify things as well.

    thanks again,

    -Pascal
    Last edited by Pascal; 09-11-2012 at 05:00 AM.

  4. #4
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    I typically remove things from a list in reverse order (face8, face5, face4,...) since this way the indices stay the same for what you want to remove.

  5. #5
    Hi Steve- OK! thanks--- so simple... works fine.
    -Pascal
    Last edited by Pascal; 09-11-2012 at 04:30 PM.

  6. #6
    Hi Steve - One more thing- the result can be a disjoint brep; are there any tools for detecting these and splitting them up? I'm not seeing anything so far. Thanks.

    -Pascal

  7. #7
    Quote Originally Posted by Steve Baer View Post
    I typically remove things from a list in reverse order (face8, face5, face4,...) since this way the indices stay the same for what you want to remove.
    Steve - Is there an easy way to find the parent brep of a surface?

    Thanks,

    Nathan

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts