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: 

Create path with multiple lines using F360 API

1 REPLY 1
SOLVED
Reply
Message 1 of 2
tmateke1
373 Views, 1 Reply

Create path with multiple lines using F360 API

I am trying to create a path that consists of several straight lines rather than just one. I am testing whether the path has successfully been created by creating a loft between two paths. The code below creates a loft between two paths that each consist of one line. I would like for it two loft together two paths that each consist of two lines. Where the paths have been created, I have included some comments that show things I have tried that have not worked.

 

import adsk.core
import adsk.fusion
import traceback


def run(context):
    ui = None
    try:
        # Get root component and ui
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct
        root_comp = design.rootComponent

        # Get sketches and xy_plane
        sketches = root_comp.sketches
        xy_plane = root_comp.xYConstructionPlane

        # Define points
        points1 = []
        points1.append(adsk.core.Point3D.create(0, 0))
        points1.append(adsk.core.Point3D.create(0, 2))
        points1.append(adsk.core.Point3D.create(2, 4))
        points2 = []
        points2.append(adsk.core.Point3D.create(0, 0, 1))
        points2.append(adsk.core.Point3D.create(0, 2, 1))
        points2.append(adsk.core.Point3D.create(2, 4, 1))

        # Make lines
        sketch1 = sketches.add(xy_plane)
        sketch_lines = sketch1.sketchCurves.sketchLines
        line1 = sketch_lines.addByTwoPoints(points1[0], points1[1])
        line2 = sketch_lines.addByTwoPoints(points1[1], points1[2])
        sketch2 = sketches.add(xy_plane)
        sketch_lines = sketch2.sketchCurves.sketchLines
        line3 = sketch_lines.addByTwoPoints(points2[0], points2[1])
        line4 = sketch_lines.addByTwoPoints(points2[1], points2[2])

        # Create paths
        # Need help here
        features = root_comp.features
        path1 = features.createPath(line1)
        path2 = features.createPath(line3)
        # path1 = features.createPath([line1,line2])?
        # path1 = features.createPath(sketch.sketchCurves)?
        # path1 = features.createPath(sketch.sketchCurves.sketchLines)?

        # Create loft feature
        new_feature = adsk.fusion.FeatureOperations.NewBodyFeatureOperation
        loft_features = features.loftFeatures
        loft_input = loft_features.createInput(new_feature)

        # Add sections
        loft_sections = loft_input.loftSections
        loft_sections.add(path1)
        loft_sections.add(path2)
        loft_features.add(loft_input)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

The code above creates the loft shown below. I would like it to loft together the remaining lines too by creating paths that contain multiple lines.

tmateke1_0-1588780472337.png

 

Temba

 

Tags (4)
1 REPLY 1
Message 2 of 2
tmateke1
in reply to: tmateke1

I've since figured this out in two different ways

        # Create paths
        features = root_comp.features
        collection = adsk.core.ObjectCollection.create()
        collection.add(line1)
        collection.add(line2)
        path1 = features.createPath(collection)
        path2 = features.createPath(line3)
        path2.addCurves(line4, 1)

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