In the past, when creating the extrude feature, we will need to create an ExtrudeInput firstly, then add the extrude feature with the input. The input is like a definition of the feature, with which, some parameters of the feature can be defined. One of the benefits is the ExtrudeFeatures.Add method would not be changed for long term. When any new parameter of creating feature is appended, the API specifies can only add more properties withExtrudeInput.
However, quoted from the latest news of Fusion 360 API: With the recent changes to the Extrude feature the API to create extrusions got quite a bit more complicated. However, we recognized that even though the feature is more powerful and provides a lot more capabilities, the majority of the time people still create simple finite extrusions. To make this more common workflow easier, we've added a new addSimple. method to the ExtrudeFeatures collection. This makes creating an extrusion much simpler than it ever was before with a single API call.
So, you could decide to use the previous way or the simple way based on your requirement. The following is a code snippets from the API sample on the two scenarios.
Python
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
#crreate 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
# Get extrude features
extrudes = rootComp.features.extrudeFeatures
# create a sketch
sketches = rootComp.sketches
sketch1 = sketches.add(rootComp.xZConstructionPlane)
sketchCircles = sketch1.sketchCurves.sketchCircles
centerPoint = adsk.core.Point3D.create(0, 0, 0)
sketchCircles.addByCenterRadius(centerPoint, 3.0)
# Get the profile defined by the circle.
prof_simple = sketch1.profiles.item(0)
# Extrude Sample 1: A simple way of creating typical extrusions (extrusion that goes from the profile plane the specified distance).
# Define a distance extent of 5 cm
distance = adsk.core.ValueInput.createByReal(5)
extrude_simple = extrudes.addSimple(prof_simple, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
# Get the extrusion body
body_simple = extrude_simple.bodies.item(0)
body_simple.name = "simple extrude feature"
#Create another sketch
sketch2 = sketches.add(rootComp.xZConstructionPlane)
sketchCircles2 = sketch2.sketchCurves.sketchCircles
sketchCircles2.addByCenterRadius(centerPoint, 13.0)
sketchCircles2.addByCenterRadius(centerPoint, 15.0)
prof_for_input = sketch2.profiles.item(1)
# Create taper angle value inputs
deg0 = adsk.core.ValueInput.createByString('0 deg')
deg2 = adsk.core.ValueInput.createByString('2 deg')
deg5 = adsk.core.ValueInput.createByString('5 deg')
#Create distance value inputs
mm10 = adsk.core.ValueInput.createByString('10 mm')
mm100 = adsk.core.ValueInput.createByString('100 mm')
# Extrude Sample 2: Create an extrusion that goes from the profile plane with one side distance extent
extrudeInput = extrudes.createInput(prof_for_input, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
# Create a distance extent definition
extent_distance = adsk.fusion.DistanceExtentDefinition.create(mm100)
extrudeInput.setOneSideExtent(extent_distance, adsk.fusion.ExtentDirections.PositiveExtentDirection)
# Create the extrusion
extrude_by_input = extrudes.add(extrudeInput)
# Get the body of extrusion
body_by_input = extrude_by_input.bodies.item(0)
body_by_input.name = "extrude feature by input"
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
JavaScript
function run(context) {
"use strict";
if (adsk.debug === true) {
/*jslint debug: true*/
debugger;
/*jslint debug: false*/
}
var ui;
try {
var app = adsk.core.Application.get();
ui = app.userInterface;
// Create a document.
var doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType);
var product = app.activeProduct;
var design = adsk.fusion.Design(product);
// Get the root component of the active design
var rootComp = design.rootComponent;
// Get extrude features
var extrudes = rootComp.features.extrudeFeatures;
// Create sketch
var sketches = rootComp.sketches;
var sketch1 = sketches.add(rootComp.xZConstructionPlane);
var sketchCircles = sketch1.sketchCurves.sketchCircles;
var centerPoint = adsk.core.Point3D.create(0, 0, 0);
var circle = sketchCircles.addByCenterRadius(centerPoint, 5.0);
// Get the profile defined by the circle
var prof_simple = sketch1.profiles.item(0);
// Extrude Sample 1: A simple way of creating typical extrusions (extrusion that goes from the profile plane the specified distance).
// Define a distance extent of 5 cm
var distance = adsk.core.ValueInput.createByReal(5);
var extrude_simple = extrudes.addSimple(prof_simple, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation);
// Get the extrusion body
var body_simple = extrude_simple.bodies.item(0);
body_simple.name = "simple extrude feature";
// Create another sketch
var sketch2 = sketches.add(rootComp.xZConstructionPlane);
var sketchCircles2 = sketch2.sketchCurves.sketchCircles;
sketchCircles2.addByCenterRadius(centerPoint, 13.0);
sketchCircles2.addByCenterRadius(centerPoint, 15.0);
var prof_for_input = sketch2.profiles.item(1);
// Create taper angle value inputs
var deg0 = adsk.core.ValueInput.createByString('0 deg');
var deg2 = adsk.core.ValueInput.createByString('2 deg');
var deg5 = adsk.core.ValueInput.createByString('5 deg');
// Create distance value inputs
var mm10 = adsk.core.ValueInput.createByString('10 mm');
var mm100 = adsk.core.ValueInput.createByString('100 mm');
// Extrude Sample 2: Create an extrusion that goes from the profile plane with one side distance extent
var extrudeInput = extrudes.createInput(prof_for_input, adsk.fusion.FeatureOperations.NewBodyFeatureOperation);
// Create a distance extent definition
var extent_distance = adsk.fusion.DistanceExtentDefinition.create(mm100);
extrudeInput.setOneSideExtent(extent_distance, adsk.fusion.ExtentDirections.PositiveExtentDirection);
// Create the extrusion
var extrude_by_input = extrudes.add(extrudeInput);
// Get the body of extrusion
var body_by_input = extrude_by_input.bodies.item(0);
body_by_input.name = "extrude feature by input";
}
catch (e) {
if (ui) {
ui.messageBox('Failed : ' + (e.description ? e.description : e));
}
}
adsk.terminate();
}