Hello,
The following sample demos how to change the position of cutting plane and get the volumes of all cells after cutting plane cuts "A" body. The path of csv need be changed if you want to play the sample in your side.
PS: if you want to get the volume of one of cellbodies(e.g. you mentioned "B"), you have to define criteria(e.g. by bounding box of cell body) to filter it out.
Thanks,
Marshal
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
root = design.rootComponent
A = root.bRepBodies.item(0)
plane = root.constructionPlanes.item(0)
tools = adsk.core.ObjectCollection.create()
tools.add(A)
tools.add(plane)
planeposparam = root.modelParameters.itemByName('d5')
planepos = planeposparam.value # 0 deg
# The position of the plan will be changed from 0 to the length of box.
boundaryFills = root.features.boundaryFillFeatures
planeposstep = design.unitsManager.convert(10, 'deg', 'rad') #10 deg
poslimit = design.unitsManager.convert(180, 'deg', 'rad') #180 deg
results = 'PlanePos Cell1 Volume Cell2 Volume Cell3 Volume\n'
while planepos < poslimit:
boundaryFillInput = boundaryFills.createInput(tools, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
resultVolumes = ''
i = 0
for cell in boundaryFillInput.bRepCells:
cell.isSelected = True
body = cell.cellBody
i = i + 1
resultVolumes += '{} {} '.format(i, body.volume)
boundaryFillFeature = boundaryFills.add(boundaryFillInput)
boundaryFillFeature.deleteMe()
boundaryFillInput = None
planepos = planeposparam.value
results += '{} {}\n'.format(design.unitsManager.convert(planepos, 'rad', 'deg'), resultVolumes)
planeposparam.value = planepos + planeposstep
with open('/Users/tum/Downloads/1.csv', 'w') as f:
f.write(results)
ui.messageBox('Ok')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Marshal Tu
Fusion Developer
>