Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i am making a model with code and i want to crop the model in a circle and for this used tool Circular pattern but I get an error, can you tell me what I did wrong?
and by the way, for clarity, I will leave a photo on the left of how the model should look, and on the right, how it looks now
here is the code
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, math, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
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 sketch on the yz plane.
sketches = rootComp.sketches;
zyPlane = rootComp.xYConstructionPlane
sketch = sketches.add(zyPlane)
lines = sketch.sketchCurves.sketchLines;
line1 = lines.addByTwoPoints(adsk.core.Point3D.create(0, 0.041, 1.27), adsk.core.Point3D.create(0, 0.53, 1.27))
line2 = lines.addByTwoPoints(line1.endSketchPoint, adsk.core.Point3D.create(0, 0.478, 1.3))
line3 = lines.addByTwoPoints(line2.endSketchPoint, adsk.core.Point3D.create(0, 0.34, 1.3))
line4 = lines.addByTwoPoints(line3.endSketchPoint, adsk.core.Point3D.create(0, 0.2622, 1.3778))
line5 = lines.addByTwoPoints(line4.endSketchPoint, adsk.core.Point3D.create(0, 0.2622, 1.6878))
line6 = lines.addByTwoPoints(line5.endSketchPoint, adsk.core.Point3D.create(0, 0.0622, 1.6878))
line7 = lines.addByTwoPoints(line6.endSketchPoint, adsk.core.Point3D.create(0, 0.0622, 1.4578))
line8 = lines.addByTwoPoints(line7.endSketchPoint, adsk.core.Point3D.create(0, 0.041, 1.4366))
line9 = lines.addByTwoPoints(line8.endSketchPoint, adsk.core.Point3D.create(0, 0.041, 1.27))
# Draw a line to use as the axis of revolution.
lines = sketch.sketchCurves.sketchLines
axisLine = lines.addByTwoPoints(adsk.core.Point3D.create(0, 0.041, 0), adsk.core.Point3D.create(0, 0.53, 0))
# Get the profile defined by the model.
prof = sketch.profiles.item(0)
# Create an revolution input to be able to define the input needed for a revolution
# while specifying the profile and that a new component is to be created
revolves = rootComp.features.revolveFeatures
revInput = revolves.createInput(prof, axisLine, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
# Define that the extent is an angle of pi to get half of a torus.
angle = adsk.core.ValueInput.createByReal(2*math.pi)
revInput.setAngleExtent(False, angle)
# Create the extrusion.
ext = revolves.add(revInput)
# CUT CYLINDER
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xZConstructionPlane)
circles1 = sketch.sketchCurves.sketchCircles
CentPoint = adsk.core.Point3D.create(0, 1.548, 0.0622)
oCirc = circles1.addByCenterRadius(CentPoint, 0.09)
# Get the profile defined by the rectangle.
features = rootComp.features
extrudes = features.extrudeFeatures
prof1 = sketch.profiles.item(0)
extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)
distance = adsk.core.ValueInput.createByReal(1.4)
extInput.setDistanceExtent(False, distance)
ext = extrudes.add(extInput)
# Create input entities for circular pattern
inputEntites = adsk.core.ObjectCollection.create()
inputEntites.add(prof1)
# Get Y axis for circular pattern
yAxis = rootComp.yConstructionAxis
# Create the input for circular pattern
circularFeats = rootComp.features.circularPatternFeatures
circularFeatInput = circularFeats.createInput(inputEntites, yAxis)
# Set the quantity of the elements
circularFeatInput.quantity = adsk.core.ValueInput.createByReal(12)
# Set the angle of the circular pattern
circularFeatInput.totalAngle = adsk.core.ValueInput.createByString('360 deg')
# Set symmetry of the circular pattern
circularFeatInput.isSymmetric = False
# Create the circular pattern
circularFeat = circularFeats.add(circularFeatInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.