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: 

Loading specific version of a derived component via API or Text Commands

1 REPLY 1
Reply
Message 1 of 2
CL6042
168 Views, 1 Reply

Loading specific version of a derived component via API or Text Commands

Hi guys,

 

for my case I need to load a specific version of a derived component. So far I can refresh the derived components to the newest version via TextCommand:

 

 

# Force a deep refresh to update all external references
app.executeTextCommand(u'Commands.Start PLM360DeepRefreshDocumentCommand')

 

 
Also I am able to load a specific file version when I open a single file on its own:

 

# Open a specific file version
adsk.core.Application.get().documents.open(file_version)

 

 
I can not find anything in the API Reference Manual and so far I have not found a good documentation on all available text commands.
 
Thanks for helping me out here or point me in the right direction to get this working.
1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: CL6042

Here's some example code that should do it. I found a bug where the call to change the version is erroring even though it appears to be successful. I'll see if a bug can get logged for this.

 

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

        occ: adsk.fusion.Occurrence = ui.selectEntity('Select an occurrence.', 'Occurrences').entity

        if not occ.isReferencedComponent:
            ui.messageBox('The selection component must be an external reference.')
            return
        
        docRef = occ.documentReference
        versionCount = docRef.dataFile.versions.count
        if versionCount == 1:
            ui.messageBox('The referenced file must have more than one version.')
            return

        currentVersion = docRef.dataFile.versionNumber
        if currentVersion == 1:
            # The first version is active so use the second version.
            version = 2
        else:
            # Get the previous version number.
            version = currentVersion - 1

        docRef.version = version
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report