よく見たら、 "ExtractBOM" と言うサンプルスプリクトが有ったので、
体積表示の代わりにサイズを表示させるようにしてみました。
#fusion360 python
import adsk.core, adsk.fusion, traceback
def spacePadRight(value, length):
pad = ''
if type(value) is str:
paddingLength = length - len(value) + 1
else:
paddingLength = length - value + 1
while paddingLength > 0:
pad += ' '
paddingLength -= 1
return str(value) + pad
def walkThrough(bom):
mStr = ''
for item in bom:
mStr += spacePadRight(item['name'], 15) + \
str(spacePadRight(item['instances'], 15)) + \
str(item['size']) + '\n'
return mStr
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
title = 'Extract BOM+'
if not design:
ui.messageBox('No active design', title)
return
root = design.rootComponent
occs = root.allOccurrences
unitsMgr = design.unitsManager
defLenUnit = unitsMgr.defaultLengthUnits
unit = unitsMgr.convert(1, unitsMgr.internalUnits, defLenUnit)
bom = []
for occ in occs:
comp = occ.component
jj = 0
for bomI in bom:
if bomI['component'] == comp:
bomI['instances'] += 1
break
jj += 1
if jj == len(bom):
(x,y,z) = GetCompBodiesSize(comp)
bom.append({
'component': comp,
'name': comp.name,
'instances': 1,
'size': '{:.3f} x {:.3f} x {:.3f}'.format(x*unit,y*unit,z*unit)
})
title = spacePadRight('コンポーネント', 15) + \
spacePadRight('数', 15) + \
spacePadRight('サイズ', 25) + '\n'
msg = title + '\n' + walkThrough(bom)
ui.messageBox(msg, 'コンポーネント サイズ')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def GetCompBodiesSize(comp):
boxes = [bBody.boundingBox
for bBody in comp.bRepBodies if bBody.isLightBulbOn & bBody.isVisible]
if len(boxes) < 1:
return (0,0,0)
maxposs = (max(box.maxPoint.x for box in boxes),
max(box.maxPoint.y for box in boxes),
max(box.maxPoint.z for box in boxes))
minposs = (min(box.minPoint.x for box in boxes),
min(box.minPoint.y for box in boxes),
min(box.minPoint.z for box in boxes))
return (maxposs[0]-minposs[0],
maxposs[1]-minposs[1],
maxposs[2]-minposs[2])

・1個のコンポーネント内に複数ボディがある場合、
全てのボディを含めた状態でのサイズです。
・コンポーネント・ボディが非表示の場合、
サイズは 0 x 0 x 0 となります。
・対象となるボディは、BRepなものだけです。
・単位は、あなたが設定している単位になります。
(アーカイブ自体かも)
・テスト不足です。
これと画像を組み合わせて、Htmlにすれば良さそうな気もしてはいます。
クラウドなCADだと、何処にファイルを書き出すかが悩みどころですが・・・。