Import .CATPart via API

Import .CATPart via API

Fliegende-Rehe
Contributor Contributor
412 Views
1 Reply
Message 1 of 2

Import .CATPart via API

Fliegende-Rehe
Contributor
Contributor

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}"')

 

 

0 Likes
Accepted solutions (1)
413 Views
1 Reply
Reply (1)
Message 2 of 2

boopathi.sivakumar
Autodesk
Autodesk
Accepted solution

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