box_with_rounded_corners.py•2.12 kB
"""
Example: Box with Rounded Corners
This script demonstrates how to create a box with rounded corners in Fusion 360.
It was generated by the Fusion 360 MCP Server.
To run this script in Fusion 360:
1. Open Fusion 360
2. Click on the "Scripts and Add-Ins" button in the toolbar
3. Click the "+" button to add a new script
4. Select this file
5. Click "Run"
"""
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
# Get the active component in the design
component = design.rootComponent
# Create a new sketch on the xy plane
sketches = component.sketches
xyPlane = component.xYConstructionPlane
sketch = sketches.add(xyPlane)
# Draw a rectangle
rectangle = sketch.sketchCurves.sketchLines.addTwoPointRectangle(
adsk.core.Point3D.create(0, 0, 0),
adsk.core.Point3D.create(10, 10, 0)
)
# Extrude the profile
prof = sketch.profiles.item(0)
extrudes = component.features.extrudeFeatures
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(5)
extInput.setDistanceExtent(False, distance)
extrude = extrudes.add(extInput)
# Fillet edges
fillets = component.features.filletFeatures
edgeCollection = adsk.core.ObjectCollection.create()
body = component.bRepBodies.item(0)
for edge in body.edges:
edgeCollection.add(edge)
filletInput = fillets.createInput()
filletInput.addConstantRadiusEdgeSet(edgeCollection, adsk.core.ValueInput.createByReal(0.5), True)
fillet = fillets.add(filletInput)
ui.messageBox('Box with rounded corners created successfully')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))