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

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

Anonymous
Not applicable
945 Views
2 Replies
Message 1 of 3

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

Anonymous
Not applicable

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. 

Capture.PNG

 

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.

 

0 Likes
Accepted solutions (1)
946 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

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):
    try:
        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.loftSections.add(path)
        loftInput.loftSections.add(circleProfile)
        loftInput.isSolid = False
        
        root.features.loftFeatures.add(loftInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) 
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

Anonymous
Not applicable

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

Capture.PNG

 

Best

0 Likes