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: 

Import .CATPart via API

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Fliegende-Rehe
121 Views, 1 Reply

Import .CATPart via API

I have method to import step file into current design, using option class createSTEPImportOptions. Is there any a special or universal class that will allow me upload .CATPart files in the same?

 

def import_step_geometry(path):
    manager = app.importManager
    options = manager.createSTEPImportOptions(path)
    filename = os.path.basename(path)

    if manager.importToTarget(options, root_comp):
        logger(f'Geometry "{filename}" loaded')
    else:
        raise Exception(f'Cannot load geometry "{filename}"')

 

 

Tags (2)
Labels (2)
1 REPLY 1
Message 2 of 2

Hi @Fliegende-Rehe 

Apart form native and few neutral formats the file needs to be translated before using it in fusion, so you have to use an upload method to upload the file to the team and use it here is the little script


import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()

        ui = app.userInterface

        doc: adsk.core.Document = app.activeDocument

        folder: adsk.core.DataFolder = app.data.activeFolder

        uploadFolder = folder.uploadFile(r'C:\Users\somepart.CATPart')

        isUploading = True
        while isUploading:
            if uploadFolder.uploadState == adsk.core.UploadStates.UploadFinished:
                isUploading = False

            elif uploadFolder.uploadState == adsk.core.UploadStates.UploadFailed:
                ui.messageBox('Upload failed.')
                isUploading = False

            adsk.doEvents()

        uploadedFile = uploadFolder.dataFile

        des: adsk.fusion.Design = doc.products.itemByProductType('DesignProductType')
        if doc.isSaved:
           des.rootComponent.occurrences.addByInsert(uploadedFile, adsk.core.Matrix3D.create(), True)

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

 

The script will upload the file to active fusion team folder and wait for the upload to complete and once the upload is done then it will insert it into the current document if it is saved.

 


Boopathi Sivakumar
Senior Technology Consultant

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