Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to create a randomly generated milling part, but it is still in the basic stage. First step is creatting a entity (cuboid), the second step is to randomly dig holes on the surface or stretch a new small body of the first solid 20 times.
1. After digging a hole in a bRep face of cuboid, cant use it again to dig another hole
2. If cant get the same bRep face after digging a hole, how can i transfer bRepface to constructionPlane.
import adsk.fusion, adsk.cam, random, math, adsk.core, os, traceback
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
design = adsk.fusion.Design.cast(app.activeProduct)
rootComp = design.rootComponent
x0 = random.uniform(10, 20)
y0 = random.uniform(20, 10)
L = random.uniform(10, 20)
rectanglePlan = random.randint(0,2)
sketch = rootComp.sketches.add(rootComp.xZConstructionPlane)
lines = sketch.sketchCurves.sketchLines
recLines = lines.addTwoPointRectangle(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(x0, y0, 0))
prof = sketch.profiles.item(0)
extrudes = rootComp.features.extrudeFeatures
distance_1 = adsk.core.ValueInput.createByReal(L)
extrudeInput = extrudes.addSimple(prof, distance_1, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
body_1 =extrudeInput.bodies.item(0)
faces = body_1.faces
selectedFace=[faces.item(0),faces.item(1),faces.item(2),faces.item(3),faces.item(4),faces.item(5)]
for i in range(6):
x1 = random.uniform(-x0, x0)
y1 = random.uniform(-y0, y0)
planeInput = rootComp.constructionPlanes.createInput()
planeInput.setByOffset(selectedFace[i-1], adsk.core.ValueInput.createByReal(0))
newPlane = rootComp.constructionPlanes.add(planeInput)
sketch2 = rootComp.sketches.add(newPlane)
lines = sketch2.sketchCurves.sketchLines
recLines = lines.addTwoPointRectangle(adsk.core.Point3D.create(x1, y1, 0), adsk.core.Point3D.create(x1/5, y1/5, 0))
prof:adsk.fusion.Profile = sketch2.profiles.item(0)
extrudes = rootComp.features.extrudeFeatures
distance_2 = adsk.core.ValueInput.createByReal(3)
distance_Cut = adsk.core.ValueInput.createByReal(-3)
extrudeInput = extrudes.addSimple(prof, distance_Cut, adsk.fusion.FeatureOperations.CutFeatureOperation)
Solved! Go to Solution.