HELP With Fill Command

needhelp
needhelp Member Posts: 3
First Comment
**

So, I have a question on how to fill.

I have a large number of shapes made by curves. I would like to fill in the area outside of the shapes, and not in the shapes. Below is the code I figured out would fill in the shapes. How can I modify this code?

selection = Selection.Create(Curve1,Curve2,Curve3,Curve4,Curve5,Curve) secondarySelection = Selection.Empty()
options = FillOptions()
results = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info2)

Thanks for your help,

Colin

Answers

  • NickFL
    NickFL Member Posts: 6
    Name Dropper First Comment
    **

    I take it you have a bounding curve and various curves inside of this region that you want to open (like swiss cheese). Here is a code I wrote to do something similar, but it may be overkill for what you need.

    # Python Script, API Version = V23
    def isParent(face0,face1):
        BB = face0.Shape.GetBoundingBox(Matrix.Identity).Size.Magnitude
        bb = face1.Shape.GetBoundingBox(Matrix.Identity).Size.Magnitude
    
        test = BB.CompareTo(bb)
        if test == 1:          # Python is wierd
            Q = True
        else:
            Q = False
    
        return(Q)
    
    def findOuter(facesToReview):
        Parents, Children = [], []
        outerFaces = list([])
        for face in facesToReview:
            numberOfNeighbors = face.AdjacentFaces.Count
    
            # skip those adjacent faces that are no longer part of facesToReview
            for n in range(numberOfNeighbors):
                if not(face.AdjacentFaces[n] in facesToReview):
                    continue
    
                if isParent(face,face.AdjacentFaces[n]):
                    Parents.append(face)
                    Children.append(face.AdjacentFaces[n])
                else:
                    Parents.append(face.AdjacentFaces[n])
                    Children.append(face)
    
        # Outer faces will be only in parents not in children
        for p in Parents:
            if not(p in Children):               
                outerFaces.append(p)
    
        # Remove Duplicates
        p = outerFaces.__len__()
        i = p - 1
        while i >= 1:
            if outerFaces[i] == outerFaces[i-1]:
                del outerFaces[i]
            i -= 1
    
        return(outerFaces)
    
    def isIsolated(facesToReview):
        isoFaces, newFacesToReview = list([]), list([])
        for face in facesToReview:
            neighbors = 0
            for adjacentFace in face.AdjacentFaces:
                if adjacentFace in facesToReview:
                    neighbors += 1
    
            if neighbors == 0: 
                isoFaces.append(face)
            else:
                newFacesToReview.append(face)
    
        return(isoFaces,newFacesToReview)
    
    myBody = GetRootPart().Bodies[-1]      # Change me here!!!
    facesToReview = myBody.Faces[:] 
    deleteMe = False                    # level 1 keep
    facesToDelete = list([])
    
    while facesToReview.Count > 0:
        (isoFaces, facesToReview) = isIsolated(facesToReview)
        if deleteMe: facesToDelete += isoFaces
    
        #Find outer faces
        outerFaces = findOuter(facesToReview)
        for outer in outerFaces:
            if facesToReview.Contains(outer) == True: facesToReview.remove(outer)
            if deleteMe: facesToDelete.append(outer) # add only when on right level
    
        # Alternates betwen delete (2nd, 4th) and not (1st, 3rd)
        deleteMe = not(deleteMe)
    
    selection = FaceSelection.Create(facesToDelete)
    result = Delete.Execute(selection)
    

    A couple of points. 1) it currently set up to work on the last created body. You can change that in the myBody variable. 2) It is set up to keep inside the alternating lines. That means if you have a circle inside a circle inside a circle, it will keep the first and thrid circles resulting in a donut with a dot in it. If you don't want this, we can simplify this down a bunch. 3) Lastly, there may be a warning that is given. This is expected because of how I am removing the faces from the lists.

    Let me know if you have any questions. Hopefully this helps.

  • needhelp
    needhelp Member Posts: 3
    First Comment
    **

    Hey,

    Thanks so much, I am learning as I go...sorry for no reprex.
    I will test this out today and respond.

  • needhelp
    needhelp Member Posts: 3
    First Comment
    **

    Hi Nick

    I tried using your code, but because I am really new, I have a hard time viewing the named bodies in the program.

    So far, I have generated enough code to give an example. What I can't figure out is how to create a face or faces between and the curves in Line 19 and then delete this/these faces. Is there any way to do that?

    Attached is my code.

    Really grateful for your help!

    `

    Python Script, API Version = V241

    Fill

    selection = Selection.Create(Curve1, Curve2, Curve3, Curve4, Curve5, Curve6, Curve7, Curve8, Curve9, Curve10, Curve11, Curve12, Curve13, Curve14, Curve15, Curve16, Curve17, Curve18, Curve19, Curve20, Curve21, Curve22, Curve23, Curve24)
    secondarySelection = Selection.Empty()
    options = FillOptions()
    result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info1)

    EndBlock

    Delete Selection

    selection = Curve25
    result = Delete.Execute(selection)

    EndBlock

    Note that to select multiple of our curves, you have to hold ctrl when you start the polygon, and when you stop to s

    select the polygon

    Line 19

    Fill

    Note that Curve... goes for a long time and is omitted here

    selection = Selection.Create(Curve26, Curve27, Curve28, Curve29, Curve30, Curve... )
    secondarySelection = Selection.Empty()
    options = FillOptions()
    result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info2)

    EndBlock

    #

    So far, this selects and fills all the pit holes

    Now I am going to fill the hole thing and then remove the faces

    Fill

    selection = Curve3636
    secondarySelection = Selection.Empty()
    options = FillOptions()
    result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info3)

    EndBlock

    Create New Face

    selection = Face1
    result = ReplaceFacesWithFace.Execute(selection)

    EndBlock

    Create New Face

    selection = Face2
    result = ReplaceFacesWithFace.Execute(selection)

    EndBlock

    #

    #

    `