Looking for ideas to get multiple flat-patterns into one DXF (retaining parametrics)

Looking for ideas to get multiple flat-patterns into one DXF (retaining parametrics)

OceanHydroAU
Collaborator Collaborator
659 Views
3 Replies
Message 1 of 4

Looking for ideas to get multiple flat-patterns into one DXF (retaining parametrics)

OceanHydroAU
Collaborator
Collaborator

Flat patterns export beautifully, and (as far as I can tell) with way more useful info than anything else (e.g. sketches):-

 

A DXF flat-pattern export:-

pic_2024-04-05_22.40.16_487.png

Looks like this on the inside:-

pic_2024-04-05_22.34.55_485.png

Notice all the stuff that the laser cutter needs to know (inner and outer profiles, assorted lines and possible text for etching onto the parts)

 

But if you project and copy/paste from the flat pattern into a sketch, all that gets lost

pic_2024-04-05_22.39.15_486.png

 

Only one single "0" layer shows up in the .dxf file:-

pic_2024-04-05_22.41.05_488.png

 

Can anyone dream up a way (either manual or API) to somehow get more-than-one flatPattern into someplace which can properly export all the layers?

 

This discussion reveals that at least some of that is exposed to the API these days...

 

I'm wondering... since a flat pattern happens to be bodies and so on inside a component itself:-

pic_2024-04-05_22.53.48_489.png

... I wonder if the API would permit us too "copyPasteBodies" on those things to make them all end up in the same place that the existing DXF exporter is reading from ?  [not ideal of course - I want all relationships preserved, so changes to the original reflect properly still... but better than nothing]

 

Other ideas?  Any outside-the-box thoughts?

0 Likes
Accepted solutions (1)
660 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor
Accepted solution

Hi @OceanHydroAU -San.

 

This is a sample script that temporarily exports a flat pattern to DXF and imports it into the root component.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion
import tempfile
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

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

        with tempfile.TemporaryDirectory() as tempDir:
            # temp path
            tmpDxfPath = str(pathlib.Path(tempDir) / "tmp.dxf")

            # export
            expMgr: fusion.ExportManager = des.exportManager
            dxfOpt: fusion.DXFFlatPatternExportOptions = expMgr.createDXFFlatPatternExportOptions(
                tmpDxfPath,
                flatPattern,
            )
            res = expMgr.execute(dxfOpt)

            # import
            impMgr: core.ImportManager = app.importManager
            dxfOpt: core.DXF2DImportOptions = impMgr.createDXF2DImportOptions(
                tmpDxfPath,
                root.xYConstructionPlane,
            )
            dxfOpt.isSingleSketchResult = False
            impMgr.importToTarget2(
                dxfOpt,
                root,
            )

        ui.messageBox("Done", "Flat Pattern Sketch")

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 4

OceanHydroAU
Collaborator
Collaborator

Good thinking @kandennti and thanks for that cool script!

 

I think I'm going to have to give-up on the idea of generating a parametric result - the current API just doesn't expose or support enough to manage multi-layer dxf outputs for now 😞

 

I'll revisit this thread when I'm done, and add anything new I've discovered

Message 4 of 4

BrianEkins
Mentor
Mentor

Sometimes creating parametric geometry isn't worth the effort. It involves keeping track of all the relationships between different objects and then, when one object changes, modifying the dependent objects so they correctly represent the intended result. Sometimes it's easier to delete the results and create it from scratch. The case when it's best to try and preserve existing geometry and update it instead of delete and re-create is when there are downstream operations that reference that geometry. For example, CAM operations. If you delete and re-create the geometry, you lose those relationships. But I've seen cases where people spent much time worrying about parametrics when they wouldn't be used. What's best depends on the case.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes