Open f3d file and get BRepBody

Open f3d file and get BRepBody

Anonymous
Not applicable
1,892 Views
3 Replies
Message 1 of 4

Open f3d file and get BRepBody

Anonymous
Not applicable

Hello

 

I already wrote a little Python script to compare two BRepBodies on Area, Volume and Faces. Now my question is: Is it possible to open a local f3d and get the second BRepBody I want to compare with the already open file. I hope you know what I mean.

 

So i want that the user will hit a Button which opens a FileDialog. There the user can select a file which will then be opened in the background and then i want to compare File1's BRepBodies with File2's BrepBodies.

 

Here is a video on how it works so far with two BRepBodies in the same Design: 

 

Greets Fabi

0 Likes
1,893 Views
3 Replies
Replies (3)
Message 2 of 4

marshaltu
Autodesk
Autodesk

Hello,

 

There is no way to open a local f3d file in background. We provide the functionality to open file with invisible mode from your project. The following codes demo that.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface   

        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent
        bodies = root.bRepBodies
        
        doc = app.documents.open(app.data.activeProject.rootFolder.dataFiles.item(0), False)
        docDesign = adsk.fusion.Design.cast(doc.products.itemByProductType('DesignProductType'))
        docBodies = docDesign.rootComponent.bRepBodies
        
        ui.messageBox('Bodies in active document {}, bodies in invisible document {}'.format(bodies.count, docBodies.count))
        doc.close(False)
        

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


Marshal Tu
Fusion Developer
>
Message 3 of 4

Anonymous
Not applicable

Hello @marshaltu

 

Thanks for your reply! 

 

I get the filesToImport with a FileDialog. I found out that you can also use the ImportManager to import a '.f3d' file. First I've created a Script where the code was in run() and worked perfectly. Now I tried to merge the import of files into my other Script where I want to compare the imported files with each other. My problem now is that Fusion will import the files but then it closes my Command Input Dialog and crashes. Why does this happen?

 

Code Snippet:

 

#following code is in my CommandExecuteHandler():
countFiles = 0
#filesToImport is an Array of filenames e.g. ['C:\\file1.f3d','C:\\file2.f3d',...]

for filename in filesToImport:
   #creating an optional new component, should also work with root
   trans = adsk.core.Matrix3D.create()
   newOccurence = rootComp.occurrences.addNewComponent(trans)
   newComponent = newOccurence.component
   # Get import manager 
   importManager = app.importManager
   countFiles = countFiles + 1
   # Get archive import options
   archiveOptions = importManager.createFusionArchiveImportOptions(filename)
   
   #Import archive file to root component or new component
   #importManager.importToNewDocument(archiveOptions) works
   importManager.importToTarget(archiveOptions, newComponent) #crashes Fusion
ui.messageBox("Imported: " + str(countFiles))

 

The full file can be found on github

 

Thanks in advance!
Greets Fabi
0 Likes
Message 4 of 4

marshaltu
Autodesk
Autodesk

Hello,

 

Unfortunately this was a limitation of ImportManager API. Currently we will invoke Import command to do import when the api is executed. So the scenario was you invoke an API command(you created) and invoke another import command in background when the API command is running. The status of Fusion 360 became messy and unstable at the moment. Theoretically invoking one command will end running command automatically. This was why command dialog was closed in your workflow.

 

You may have to redesign your workflow to avoid the issue.  For example: you could make use of Custom Event API. In your command, you can collect users' input for the path of importing file and other options, but not do import right away. Then you can fire custom event at the end of your command execute hander, and do import/compare bodies in your custom event handler. I am not sure if that makes sense to you.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>