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 EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com