I may not understand correctly.
Do you want this kind of processing?
#Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import os, re
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
def run(context):
try:
global _app, _ui
_app = adsk.core.Application.get()
_ui = _app.userInterface
des :adsk.fusion.Design = _app.activeProduct
root :adsk.fusion.Component = des.rootComponent
showBodies = []
body = adsk.fusion.BRepBody.cast(None)
if root.isBodiesFolderLightBulbOn:
lst = [body for body in root.bRepBodies if body.isLightBulbOn]
if len(lst) > 0:
showBodies.append(['root', lst])
occ = adsk.fusion.Occurrence.cast(None)
for occ in root.allOccurrences:
if not occ.isLightBulbOn: continue
if not occ.component.isBodiesFolderLightBulbOn: continue
lst = [body for body in occ.bRepBodies if body.isLightBulbOn]
if len(lst) > 0:
showBodies.append([occ.name, lst])
# get clone body
tmpBrepMng = adsk.fusion.TemporaryBRepManager.get()
tmpBodies = []
for name,bodies in showBodies:
lst = [tmpBrepMng.copy(body) for body in bodies]
if len(lst) > 0:
tmpBodies.append([name, lst])
# create export Doc - DirectDesign
fusionDocType = adsk.core.DocumentTypes.FusionDesignDocumentType
expDoc :adsk.fusion.FusionDocument = _app.documents.add(fusionDocType)
expDes :adsk.fusion.Design = expDoc.design
expDes.designType = adsk.fusion.DesignTypes.DirectDesignType
# get export rootComponent
expRoot :adsk.fusion.Component = expDes.rootComponent
# paste clone body
mat0 = adsk.core.Matrix3D.create()
for name,bodies in tmpBodies:
occ = expRoot.occurrences.addNewComponent(mat0)
comp = occ.component
comp.name = name
for body in bodies:
comp.bRepBodies.add(body)
# export stl
exportFolder = r'C:\temp'
exportMgr = des.exportManager
for occ in expRoot.allOccurrences:
expName = re.sub(r'[\\|/|:|?|.|"|<|>|\|]', '-', occ.name)
expPath = os.path.join(exportFolder, '{}.stl'.format(expName))
stlOpts = exportMgr.createSTLExportOptions(occ, expPath)
exportMgr.execute(stlOpts)
# remove export Doc
expDoc.close(False)
# finish
_ui.messageBox('Exported the STL file.\n' + exportFolder)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))