Sketches on multiple offset construction planes

Sketches on multiple offset construction planes

Anonymous
1,527 Views
2 Replies
Message 1 of 3

Sketches on multiple offset construction planes

Anonymous
Not applicable

Hi all-

 

Fairly new to Fusion 360 and definitely to this API/programming...

 

I want to basically have an external file of coordinates being imported (something like the importCSV script) and have curves drawn on sketches that are on a series of offset construction planes (see below) - we'll deal with looping later... I've been cobbling together two of the sample API scripts to get a better grasp of how to do this and have ended up with this so far:

 

So, how do I 1. create a sketch on a construction plane and 2. create a curve on that new sketch? Thanks!

 

*********************

 

import adsk.core, adsk.fusion, traceback

 

def run(context):

ui = None

try:

app = adsk.core.Application.get()

ui = app.userInterface

 

# Create a document.

doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

 

product = app.activeProduct

design = adsk.fusion.Design.cast(product)

 

# Get the root component of the active design

rootComp = design.rootComponent

 

# Create sketch

sketches = rootComp.sketches

sketch = sketches.add(rootComp.xZConstructionPlane)

 

# Create sketch circle

sketchCircles = sketch.sketchCurves.sketchCircles

centerPoint = adsk.core.Point3D.create(0, 0, 0)

sketchCircles.addByCenterRadius(centerPoint, 5.0)

 

# Get the profile defined by the circle

prof = sketch.profiles.item(0)

 

# Get construction planes

planes = rootComp.constructionPlanes

 

# Create construction plane input

planeInput = planes.createInput()

 

# Add construction plane by offset

offsetValue = adsk.core.ValueInput.createByReal(3.0)

planeInput.setByOffset(prof, offsetValue)

planeOne = planes.add(planeInput)

 

 

# Create an object collection for the points.

points = adsk.core.ObjectCollection.create()

 

# Define the points the spline with fit through.

points.add(adsk.core.Point3D.create(0, 0, 0))

points.add(adsk.core.Point3D.create(5, 1, 0))

points.add(adsk.core.Point3D.create(6, 4, 0))

 

# Create the spline.

sketch.sketchCurves.sketchFittedSplines.add(points)

 

offsetValue = adsk.core.ValueInput.createByReal(6.0)

planeInput.setByOffset(prof, offsetValue)

planeTwo = planes.add(planeInput)

 

# Create an object collection for the points.

points = adsk.core.ObjectCollection.create()

 

# Define the points the spline with fit through.

points.add(adsk.core.Point3D.create(0, 0, 0))

points.add(adsk.core.Point3D.create(3, 7, 0))

points.add(adsk.core.Point3D.create(5, 9, 0))

 

# Create the spline.

sketch.sketchCurves.sketchFittedSplines.add(points)

 

offsetValue = adsk.core.ValueInput.createByReal(9.0)

planeInput.setByOffset(prof, offsetValue)

planeThree = planes.add(planeInput)

 

# Create an object collection for the points.

points = adsk.core.ObjectCollection.create()

 

# Define the points the spline with fit through.

points.add(adsk.core.Point3D.create(0, 0, 0))

points.add(adsk.core.Point3D.create(2, 5, 0))

points.add(adsk.core.Point3D.create(3, 8, 0))

 

# Create the spline.

sketch.sketchCurves.sketchFittedSplines.add(points)

 

 

except:

if ui:

ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

*********************

 

fusion360-sketchOnConstructionPlane.png

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

ekinsb
Alumni
Alumni
Accepted solution

