@isocam -San.
The execution condition is that the root component must have a sheet metal body.
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.fusion as fusion
import pathlib
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
des: fusion.Design = app.activeProduct
root: fusion.Component = des.rootComponent
# get sheetmetal bodies
sheetBodies = [b for b in root.bRepBodies if b.isSheetMetal]
# get sheetmetal large face
flatFaces = [f for f in sheetBodies[0].faces
if f.geometry.objectType == core.Plane.classType()]
targetFace: fusion.BRepFace = max(flatFaces, key=lambda f: f.area)
# remove flatpattern
flat: fusion.FlatPattern = root.flatPattern
if flat:
flatProd: fusion.FlatPatternProduct = flat.parentComponent.parentDesign
flatProd.deleteMe()
# create flatpattern
flat: fusion.FlatPattern = root.createFlatPattern(targetFace)
# export path
exportPath = str(pathlib.Path("C:/temp") / f"{flat.name}.dxf")
# export dxf
export_dxf(exportPath, flat)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def export_dxf(path: str, flat: fusion.FlatPattern) -> None:
app: core.Application = core.Application.get()
des: fusion.Design = app.activeProduct
expMgr: fusion.ExportManager = des.exportManager
dxfOpt: fusion.DXFFlatPatternExportOptions = expMgr.createDXFFlatPatternExportOptions(
path,
flat,
)
expMgr.execute(dxfOpt)