Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Importing external models without saving?

chris.monachanZWSCF
Enthusiast Enthusiast
597 Views
2 Replies
Message 1 of 3

Importing external models without saving?

chris.monachanZWSCF
Enthusiast
Enthusiast

I have an Add-in I've developed that builds a fairly complex item from specifications that I read from a spreadsheet. I have got to the point where I need to add in various fixings and so forth which I have STEP files for. (Note, the fact they're STEP doesn't matter, I can convert them to anything)

 

Is there a way for me to bring this into the model I'm building using the API without the user having to first save the document? I know when I try to bring in other components I need to force the user to first save the document, but I was wondering if there is another way I can bring in external elements through the API without forcing the user to save first? 

 

It wouldn't be so bad if the standard Fusion UI save dialog was available to use, but I believe it's private, and I've tried using TextCommands to bring it up. It works but not very well, and it isn't officially supported.

 

Any help would be appreciated, even workflow suggestions.

1 Like
Accepted solutions (1)
598 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @chris.monachanZWSCF .

 

ImportManager can be used to import STEP files without saving them.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-DA509909-1E13-48F1-8235-744BA6B94CBA 

 

The following sample creates a new document and imports a Step file.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui: adsk.core.UserInterface = adsk.core.UserInterface.cast(None)
    try:
        stpFileName = r'C:\temp\sample.step'

        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        importManager: adsk.core.ImportManager = app.importManager
        stpOptions: adsk.core.STEPImportOptions = importManager.createSTEPImportOptions(stpFileName)
        importManager.importToTarget(stpOptions, root)

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

 

For more formats, there is a sample here.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-3f24e9e8-422d-11e5-937b-f8b156d7cd97 

 

1 Like
Message 3 of 3

chris.monachanZWSCF
Enthusiast
Enthusiast
Hey Thanks! That should work for me for now. Although I tried it with a STEP file and it failed. The file imported fine using the UI. But the IGES importer seems to work so I can use that. It could be my STEP file format, although it's odd it imported using the UI.

What would be amazing was if there was a way to load a file from the Cloud Storage. I noticed it can take a URL but it doesn't seem to like the URN type ID's files get from the DataManager. The work-a-round I have is that I'll find the file in the DataManager, export it to a temporary file on disk then use the import manager to import it into the model I'm building. It's a bit clunky but it means I can keep all the data in the cloud.
1 Like