Lofting two lofts through API

Lofting two lofts through API

BradAndersonJr
Enthusiast Enthusiast
1,094 Views
5 Replies
Message 1 of 6

Lofting two lofts through API

BradAndersonJr
Enthusiast
Enthusiast

Greetings!

 

I've hit a wall with a script I'm working on.  I've created 4 lines, and from them created two pairs a distance apart from each other.  Now I'm trying to loft to two together to form a solid shape.  I'm lost at how to define the initial lofts to be called upon for the 3rd loft.  Very novice to scripting, I apologize for my 'lingo'.  Here's part of the code I have so far for the lofting.

 

        # Create input
        loftFeats = rootComp.features.loftFeatures
        loftInput1 = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftSectionsObj1 = loftInput1.loftSections
        loftSectionsObj1.add(openProfile2)
        loftSectionsObj1.add(openProfile1)
        loftInput1.isSolid = False
       
        # Create 
        loftFeats.add(loftInput1)

        # Create input
        loftInput2 = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftSectionsObj2 = loftInput2.loftSections
        loftSectionsObj2.add(openProfile3)
        loftSectionsObj2.add(openProfile4)
        loftInput2.isSolid = False
       
        # Create
        loftFeats.add(loftInput2)

#        # Create input
#        loftInput3 = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
#        loftSectionsObj3 = loftInput3.loftSections
#        loftSectionsObj3.add(loftInput1)
#        loftSectionsObj3.add(loftInput2)
#        loftInput3.isSolid = False
#       
#        # Create
#        loftFeats.add(loftInput3)

loftQuestion.png

 

Here's the two new surfaces I'm trying to loft together.  I'm sure I just need to define each new loft as a surface, but don't know how.

 

Thanks for any help or guidance! 

 

Brad

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
0 Likes
Accepted solutions (1)
1,095 Views
5 Replies
Replies (5)
Message 2 of 6

marshaltu
Autodesk
Autodesk

Hello,

 

It would be good if you can record a video to explain what you were going to do. You can create a loft in UI according to your thoughts. Then I can probably give clues how to do same by API.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 3 of 6

BradAndersonJr
Enthusiast
Enthusiast

Hey Marshal!

 

I recorded a simple Screencast of the operations I'm trying to complete via the API.  I'm able to create the first 2/side lofts via my script but am stuck on how to loft the two surfaces together to create a whole object.

 

From what I've gathered so far, I need to specify that the newly created surfaces are BRepFaces and that's how I should call them in my 3rd loft feature.  I just have no clue how to do that in the API, yet!

 

Thanks for any help!

 

Brad

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
0 Likes
Message 4 of 6

BradAndersonJr
Enthusiast
Enthusiast

 

 

 

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor
Accepted solution

I believe the code below will create what you described.

 

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent
        
        # Create a sketch and draw the four lines.
        sk = root.sketches.add(root.xYConstructionPlane)
        lines = sk.sketchCurves.sketchLines
        line1 = lines.addByTwoPoints(adsk.core.Point3D.create(0,0,0),
                                     adsk.core.Point3D.create(1,10,0))
        line2 = lines.addByTwoPoints(adsk.core.Point3D.create(15,0,0),
                                     adsk.core.Point3D.create(16,12,0))
        line3 = lines.addByTwoPoints(adsk.core.Point3D.create(2,-1,8),
                                     adsk.core.Point3D.create(3,10,7))
        line4 = lines.addByTwoPoints(adsk.core.Point3D.create(17,0,8),
                                     adsk.core.Point3D.create(15,12,9))

        # Create a loft between two of the lines.
        loftInput = root.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        section1 = loftInput.loftSections.add(root.features.createPath(line1, False))
        section2 = loftInput.loftSections.add(root.features.createPath(line3, False))
        loft1 = root.features.loftFeatures.add(loftInput)

        # Create a second loft between two of the lines.
        loftInput = root.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        section1 = loftInput.loftSections.add(root.features.createPath(line2, False))
        section2 = loftInput.loftSections.add(root.features.createPath(line4, False))
        loft2 = root.features.loftFeatures.add(loftInput)
        
        # Create the loft between the two faces.
        loftInput = root.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        section1 = loftInput.loftSections.add(loft1.faces.item(0))
        section2 = loftInput.loftSections.add(loft2.faces.item(0))
        loft3 = 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 6 of 6

BradAndersonJr
Enthusiast
Enthusiast

Hey Brian!

 

Thanks for the help!  It definitely turns out it was the ' faces.item(0) ' bit that I was lacking!  Adding it to the end of each Loft "block" gave me the results I need!  I ended up with:

 

        # Create surface for bridge-end of fretboard
        loftFeats = rootComp.features.loftFeatures
        loftInput1 = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftSectionsObj1 = loftInput1.loftSections
        loftSectionsObj1.add(openProfile2)
        loftSectionsObj1.add(openProfile1)
        loftInput1.isSolid = False
        
        loft1 = loftFeats.add(loftInput1)
        l1 = loft1.faces[0]

        # Create surface for nut-end of fretboard
        loftInput2 = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftSectionsObj2 = loftInput2.loftSections
        loftSectionsObj2.add(openProfile3)
        loftSectionsObj2.add(openProfile4)
        loftInput2.isSolid = False
       
        loft2 = loftFeats.add(loftInput2)
        l2 = loft2.faces[0]

        # Create surface using previous surfaces
        loftInput3 = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftSectionsObj3 = loftInput3.loftSections
        loftSectionsObj3.add(l1)
        loftSectionsObj3.add(l2)
        loftInput3.isSolid = False

        loft3 = loftFeats.add(loftInput3)

Thanks!

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
0 Likes