Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

addByInsert is not working for occurrences in Python

MiWaNiZa
Advocate

addByInsert is not working for occurrences in Python

MiWaNiZa
Advocate
Advocate

Hi Team,

 

I'm trying to insert an existing file (created in the program way too) into existing design.

        doc1 = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        doc1.saveAs('Child', folder, '', '')
        ret=doc1.close(True)
        ui.messageBox(str(ret))
        rootComp = design.rootComponent
        matrix = adsk.core.Matrix3D.create()        
        rootComp.occurrences.addByInsert(doc1, matrix, True) # error

But getting an error message:

 2017-07-02 23_47_49-Fusion 360.png

 

Could you please help me with this issue?

Dmytro Yemelianov / Дмитрий Емельянов
Mechanical engineer & Software Developer / Инженер-машиностроитель и разработчик программного обеспечения
Blog (EN) | Blog (RU)
Facebook | Twitter | LinkedIn


 

0 Likes
Reply
548 Views
1 Reply
Reply (1)

neil.liu
Autodesk
Autodesk

Hi @MiWaNiZa

 

The main reason is that the first parameter of 'addByInsert' is a data file, not a document. And doc1 is closed, it is not valid any more. 

 

I changed the script a little bit, it works as expected.

 

        folder = app.data.activeProject.rootFolder.dataFolders.itemByName('folder')
        doc1 = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        doc1.saveAs('Child', folder, '', '')
        ret=doc1.close(True)
        ui.messageBox(str(ret))
        
        datafile = None        
        for file in folder.dataFiles:
            if (file.name == 'Child'):
                dataFile = file
                break
        if (datafile is None):
            return
        
        # document must be saved before insert a new file into it
        app.activeDocument.saveAs('parent', folder, '', '')
        design = adsk.fusion.Design.cast(app.activeProduct)
        rootComp = design.rootComponent
        matrix = adsk.core.Matrix3D.create()        
        rootComp.occurrences.addByInsert(datafile, matrix, True) 

If you have further questions please let me know.

 

Thanks, 

Neil Liu

0 Likes