
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()))
*********************
Solved! Go to Solution.