Breaking the Link on an Imported .f3d Body

allanr3gis
Explorer

Breaking the Link on an Imported .f3d Body

allanr3gis
Explorer
Explorer

Hello my Fusion 360 Commmunity!

 

I'm trying to figure out if there is a way to Break the Link of an external .f3d model after it has been imported into your existing design. Ultimately, my goal is to do all of the following through the Fusion API:

 

  1. Import a Body from a .f3d file (I know how to do this),
  2. Break the Link so that I can Cut the imported body in my existing design,
  3. Combine the Imported Body (whose link is broken) with a Body native to the existing design file together.

Is it possible to Break Links of imported models through the Fusion 360 API?

 

break link help.PNG

0 Likes
Reply
Accepted solutions (1)
749 Views
2 Replies
Replies (2)

ekinsb
Alumni
Alumni
Accepted solution

The API doesn't directly support the "Break Link" command, although that is on our backlog to provide in the future.  However, depending on how the occurrence was created you may not need it.  If you're creating the occurrence in your program, the second argument in the addByInsert method specifies if you want to create a link or not.  If this is False, then there is no link and the contents are copied into the current design.  Below is some code that demonstrates this.

 

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

        # Find the file to insert.
        fileFound = False
        proj = adsk.core.DataProject.cast(None)
        for proj in app.data.dataProjects:
            if proj.name == 'Junk':
                file = adsk.core.DataFile.cast(None)
                for file in proj.rootFolder.dataFiles:
                    if file.name == 'CAMTest':
                        fileFound = True
                        
                        # Insert the file into the active design.
                        des = adsk.fusion.Design.cast(app.activeProduct)
                        occs = des.rootComponent.occurrences
                        occ = occs.addByInsert(file, adsk.core.Matrix3D.create(), False)                   
            if fileFound:
                break
                        
        if not fileFound:
            ui.messageBox('The file was not found.')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

If the occurrence already exists and you need to break the link then there is a workaround where you can call the "Break Link" command.  Because the "Break Link" command doesn't need any input besides the currently selected occurrence, selecting the occurrence and execute the command is all you need.  Here's some code that illustrates that.

 

# Break the link.
ui.activeSelections.clear()
ui.activeSelections.add(occ)                        
breakCmd = ui.commandDefinitions.itemById('BreakXRefLinkCmd')
breakCmd.execute()

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
1 Like

allanr3gis
Explorer
Explorer

Wow! Not only is this exactly the type of solution that I was looking for, but it also gave me an idea on how to make my code's syntax a little more robust.

 

I'll work on integrating your suggestion into my code.  After I do, I'll let you know how it's working out for me.  Thanks a ton!

0 Likes