I am trying to split a model into sections of 1cm along one axis(lets say Y-axis)
The model is about 700cm high, so there will be 699 sections. I want to read out the volume of each of theese "slices". So if there is a way that doesnt involve splitting the body, I am all ears.
I can do it using the API, but the time it takes is extreme. (10 minutes)
Are there any better(read:faster) way than making an offset plane, using it as a splitting tool and splitting the body.?
I cant seem to find a way to get the split-feature to accept multiple inputs, i think that is part of the problem, because the timeline gets filled with plane-fetures and split-features. I have also tried to model a continuous line that covers the model in a back-and-forth kind of way, but no luck.
Any thoughts ?
Thanks.
Andreas
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
Think of it as an idea.
I found the analyzeInterference method to be very fast when I tried it here before.
You may want to try creating a box as the tools of the split in advance and check for interference.
Hi Mr. Andreas.Pedersen8EDUH,
Consider implementing the splitting process in the domain of TemporaryBRepManager.
It should run much faster. The F360 docs contain some examples of HOW TO DO IT.
Regards
MichaelT
I wrote this add-in a few years ago and it might be close to what you're looking for.
https://ekinssolutions.com/sliceitup/
Thanks for your reply! I will look into this, but as I understand, it will still require 700 tool-boxes ?
-Andreas
Thank you for your suggestion, I will look into this, as this may be what I need for reducing the time.
_Andreas
Thank you for your contribution. Looks nice. If I cant fix my script, I will look into your plugin.
-Andreas
>it will still require 700 tool-boxes ?
Yes, it is.
I'd like to try it out and compare, but I'm busy with work and don't have the time.
We created a sample to compare.
I didn't know how to do the splitting using TemporaryBRepManager, so I used the booleanOperation method.
The result of my test was that TemporaryBRepManager was faster to process.
I feel that the reason for the slowness is the fact that Component.bRepBodies.add needs to be done twice when using the analyzeInterference method.
# Fusion360API Python script
import traceback
import adsk.fusion
import adsk.core
import time
def run(context):
ui = adsk.core.UserInterface.cast(None)
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
des: adsk.fusion.Design = app.activeProduct
msg: str = 'Select Solid Body'
selFiltter: str = 'SolidBodies'
sel: adsk.core.Selection = selectEnt(msg, selFiltter)
if not sel:
return
targetBody:adsk.fusion.BRepBody = sel.entity
des.designType = adsk.fusion.DesignTypes.ParametricDesignType
# start test
app.log(' -- test start --')
t = time.time()
# Please switch between test1 and test2 to execute.
test1(targetBody) # Design.analyzeInterference
# test2(targetBody) # TemporaryBRepManager.booleanOperation
app.log(f'done: {time.time() - t} s')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def selectEnt(
msg: str,
filterStr: str) -> adsk.core.Selection:
try:
app = adsk.core.Application.get()
ui = app.userInterface
sel = ui.selectEntity(msg, filterStr)
return sel
except:
return None
# TemporaryBRepManager.booleanOperation Method
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-F845AD0E-D25F-4FDD-B31B-3E6DFC5A8A9B
def test2(
targetBody: adsk.fusion.BRepBody,
step: float = 1):
app: adsk.core.Application = adsk.core.Application.get()
measMgr: adsk.core.MeasureManager = app.measureManager
oriBBox: adsk.core.OrientedBoundingBox3D = measMgr.getOrientedBoundingBox(
targetBody,
adsk.core.Vector3D.create(1, 0, 0),
adsk.core.Vector3D.create(0, 1, 0),
)
minZ = oriBBox.centerPoint.z - oriBBox.height * 0.5
halfStep = step * 0.5
count = int((oriBBox.height // step) + 1)
baseBBox: adsk.core.OrientedBoundingBox3D = oriBBox.copy()
baseBBox.centerPoint = adsk.core.Point3D.create(
oriBBox.centerPoint.x,
oriBBox.centerPoint.y,
minZ + halfStep
)
baseBBox.height = step
tempMgr: adsk.fusion.TemporaryBRepManager = adsk.fusion.TemporaryBRepManager.get()
tempBodies = []
for idx in range(count):
bBox: adsk.core.OrientedBoundingBox3D = baseBBox.copy()
pnt: adsk.core.Point3D = bBox.centerPoint.copy()
pnt.z = minZ + halfStep + (step * idx)
bBox.centerPoint = pnt
tempBodies.append(tempMgr.createBox(bBox))
# -- Same process until this part --
resBodies = []
for tempBody in tempBodies:
clone: adsk.fusion.BRepBody = tempMgr.copy(targetBody)
tempMgr.booleanOperation(
clone,
tempBody,
adsk.fusion.BooleanTypes.IntersectionBooleanType
)
resBodies.append(clone)
comp: adsk.fusion.Component = targetBody.parentComponent
bodies: adsk.fusion.BRepBodies = comp.bRepBodies
resBaseFeat: adsk.fusion.BaseFeature = comp.features.baseFeatures.add()
resBaseFeat.startEdit()
try:
for body in resBodies:
bodies.add(
body,
resBaseFeat
)
except:
pass
finally:
resBaseFeat.finishEdit()
app.log(f' bodies count: {resBaseFeat.bodies.count}')
# Design.analyzeInterference Method
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7B17A057-49A7-4332-ACD1-F6FA4EA84C88
def test1(
targetBody: adsk.fusion.BRepBody,
step: float = 1):
app: adsk.core.Application = adsk.core.Application.get()
measMgr: adsk.core.MeasureManager = app.measureManager
oriBBox: adsk.core.OrientedBoundingBox3D = measMgr.getOrientedBoundingBox(
targetBody,
adsk.core.Vector3D.create(1, 0, 0),
adsk.core.Vector3D.create(0, 1, 0),
)
minZ = oriBBox.centerPoint.z - oriBBox.height * 0.5
halfStep = step * 0.5
count = int((oriBBox.height // step) + 1)
baseBBox: adsk.core.OrientedBoundingBox3D = oriBBox.copy()
baseBBox.centerPoint = adsk.core.Point3D.create(
oriBBox.centerPoint.x,
oriBBox.centerPoint.y,
minZ + halfStep
)
baseBBox.height = step
tempMgr: adsk.fusion.TemporaryBRepManager = adsk.fusion.TemporaryBRepManager.get()
tempBodies = []
for idx in range(count):
bBox: adsk.core.OrientedBoundingBox3D = baseBBox.copy()
pnt: adsk.core.Point3D = bBox.centerPoint.copy()
pnt.z = minZ + halfStep + (step * idx)
bBox.centerPoint = pnt
tempBodies.append(tempMgr.createBox(bBox))
# -- Same process until this part --
comp: adsk.fusion.Component = targetBody.parentComponent
bodies: adsk.fusion.BRepBodies = comp.bRepBodies
bodyObjs: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
bodyObjs.add(targetBody)
toolBaseFeat: adsk.fusion.BaseFeature = comp.features.baseFeatures.add()
toolBaseFeat.startEdit()
try:
for body in tempBodies:
bodyObjs.add(
bodies.add(
body,
toolBaseFeat
)
)
except:
pass
finally:
toolBaseFeat.finishEdit()
des: adsk.fusion.Design = app.activeProduct
interferanceResults: adsk.fusion.InterferenceResults = des.analyzeInterference(
des.createInterferenceInput(bodyObjs)
)
interBodies = []
res: adsk.fusion.InterferenceResult
for res in interferanceResults:
interBodies.append(res.interferenceBody)
resBaseFeat: adsk.fusion.BaseFeature = comp.features.baseFeatures.add()
resBaseFeat.startEdit()
try:
for body in interBodies:
bodies.add(
body,
resBaseFeat
)
except:
pass
finally:
resBaseFeat.finishEdit()
# resBaseFeat.bodies.count <- 0
app.log(f' bodies count: {len(interBodies)}')
toolBaseFeat.deleteMe()
WOW! That was lightning fast compared to my code!
It went from 221 seconds to 10.5 seconds!
I dont need the resulting bodies, just the volumes, best thing is if there is no change on the original model.
Edited your code to not add the resulting bodies, just collectiong their volumes, and the execution time went down to 5.9 seconds! That is very acceptable for me!
Thank you,@kandennti so much!
-Andreas