Insert Design into current Design

Insert Design into current Design

Jonschke
Participant Participant
935 Views
2 Replies
Message 1 of 3

Insert Design into current Design

Jonschke
Participant
Participant

Hey,

i´m new to the Fusion 360 Scripting interface and i dug through the objecttree but i couldnt find a method to insert a design into the current document. In the screenshot you can see what i want to accomplish with the scripting interface.

0 Likes
936 Views
2 Replies
Replies (2)
Message 2 of 3

Jonschke
Participant
Participant
0 Likes
Message 3 of 3

ekinsb
Alumni
Alumni

Here's a smaller, simpler script that demonstrates the process.  It's essentially the same as in the UI; you need to find the specific file on A360 by going to the project, and any subfolders, and then insert it into the active design.  The active design must have been saved at some point or the insert will fail, just like in the UI.  In this example, it's placing the file named "Bookshelf" that exists at the top level of the active project.

 

import adsk.core, adsk.fusion, traceback

_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

        project = _app.data.activeProject
        bookshelfFile = None
        for file in project.rootFolder.dataFiles:
            if file.name == 'Bookshelf':
                bookshelfFile = file
                break

        des = adsk.fusion.Design.cast(_app.activeProduct)
        root = des.rootComponent
        occ = root.occurrences.addByInsert(bookshelfFile, adsk.core.Matrix3D.create(), True)            
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog