Import Manager Help

Import Manager Help

TechrimStandards
Enthusiast Enthusiast
745 Views
1 Reply
Message 1 of 2

Import Manager Help

TechrimStandards
Enthusiast
Enthusiast
import adsk.core, adsk.fusion, traceback
import os.path, sys

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        # Get import manager
        importManager = app.importManager
        


       # Get step import options
        stpFileName = 'C:\\Users\Phartman.hartprecision\Desktop\WAGDE-MB723291S-S.STEP'
        stpOptions = importManager.createSTEPImportOptions(stpFileName)
        stpOptions.isViewFit = False
        
        # Get active design
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Get root component
        rootComp = design.rootComponent
        
        
        # Import step file to root component
        importManager.importToTarget(stpOptions, rootComp)
    
       
        # Close the new created document
        doc = app.activeDocument
        doc.close(False)
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

SAMPLE CODE:

 

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

 

 

Trying to run the sample code from the link attached. Getting error "AttributeError: "NoneType" object has no attribute 'rootComponent' . When uploading the file from my computer without the add-in it works fine. Why is this happening? Any would be greatly appreciated!

0 Likes
746 Views
1 Reply
Reply (1)
Message 2 of 2

JeromeBriot
Mentor
Mentor

Hello,

 

This is not related to the error message you mentioned, but replace the line:

 

stpFileName = 'C:\\Users\Phartman.hartprecision\Desktop\WAGDE-MB723291S-S.STEP'

With:

stpFileName = 'C:\\Users\\Phartman.hartprecision\\Desktop\\WAGDE-MB723291S-S.STEP

 Or:

stpFileName = r'C:\Users\Phartman.hartprecision\Desktop\WAGDE-MB723291S-S.STEP'

 Or:

stpFileName = 'C:/Users/Phartman.hartprecision/Desktop/WAGDE-MB723291S-S.STEP'

 

0 Likes