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: 

How to import DWG file by Fusion 360 API

2 REPLIES 2
Reply
Message 1 of 3
xusho
502 Views, 2 Replies

How to import DWG file by Fusion 360 API

Please advise how to import a *.dwg file in Fusion 360 by API.

Shoudong Xu
Autodesk Moldflow Meshing
Shoudong.Xu@autodesk.com
2 REPLIES 2
Message 2 of 3
kandennti
in reply to: xusho

Hi @xusho .

 

I don't know if it's 3D or 2D, but I don't think DWG import is currently supported.

 

In order to do this, if you are using 3D, you may want to parse the DWG and draw it on the sketch.
I have created and published an add-in that imports Iges and Step curves in this way.

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


In the case of 2D, I think the shortcut is to automate the process of converting to DXF and importing.

 

Addendum.
I'm sorry, I made a mistake.
There was no way to import 2D.

Message 3 of 3
BrianEkins
in reply to: xusho

To use a DWG file when working interactively with Fusion, you need to first open it using the "Open" command. This allows you to specify the file and then Fusion will upload the file and convert it to a Fusion file. you can then open this file and save it to the desired location on Fusion Teams.  Once saved, you can use this file like any other file.

 

You can do the same thing through the API but the workflow is slightly different.  First, you'll use the API to navigate to the folder you want to save the converted DWG file to.  For example, the following will get the folder named "DWG Files" in the project named "Test Project" that exists in the hub named "Sample".  It's a bit messy but it does work.  There are certainly some things that could be added to the API to make this easier.

def run(context):
    try:
        app: adsk.core.Application = adsk.core.Application.get() 
        ui = app.userInterface 

        data = app.data

        # Get the hub named "Sample".
        hub: adsk.core.DataHub = getNamedItem(data.dataHubs, 'Sample')
        if hub is not None:
            # Get the project named "Test Project".
            proj: adsk.core.DataProject = getNamedItem(hub.dataProjects, 'Test Project')

            if proj is not None:
                # Get the folder named "DWG Files"
                projFolder: adsk.core.DataFolder = proj.rootFolder.dataFolders.itemByName('DWG Files')

                if projFolder is not None:
                    # Upload the DWG file.
                    uploadFuture = projFolder.uploadFile('C:/Temp/NewCylinder6.dwg')

                    if uploadFuture is not None:
                        # Loop until the initial upload is complete.
                        while uploadFuture.uploadState == adsk.core.UploadStates.UploadProcessing:
                            adsk.doEvents()
                            if uploadFuture.uploadState == adsk.core.UploadStates.UploadFinished:
                                # Loop until the file can be opened, which means it's fully processed.
                                dataFile = uploadFuture.dataFile
                                isOpened = False
                                while not isOpened:
                                    adsk.doEvents()
                                    try:
                                        doc: adsk.core.Document = app.documents.open(dataFile)
                                        doc.close(False)
                                        isOpened = True
                                    except:
                                        continue

                                app.log('Successfully processed DWG import.')
                            else:
                                continue
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

 

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

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

Post to forums  

Autodesk Design & Make Report