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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

My first script - Doesn't seem to work??

Message 1 of 3
106 Views, 2 Replies

My first script - Doesn't seem to work??

Hi all,


Trying to create a simple cube via the following script, buyt all it seems to do is create a line in the sketch that is 1000mm long!


What am I missing?




import adsk.core
import adsk.fusion
import traceback

def create_cube():
app = adsk.core.Application.get()
design = app.activeProduct
root = design.rootComponent

# Define cube dimensions
width = 100 # mm
length = 200 # mm
depth = 25 # mm

# Create a new sketch on the XY plane
sketches = root.sketches
xy_plane = root.xYConstructionPlane
sketch = sketches.add(xy_plane)

# Create a rectangle in the sketch
sketch_lines = sketch.sketchCurves.sketchLines
point1 = adsk.core.Point3D.create(0, 0, 0)
point2 = adsk.core.Point3D.create(width, 0, 0)
point3 = adsk.core.Point3D.create(width, length, 0)
point4 = adsk.core.Point3D.create(0, length, 0)

lines = sketch_lines.addByTwoPoints(point1, point2)
lines.addByTwoPoints(point2, point3)
lines.addByTwoPoints(point3, point4)
lines.addByTwoPoints(point4, point1)

# Create an extrusion feature from the sketch
extrudes = root.features.extrudeFeatures
profile = sketch.profiles.item(0)
extrude_input = extrudes.createInput(profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

# Set the extrusion distance
extrude_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(depth))

extrude = extrudes.add(extrude_input)

except Exception as e:
print('Failed: {}'.format(traceback.format_exc()))



David Harrison
Harrison Classic Boats

Win 10 / I7-11700K @ 4.9GHz / 64Gb RAM / SSD's
Message 2 of 3
in reply to: David_HCB



The line you are creating is 100 cm long (1000 mm), not mm as it is commented out.

I'd suggest reading this article regarding units in Fusion 360:


As per the other lines of the cube base, you have to create them the same way you create the first, it is, with the sketch_lines.addByTwoPoints() method.



Jorge Jaramillo

Software Engineer


Message 3 of 3
in reply to: Jorge_Jaramillo

thanks - I forgot about cm being the base unit for Metric.


Let me sort - thanks again

David Harrison
Harrison Classic Boats

Win 10 / I7-11700K @ 4.9GHz / 64Gb RAM / SSD's

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