Getting Started with Fusion 360s API Brian Ekins

Getting Started with Fusion 360’s API Brian Ekins Fusion 360 API Designer

Key learning objectives § Know about scripts and add-ins § Have a basic understanding of the Object Model § Know the capabilities and limitations of the Fusion 360 API § Know how to use the tools to write, run, and debug programs § Know how to access and use the API documentation

Legacy Python API

New Fusion API § API preview introduced in September 2014 release § September release supported Javascripts § November release added support for Python scripts § March release added support for add-ins § Future release will support C++

New Fusion API § Multiple languages but a single API § Initial API design is language agnostic § Wrappers get created for each language § Uses hierarchical object model to structure the API § Objects – Represent Fusion objects and API specific objects § Object model shows ownership, not inheritance § Collections – Provide access to a set of related objects and support creating new objects.

API Object Model

Create an Extrusion app = adsk. core. Application. get() design = app. active. Product # Get the root component of the active design. root. Comp = design. root. Component # Create a new sketch on the xy plane. sketch = root. Comp. sketches. add(root. Comp. x. YConstruction. Plane) # Draw a circles = sketch. Curves. sketch. Circles circle 1 = circles. add. By. Center. Radius(adsk. core. Point 3 D. create(0, 0, 0), 2) # Get the profile defined by the circle. prof = sketch. profiles. item(0) # Create an extrusion input to be able to define the input needed for an extrusion # while specifying the profile and that a new component is to be created extrudes = root. Comp. features. extrude. Features ext. Input = extrudes. create. Input(prof, adsk. fusion. Feature. Operations. New. Component. Feature. Operation) # Define that the extent is a distance extent of 5 cm. ext. Input. set. Distance. Extent(False, adsk. core. Value. Input. create. By. Real(5)) # Create the extrusion. ext = extrudes. add(ext. Input)

What Can I Do With the API? § Most of what you can do manually in the UI. § Example

Current Functionality in green (as of March release) § Features and timeline § Sketches § Construction geometry § Parameters § Materials § Appearances § Basic A 360 access

Current Functionality (as of March release) § § § Assembly structure (Components and Occurrences) B-Rep and geometry query (including mesh extraction) User Preferences Camera related functionality Commands and UI access Add-Ins

Future Functionality § § § § C++ Support Assembly Joints and other assembly functionality Remaining features T-Splines Custom graphics Drawings CAM And much more…

Choosing a Language § Java. Script § Used as a general-purpose language § Cannot use html for GUI § No built-in file system access § Use any text editor to write (Brackets comes with Fusion) § Debugging is done in Chrome or Webkit browser § Runs out-of-process in its own invisible browser instance § Can use external Java. Script libraries

Choosing a Language § Python § § § Runs in-process to Fusion in its own Python interpreter Faster than Java. Script (275 x, 23 x) Full access to the file system Can use any editor to edit (Spyder comes with Fusion) Uses Spyder for debugging Python comes with Tkinter for GUI development (doesn’t work on Mac) § Can use other Python libraries

Script Example (Javascript) var app = adsk. core. Application. get(); var design = app. active. Product; // Get the root component of the active design. var root. Comp = design. root. Component; // Create a new sketch on the xy plane. var sketches = root. Comp. sketches; var xy. Plane = root. Comp. x. YConstruction. Plane; var sketch = sketches. add(xy. Plane); // Draw a circle. var circles = sketch. Curves. sketch. Circles; var circle 1 = circles. add. By. Center. Radius(adsk. core. Point 3 D. create(0, 0, 0), 2); // Constrain the circle size. sketch. Dimensions. add. Diameter. Dimension(circle 1, adsk. core. Point 3 D. create(3, 3, 0));

Script Example (Python) app = adsk. core. Application. get() design = app. active. Product # Get the root component of the active design. root. Comp = design. root. Component # Create a new sketch on the xy plane. sketches = root. Comp. sketches xy. Plane = root. Comp. x. YConstruction. Plane sketch = sketches. add(xy. Plane) # Draw a circles = sketch. Curves. sketch. Circles circle 1 = circles. add. By. Center. Radius(adsk. core. Point 3 D. create(0, 0, 0), 2) # Constrain the circle size. sketch. Dimensions. add. Diameter. Dimension(circle 1, adsk. core. Point 3 D. create(3, 3, 0))

Scripts vs. Add-Ins § Scripts are usually “run and done”. § Add-Ins usually run at startup and remain running. § Add-Ins require an additional manifest file. § Fusion expects certain functions to be implemented. § Scripts can optionally use a manifest and implement the same functions.

Scripts and Add-Ins § Access existing Scripts and Add. Ins § Run scripts § Start add-ins § Create new scripts and add-ins § Edit existing scripts and add-ins § Debug scripts and add-ins § Easy access to many samples

Fusion Commands § Can be used by scripts and add-ins § Fusion has well-defined concept of a “command”. § Command definition defines the information needed to create a button. § Command is created when user clicks the command button. § Can create command inputs which results in a dialog. § Can validate input as user interacts with the inputs. § Can show a preview of the result. § Transactions (Undo) are automatically handled.

Documentation

Fusion 360 API Forum

Getting Started With the API § Install Fusion 360 (fusion 360. autodesk. com) § Use Fusion § Look at the API documentation § Run and look at the sample programs § Use the API Forum § Let us know what you need

Autodesk is a registered trademark of Autodesk, Inc. , and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2013 Autodesk, Inc. All rights reserved.
- Slides: 22