Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python API: ThickenFeature missing participantBodies?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
GRSnyder
181 Views, 3 Replies

Python API: ThickenFeature missing participantBodies?

I see that in the Fusion 360 UI, Thicken operations do allow the specification of participant bodies (e.g., those that will be affected by a cut). However, there doesn't seem to be any documented API for this.

 

According to this blog entry from 2017, a participantBodies attribute was added to a few other feature types (and/or their corresponding Input types), but Thicken seems to have been left as a red-headed stepchild. I thought perhaps the feature might actually be there in the API but just undocumented. However, that does not seem to be the case.

 

What I'm actually trying to do is create a flat patch with holes in it. Since PatchFeatures don't (directly) allow the specification of interior loops, I thought the best way to go about it would be to create separate patches for the outer and inner loops, then punch out the outer patch by thicken-cutting the inner patch.

 

I'm guessing that the best work-around would be to continue to generate separate patches, then do a Split Face on the outer patch with each of the inner patches, then delete the faces mentioned in SplitFaceFeature.faces. Then remove the inner patches. That seems like a lot of features - is there a better way?

 

(Unfortunately, I do not think it would work to just bounce all the profiles into a sketch and create a patch from the composite profile. Often, the projection operation seems to perturb the coordinates enough that the loops are no longer closed, although they look closed on inspection.)

3 REPLIES 3
Message 2 of 4
kandennti
in reply to: GRSnyder

Hi @GRSnyder .

 

If you are okay with BaseFuture, you can create a flat patch with holes by using TemporaryBRepManager.

#Fusion360API Python script
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # Parametric
        createHoleFlatPatch(adsk.fusion.DesignTypes.ParametricDesignType)

        # Direct
        createHoleFlatPatch(adsk.fusion.DesignTypes.DirectDesignType)

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def createHoleFlatPatch(
    designType :adsk.fusion.DesignTypes
    ):

    try:
        global _app, _ui

        # create document
        _app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        des  :adsk.fusion.Design = _app.activeProduct
        des.designType = designType

        root :adsk.fusion.Component = des.rootComponent

        # create sketch
        skt :adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)

        pntZero :adsk.core.Point3D = adsk.core.Point3D.create(0,0,0)
        sktCircles :adsk.fusion.SketchCircles = skt.sketchCurves.sketchCircles
        circle1 :adsk.fusion.SketchCircle = sktCircles.addByCenterRadius(pntZero,10.0)
        circle2 :adsk.fusion.SketchCircle = sktCircles.addByCenterRadius(pntZero,5.0)

        # get TemporaryBRepManager
        tmpMgr = adsk.fusion.TemporaryBRepManager.get()

        # get geometry
        crvs = [
            circle1.geometry,
            circle2.geometry
        ]

        # create wireBody
        # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-62A548C4-305D-47D3-9574-A09743736FC8
        wireBody, _ = tmpMgr.createWireFromCurves(crvs)

        # create Flat Patch with Holes
        # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-18D6210D-FF0A-4CA8-8244-CFDC30213A4D
        targetSurf = tmpMgr.createFaceFromPlanarWires([wireBody])

        # add surface
        bodies :adsk.fusion.BRepBodies = root.bRepBodies
        if des.designType == adsk.fusion.DesignTypes.DirectDesignType:
            bodies.add(targetSurf )
        else:
            baseFeatures = root.features.baseFeatures
            baseFeature = baseFeatures.add()
            try:
                baseFeature.startEdit()
                bodies.add(targetSurf , baseFeature)
            except:
                pass
            finally:
                baseFeature.finishEdit()

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 3 of 4
GRSnyder
in reply to: kandennti

Thanks @kandennti, that does look quite a bit simpler. Sure, I guess BaseFeatures would be fine, although I suppose they make the timeline a bit more opaque for the user.

 

I especially appreciate the fact that this API makes Fusion 360 sort out the loops. The way I had been approaching it, I had to identify the outer loop on my own, which was kind of a pain.

 

I will give it a shot!

Message 4 of 4
GRSnyder
in reply to: GRSnyder

Just to follow up for anyone seeing this in the future: this approach works well.

 

The only tricky part is that edges for a wire loop must be presented in sequence. If you are using existing BRepEdges and do not know the proper order (e.g., because you are picking edges of multiple faces), you must sequence them manually. Edges can abut end-to-start, start-to-start, end-to-end, or start-to-end, so it's not as simple as just looking for an edge whose startVertex is the same as the previous edge's endVertex.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report