Creative solution for bounding box of flat pattern

Creative solution for bounding box of flat pattern

Anonymous
Not applicable
491 Views
2 Replies
Message 1 of 3

Creative solution for bounding box of flat pattern

Anonymous
Not applicable

Hello all,

 

It seems that sheet metal is not included in the api. Quite a bummer, as I'm working on an add-in that generates a BOM: It would mean that it is impossible to get the dimensions of a sheet, as you can only retrieve the bounding box of the folded body, not of the unfolded body.

 

But as I've been surprised several times by the creativity of some of the community members here, I thought that I should ask here before I give up. Does anyone have a suggestion on how to retrieve the bounding box of a flat pattern? Maybe trough usage of ui commands?

 

Thanks!

492 Views
2 Replies
Replies (2)
Message 2 of 3

OceanHydroAU
Collaborator
Collaborator
0 Likes
Message 3 of 3

kandennti
Mentor
Mentor

Hi @Anonymous -San.

 

Flat patterns also have 3D data when flattened.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-AA00DEBE-61BB-4FF1-AE0D-EDF71A82C183 

 

It can be obtained from the BoundingBox of this Body.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

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

        flatPattern: fusion.FlatPattern = root.flatPattern
        if not flatPattern:
            ui.messageBox("No flat pattern")
            return

        flatBody: fusion.BRepBody = flatPattern.flatBody
        bBox: core.BoundingBox3D = flatBody.preciseBoundingBox
        flatSize = [
            abs(bBox.maxPoint.x - bBox.minPoint.x),
            abs(bBox.maxPoint.y - bBox.minPoint.y),
            abs(bBox.maxPoint.z - bBox.minPoint.z),
        ]

        unitsMgr: core.UnitsManager = des.unitsManager
        flatSizeStr = [unitsMgr.formatValue(v) for v in flatSize]

        ui.messageBox(" x ".join(flatSizeStr), "Flat Pattern Size")

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Since this Body can also be exported, we have created this add-in and published it.

https://github.com/kantoku-code/Fusion360_BLACKSMITH 

0 Likes