Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How do I turn temporary BRep Surfaces into temporary BRep Solid

Anonymous

How do I turn temporary BRep Surfaces into temporary BRep Solid

Anonymous
Not applicable

I have created a few surfaces with the TemporaryBRepManager that I would like to turn into a temporary BRep Solid.

They form a watertight volume. I haven't found how to turn them into a solid.

I don't see a method for that in the TemporaryBRep manager.

I have tried to use a Boundary fill feature but it seems to only work with real BRep Bodies, I am guessing its not the right tool for that.

How can I do this?

 

 

            height = 15
            width = 15
            length = 100
            module = 2
            helixAngle = 0.349066
            pressureAngle = 0.349066


            app = adsk.core.Application.get()
            des = app.activeProduct
            root = des.rootComponent
            bodies = root.bRepBodies        

            # Creating a base feature is the best option for doing direct modeling in an otherwise parametric design
            # Needs to be created, started and finished afterwards
            baseFeature = root.features.baseFeatures.add()
            baseFeature.startEdit()     

            # The temporaryBRep manager is a tool for creating 3d geometry without the use of features
            # The word temporary referrs to the geometry being created being virtual, but It can easily be converted to actual geometry
            tbm = adsk.fusion.TemporaryBRepManager.get()

            #Array to keep track of TempBRepBodies
            tempBRepBodies = []  

            def rackLines(x ,y ,z , m, n, height, pAngle, hAngle):
                strech = 1/math.cos(hAngle)
                P = m * math.pi

                blsh = 0

                lines = []

                for i in range(n):
                    # Root
                    lines.append(
                        adsk.core.Line3D.create(adsk.core.Point3D.create( x + (i*P), y, z - 1.25 * m ),
                                                adsk.core.Point3D.create( x + (i*P) + (P/2) + blsh - (math.tan(pAngle) * 2.5 * m) , y, z - 1.25 * m ))
                    )
                    # Left Edge
                    lines.append(
                        adsk.core.Line3D.create(adsk.core.Point3D.create( x + (i*P) + (P/2) + blsh - (math.tan(pAngle) * 2.5 * m) , y, z - 1.25 * m ),
                                                adsk.core.Point3D.create( x + (i*P) + (P/2) + blsh - (math.tan(pAngle) * 0.25 * m) , y, z + m ))
                    )
                    # Tip
                    lines.append(
                        adsk.core.Line3D.create(adsk.core.Point3D.create( x + (i*P) + (P/2) + blsh - (math.tan(pAngle) * 0.25 * m) , y, z + m ),
                                                adsk.core.Point3D.create( x + (i*P) + P - blsh - (math.tan(pAngle)*2.25*m) , y, z + m ))
                    )
                    # Right Edge
                    lines.append(
                        adsk.core.Line3D.create(adsk.core.Point3D.create( x + (i*P) + P - blsh - (math.tan(pAngle)*2.25*m) , y, z + m ),
                                                adsk.core.Point3D.create( x + (i*P) + P, y, z - 1.25 * m ))
                    )
                    
                # Right Edge
                lines.append(
                    adsk.core.Line3D.create(adsk.core.Point3D.create( x + (n*P), y, z - 1.25 * m ),
                                            adsk.core.Point3D.create( x + (n*P), y, z - height ))
                )
                # Bottom Edge
                lines.append(
                    adsk.core.Line3D.create(adsk.core.Point3D.create( x + (n*P), y, z - height ),
                                            adsk.core.Point3D.create( x, y, z - height ))
                )
                # Left Edge
                lines.append(
                    adsk.core.Line3D.create(adsk.core.Point3D.create( x, y, z - height ),
                                            adsk.core.Point3D.create( x, y, z - 1.25 * m ))
                )

                return lines

            # Creates BRep wire object(s), representing edges in 3D space from an array of 3Dcurves
            wireBody1, _ = tbm.createWireFromCurves(rackLines(0, 0, 0, module, 12, height, pressureAngle, helixAngle))

            wireBody2, _ = tbm.createWireFromCurves(rackLines(0, width, 0, module, 12, height, pressureAngle, helixAngle))

            # Creates a planar face from an array of Wires.
            face = tbm.createFaceFromPlanarWires([wireBody1])

            tempBRepBodies.append(face)


            # Creates a planar face from an array of Wires.
            face = tbm.createFaceFromPlanarWires([wireBody2])

            tempBRepBodies.append(face)


            surface = tbm.createRuledSurface(wireBody1.wires.item(0), wireBody2.wires.item(0))

            tempBRepBodies.append(surface)


            tools = adsk.core.ObjectCollection.create()

            for b in tempBRepBodies:
                #tools.add(bodies.add(b, baseFeature))
                tools.add(b)

            boundaryFills = root.features.boundaryFillFeatures
            boundaryFillInput = boundaryFills.createInput(tools, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

            boundaryFillInput.targetBaseFeature = baseFeature

            print(boundaryFillInput.tools.count)

            cell = boundaryFillInput.bRepCells.item(0)
            cell.isSelected = True

            boundaryFills.add(boundaryFillInput)  

            # Finishes the base feature
            baseFeature.finishEdit()
None
3
Traceback (most recent call last):
  File "/Users/nicoschluter/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/RackTest/RackTest.py", line 184, in notify
    cell = boundaryFillInput.bRepCells.item(0)
  File "/Users/nicoschluter/Library/Application Support/Autodesk/webdeploy/production/1235e987d853b6f5773abdcdd7ff0ff6bea9a707/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/fusion.py", line 3977, in item
    return _fusion.BRepCells_item(self, *args)
RuntimeError: 2 : InternalValidationError : Xl::Utils::getObjectPath(object.get(), objPath, occurrence, contextPath)

 

0 Likes
Reply
Accepted solutions (1)
775 Views
3 Replies
Replies (3)

JesusFreke
Advocate
Advocate
Accepted solution

I think a stitch feature is what you want.

 

Also, you can't directly use features on temporary brep objects. You have to import the object into the fusion document, and then perform the feature on the imported object.

 

See, e.g. my _create_component method, which accepts a list of possibly temporary brep bodies, creates a new component, imports the bodies into the component and returns an occurrence of that component.

 

You can then use the bodies in the new component/occurrence in a feature. If you're using a primarily temporary brep focused workflow, you can then make a temporary brep copy of the body/bodies that the feature produces (TemporaryBRepManager.copy()), and then entirely delete the occurrence/component (Occurrence.deleteMe())

1 Like

Anonymous
Not applicable

Thank you, I was unaware that stitch created solids, I thought it would just make an empty shell. This may be a bit faster then boundary fill.

Boundary fill also works fine with real (imported) surfaces, but I was hoping to only use temporary bodies as I believe them to be way faster than imported ones, at least in my experience.

But I guess that is the only way of doing it. 

0 Likes

JesusFreke
Advocate
Advocate

Yeah, I take a similar approach in my fscad framework. I try to use temporary brep objects as much as possible for better performance, but there are lots of cases where it has to fall back to creating a component and a feature.

1 Like