Here's a modified version of your program that creates a series of curves on different construction planes and then creates a loft feature through them.  The thing to always start with when you're automating some process like this is to go through the same steps in the user interface and pay careful attention to the steps needed. In your code you were getting the profile from the sketch and using that to create then construction plane.  Profiles represent the closed areas within a sketch that are drawn as filled in.  When drawing a single open curve, there aren't any profiles.  I modified the program to build the construction planes using one of the base construction planes. For open curves you can create a "Path" rather than a profile.  I do that with each curve that's drawn and then finally use those paths to create a loft feature.

 

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
         
        # Create a document.
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
         
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
         
        # Get the root component of the active design
        rootComp = design.rootComponent
         
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)
         
        # Create sketch circle
        sketchArcs = sketch.sketchCurves.sketchArcs
        arc = sketchArcs.addByThreePoints(adsk.core.Point3D.create(0,0,0),
                                          adsk.core.Point3D.create(3,2,0),
                                          adsk.core.Point3D.create(6,0,0))
         
        # Create a path using the arc.
        paths = []
        paths.append(adsk.fusion.Path.create(arc, adsk.fusion.ChainedCurveOptions.noChainedCurves))
         
        # Get construction planes
        planes = rootComp.constructionPlanes
         
        # Create construction plane input
        planeInput = planes.createInput()
         
        # Add construction plane by offset
        offsetValue = adsk.core.ValueInput.createByReal(3.0)
        planeInput.setByOffset(rootComp.xZConstructionPlane, offsetValue)
        constPlane = planes.add(planeInput)
        
        sketch = sketches.add(constPlane)
             
        # Create an object collection for the points.
        points = adsk.core.ObjectCollection.create()
         
        # Define the points the spline with fit through.
        points.add(adsk.core.Point3D.create(0, 0, 0))
        points.add(adsk.core.Point3D.create(5, 1, 0))
        points.add(adsk.core.Point3D.create(6, 4, 0))
         
        # Create the spline.
        curve = sketch.sketchCurves.sketchFittedSplines.add(points)
    
        paths.append(adsk.fusion.Path.create(curve, adsk.fusion.ChainedCurveOptions.noChainedCurves))
    
         
        offsetValue = adsk.core.ValueInput.createByReal(6.0)
        planeInput.setByOffset(rootComp.xZConstructionPlane, offsetValue)
        constPlane = planes.add(planeInput)
    
        sketch = sketches.add(constPlane)
         
        # Create an object collection for the points.
        points = adsk.core.ObjectCollection.create()
         
        # Define the points the spline with fit through.
        points.add(adsk.core.Point3D.create(0, 0, 0))
        points.add(adsk.core.Point3D.create(3, 7, 0))
        points.add(adsk.core.Point3D.create(5, 9, 0))
         
        # Create the spline.
        curve = sketch.sketchCurves.sketchFittedSplines.add(points)
    
        paths.append(adsk.fusion.Path.create(curve, adsk.fusion.ChainedCurveOptions.noChainedCurves))
         
        offsetValue = adsk.core.ValueInput.createByReal(9.0)
        planeInput.setByOffset(rootComp.xZConstructionPlane, offsetValue)
        constPlane = planes.add(planeInput)
    
        sketch = sketches.add(constPlane)
         
        # Create an object collection for the points.
        points = adsk.core.ObjectCollection.create()
         
        # Define the points the spline with fit through.
        points.add(adsk.core.Point3D.create(0, 0, 0))
        points.add(adsk.core.Point3D.create(2, 5, 0))
        points.add(adsk.core.Point3D.create(3, 8, 0))
         
        # Create the spline.
        curve = sketch.sketchCurves.sketchFittedSplines.add(points)
    
        paths.append(adsk.fusion.Path.create(curve, adsk.fusion.ChainedCurveOptions.noChainedCurves))
        
        loftInput = rootComp.features.loftFeatures.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        for path in paths:
            loftInput.loftSections.add(path)
            
        rootComp.features.loftFeatures.add(loftInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you much for the code and explanation - this makes more sense.

 

Additionally, funny you added the loft - I was going to ask a follow up question about doing something similar using tsplines - the question being, how would I go about creating coordinate control points - but what you did does just that!

0 Likes