Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert Design into current Design

2 REPLIES 2
Reply
Message 1 of 3
Jonschke
553 Views, 2 Replies

Insert Design into current Design

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.

2 REPLIES 2
Message 2 of 3
Jonschke
in reply to: Jonschke

Message 3 of 3
ekinsb
in reply to: Jonschke

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report