#Author-
#Description-
from asyncio import constants
import adsk.core, adsk.fusion, adsk.cam, 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
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
Lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(0, 0, 0)
endPoint = adsk.core.Point3D.create(5, 9, 0)
Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
prof = sketch.profiles.item(0)
# Create an extrusion input.
features = rootComp.features
extrudes = 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.8)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# CUT FRONT
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
Lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(4, 0, 1)
endPoint = adsk.core.Point3D.create(5, 9, 1)
Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
prof2 = sketch.profiles.item(0)
# Create an extrusion input.
features = rootComp.features
extrudes = features.extrudeFeatures
extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
distance = adsk.core.ValueInput.createByReal(5)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# CUT Back
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
Lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(0, 0, 1)
endPoint = adsk.core.Point3D.create(1, 9, 1)
Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
prof2 = sketch.profiles.item(0)
# Create an extrusion input.
features = rootComp.features
extrudes = features.extrudeFeatures
extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
distance = adsk.core.ValueInput.createByReal(5)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# CUT Diagonal
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
Lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(1, 9, 1)
endPoint = adsk.core.Point3D.create(1, 7.0118, 5.8)
Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
prof2 = sketch.profiles.item(0)
# Create an extrusion input.
features = rootComp.features
extrudes = features.extrudeFeatures
extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
distance = adsk.core.ValueInput.createByReal(5)
extInput.setDistanceExtent(False, distance)
#problem here
ext = extrudes.add(extInput)
#problem here
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
Lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(4, 0, 1)
endPoint = adsk.core.Point3D.create(4, 1.9882, 5.8)
Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
prof2 = sketch.profiles.item(0)
# Create an extrusion input.
features = rootComp.features
extrudes = features.extrudeFeatures
extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
distance = adsk.core.ValueInput.createByReal(5)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# CUT Inside
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
Lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(1.7, 0, 2)
endPoint = adsk.core.Point3D.create(3.3, 9, 2)
Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
prof2 = sketch.profiles.item(0)
# Create an extrusion input.
features = rootComp.features
extrudes = features.extrudeFeatures
extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
distance = adsk.core.ValueInput.createByReal(2.7)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# ADD CYLINDER
sketches = rootComp.sketches
sketch = sketches.add(rootComp.yZConstructionPlane)
circles1 = sketch.sketchCurves.sketchCircles
CentPoint = adsk.core.Point3D.create(-4.5, 4.5, 5.5)
oCirc = circles1.addByCenterRadius(CentPoint, 2)
# Get the profile defined by the rectangle.
prof1 = sketch.profiles.item(0)
extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.JoinFeatureOperation)
distance = adsk.core.ValueInput.createByReal(-6)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# CUT CYLINDER
sketches = rootComp.sketches
sketch = sketches.add(rootComp.yZConstructionPlane)
circles1 = sketch.sketchCurves.sketchCircles
CentPoint = adsk.core.Point3D.create(-4.5, 4.5, 5.5)
oCirc = circles1.addByCenterRadius(CentPoint, 1)
# Get the profile defined by the rectangle.
prof1 = sketch.profiles.item(0)
extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)
distance = adsk.core.ValueInput.createByReal(-6)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# CUT Top
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
Lines = sketch.sketchCurves.sketchLines
startPoint = adsk.core.Point3D.create(0.4, 1.5, 5.8)
endPoint = adsk.core.Point3D.create(4.6, 7.5, 5.8)
Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
prof2 = sketch.profiles.item(0)
# Create an extrusion input.
features = rootComp.features
extrudes = features.extrudeFeatures
extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
distance = adsk.core.ValueInput.createByReal(2.7)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))