[Bug] intersectWithSketchPlane method doesn't create closed profiles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I wrote a code that slices a body using the intersectWithSketchPlane method to get sketch profiles.
import adsk.core, adsk.fusion, adsk.cam, traceback
import math
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Slice spacing in cm
sliceSpacing = 0.2
body = ui.selectEntity('Select a body', 'SolidBodies').entity
if body is None:
return
rootComponent = body.parentComponent.parentDesign.rootComponent
bbPointMax = body.boundingBox.maxPoint
bbPointMin = body.boundingBox.minPoint
baseFeats = rootComponent.features.baseFeatures
baseFeat = baseFeats.add()
baseFeat.startEdit()
planes = rootComponent.constructionPlanes
planeInput = planes.createInput()
planeInput.targetBaseOrFormFeature = baseFeat
numSlices = math.floor((bbPointMax.z - bbPointMin.z) / sliceSpacing)
offset = adsk.core.ValueInput.createByReal(bbPointMin.z)
planeInput.setByOffset(rootComponent.xYConstructionPlane, offset)
plane = planes.add(planeInput)
sketches = rootComponent.sketches
msg = ''
for i in range(0, numSlices+1):
vector = adsk.core.Vector3D.create(0.0, 0.0, bbPointMin.z + i * sliceSpacing)
transform = adsk.core.Matrix3D.create()
transform.translation = vector
plane.transform = transform
sketch = sketches.add(plane)
sketch.intersectWithSketchPlane([body])
sketch.name = 'MySketch_{:03d}'.format(i)
sketch.isVisible = False
if sketch.profiles.count == 0:
sketch.isVisible = True
msg += 'MySketch_{:03d} : no profile\n'.format(i)
baseFeat.finishEdit()
if msg:
ui.messageBox(msg)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
It works well except on some geometries like the one attached to this message.
Some intersections don't create closed profiles (forget about the first and the last ones):
MySketch_000 : no profile
MySketch_011 : no profile
MySketch_012 : no profile
MySketch_013 : no profile
MySketch_014 : no profile
MySketch_037 : no profile
MySketch_038 : no profile
MySketch_049 : no profile
Any ideas?
Thank you.
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file