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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API: How to loft between a closed edge from a solid to a sketched profile

Message 1 of 3
568 Views, 2 Replies

API: How to loft between a closed edge from a solid to a sketched profile

I am trying to write a script to create a patch loft between a closed edge on a solid to a sketched circle profile (both highlighted in blue). The solid is a sweep feature obtained from a square profile swept through a closed spline curve. 



My first problem is that I do not know how to convert the closed BRep edge on the solid to a profile object type. I tried to use the following lines of code to create profile:


brep_edges = rootComp.bRepBodies[0].edges 

profile0 = brep_edges[4]


But when I tried to loft, I got the following error message:

RuntimeError 3: Invalid entity type: entities the BRepFace, Profile, Path, SketchPoint, ConstructionPoint, or an ObjectCollection containing a contiguous set of Profile objects that defines the section.


So I went into debug mode, it shows that the object type for profile0 is fusion.BRepEdge. So I thought need to convert that BRep edge into a profile. So I tried to use the following lines of code:


brep_edges = rootComp.bRepBodies[0].edges

profile0 = rootComp.createBRepEdgeProfile(brep_edges[4])


This time in debug mode, it shows that profile0 is a fusion.Profile object type. But when I tried to loft between profile0 and profile1 (which is a circle on a sketch), I received the following error message:

TypeError: LoftSections_add() takes exactly 2 arguments(1 given)


So I used profile0.isValid to check whether the profile is valid, but was returned with False. It seems that I managed to create a Profile from a BRep edge, but the profile is not valid. I don't know where went wrong. 


My second problem is I do not know how to identify my desired edge on that solid. Is there ways to differentiate these edges automatically without user interaction?


Many thanks in advance.


Message 2 of 3
in reply to: sl3117

Below is some code that creates the loft you defined.  I hard-coded some values to make it easy to find the existing body and the sketch.  It works with the attached f3d file, but you'll see there's nothing special with it other than the sketch and body have the names that the script is expecting.  To use the edge of the solid as input for a loft you need to create a "path".  Profiles are always 2D and consist of geometry within a single sketch.  Paths can be 3D and can consist of a mix of edges and sketch geometry.


About your question on how to identify the desired edge, there is access to the edges of a solid and you can get the geometry information of those edges.  Using that you'll have to somehow figure out which of the edges is the one you want.

def run(context):
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        body = root.bRepBodies.itemByName('Body2')
        edge = body.edges.item(2)
        sketch = root.sketches.itemByName('Sketch6')
        circleProfile = sketch.profiles.item(0)
        path = adsk.fusion.Path.create(edge, adsk.fusion.ChainedCurveOptions.tangentChainedCurves)
        loftInput = root.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftInput.isSolid = False
        if ui:
Brian Ekins
Inventor and Fusion 360 API Expert
Message 3 of 3
in reply to: BrianEkins

Many thanks Brian for your detailed explanation. I tried to use Path and it works like a charm.




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