Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying my first script in Fusion.
To help me, I asked Chat GPT to write the script, but it looks that it miss something.
Here is what I want to do:
I have a design with some named Sketches.
for each of this sketch, I wnat to generate a new component with a extrusion ot this sketch.
And name the component with the name of the sketch.
could someone help me to correct this script?
################################
#Author-
#Description-
import adsk.core, adsk.fusion, traceback
def run(context😞
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Get the active design
design = app.activeProduct
# Get the root component of the active design
root_comp = design.rootComponent
# Get the sketches in the design
sketches = root_comp.sketches
# Iterate through each sketch
for sketch in sketches:
# Create a new component for each sketch
new_comp = root_comp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
# Extrude the sketch
extrudes = new_comp.component.features.extrudeFeatures
ext_input = extrudes.createInput(sketch.profiles.item(0), adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(5)
ext_input.setDistanceExtent(False, distance)
extrudes.add(ext_input)
# Name the component with the sketch name
new_comp.name = sketch.name
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#########################Solved! Go to Solution.