offset and extrude code

offset and extrude code

Anonymous
Not applicable
1,115 Views
1 Reply
Message 1 of 2

offset and extrude code

Anonymous
Not applicable

I'm still new to scripting and python but i have the basic understanding, but iv been struggling to offset and/or extrude a sketch. iv tried sample codes but cant quite understand what to change to suit the fact that i want to change a existing sketch

 

can anyone help me with links, code downloads, recommendations, tips, etc

 

this is all i have been able to get working currently in python:

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

# Get extrude features
extrudes = rootComp.features.extrudeFeatures

# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xZConstructionPlane)
sketchCircles = sketch.sketchCurves.sketchCircles
centerPoint = adsk.core.Point3D.create(0, 0, 0)
circle = sketchCircles.addByCenterRadius(centerPoint, 5.0)

# Get the profile defined by the circle
prof = sketch.profiles.item(0)

# Create another sketch
sketchVertical = sketches.add(rootComp.yZConstructionPlane)
sketchCirclesVertical = sketchVertical.sketchCurves.sketchCircles
centerPointVertical = adsk.core.Point3D.create(0, 1, 0)
cicleVertical = sketchCirclesVertical.addByCenterRadius(centerPointVertical, 0.5)

# Get the profile defined by the vertical circle
profVertical = sketchVertical.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)
extrude1 = extrudes.addSimple(prof, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
# Get the extrusion body
body1 = extrude1.bodies.item(0)
body1.name = "simple"

# Get the state of the extrusion
health = extrude1.healthState
if health == adsk.fusion.FeatureHealthStates.WarningFeatureHealthState or health == adsk.fusion.FeatureHealthStates.ErrorFeatureHealthState:
message = extrude1.errorOrWarningMessage

# Get the state of timeline object
timeline = design.timeline
timelineObj = timeline.item(timeline.count - 1);
health = timelineObj.healthState
message = timelineObj.errorOrWarningMessage
except:
if ui:
ui.messa

 

Tristan

0 Likes
Accepted solutions (1)
1,116 Views
1 Reply
Reply (1)
Message 2 of 2

goyals
Autodesk
Autodesk
Accepted solution

This is some related post showing how to edit a sketch. It also shows how to select an existing sketch but you can ignore it. https://forums.autodesk.com/t5/fusion-360-api-and-scripts/how-do-i-select-a-sketch-and-edit-it-how-d...



Shyam Goyal
Sr. Software Dev. Manager
0 Likes