Created
October 14, 2020 03:01
-
-
Save raihanba13/6e180fdd75e9fc44336373b1c4cadfc0 to your computer and use it in GitHub Desktop.
Script to demonstrate basic use of Autodesk Fusion 360 API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import adsk.core, adsk.fusion, adsk.cam, traceback | |
def run(context): | |
ui = None | |
try: | |
app = adsk.core.Application.get() | |
ui = app.userInterface | |
# we create a blank new document | |
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType) | |
design = app.activeProduct | |
# Get the root component of the active design. | |
rootComp = design.rootComponent | |
# Create a new sketch1 on the xy plane. | |
sketches = rootComp.sketches; | |
xyPlane = rootComp.xYConstructionPlane | |
sketch1 = sketches.add(xyPlane) | |
lines = sketch1.sketchCurves.sketchLines | |
recLines = lines.addTwoPointRectangle(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(12, 6,0)) | |
# add Constraints | |
sketch1.geometricConstraints.addHorizontal(recLines.item(0)) | |
sketch1.geometricConstraints.addHorizontal(recLines.item(2)) | |
sketch1.geometricConstraints.addVertical(recLines.item(1)) | |
sketch1.geometricConstraints.addVertical(recLines.item(3)) | |
# Get profile of the sketch | |
prof = sketch1.profiles.item(0) | |
extrudes = rootComp.features.extrudeFeatures | |
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) | |
# Define that the extent is a distance extent of 5 cm. | |
distance = adsk.core.ValueInput.createByReal(5) | |
extrude1 = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) | |
# Get the body of the extrusion | |
body1 = extrude1.bodies.item(0) | |
body1.name = "distance, from profile" | |
# Create a collection of entities for shell | |
entities1 = adsk.core.ObjectCollection.create() | |
entities1.add(extrude1.endFaces.item(0)) | |
# Create a shell feature | |
shellFeats = rootComp.features.shellFeatures | |
isTangentChain = False | |
shellFeatureInput = shellFeats.createInput(entities1, isTangentChain) | |
thickness = adsk.core.ValueInput.createByReal(.5) | |
shellFeatureInput.insideThickness = thickness | |
shellFeats.add(shellFeatureInput) | |
except: | |
if ui: | |
ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment