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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating out-of-date references through API

Message 1 of 3
314 Views, 2 Replies

Updating out-of-date references through API

I am trying to update out-of-date references of a document and encountered few issues. 

I have the following situation:

  • Document `A` which has references to documents `B` and `C`.
  • Document `B` also has a reference to a document `B.1`

How to update all references (`B`, `C` and `B.1`) from document `A` using API?

This is my approach:



import adsk.core, adsk.fusion, traceback

def update_document_demo( document, recurse=False, save_message="Updated" 😞 
    for doc_ref in document.documentReferences:
        if recurse:
            print ("ref doc:")
            print (
            # if not doc_ref.referencedDocument.isUpToDate: # can't check if referenced document is up to date, raises an error 😕 
            child_document = doc_ref.referencedDocument.dataFile, True )
            update_document_demo( child_document, recurse=True, save_message=save_message )
   save_message )
            # child_document.close(saveChanges=False)
            print (f"updated child doc: {}")

        if doc_ref.isOutOfDate:
            print (f"updating reference to {} ")
            if not doc_ref.getLatestVersion():
                print ("getLastestVersion was unsuccessful")
            print (f"finished updating reference to {}")

    if not document.isUpToDate:
        raise Exception( f"Document {} has references which could not be updated. Update manually and continue" )

def run( context ):
    app = adsk.core.Application.get()
    ui  = app.userInterface
    doc = app.activeDocument
    update_document_demo(document=doc, recurse=True)



If I run this on provided dummy files (attached) when documents `B`, `C` and `B.1` are modified and are out-of-date for document `A`, I get the following output before the exception is raised:



ref doc:
B v2
ref doc:
B.1 v1
updated child doc: B.1 v1
updating reference to B.1 v1 
finished updating reference to B.1 v2
updated child doc: B v3   
updating reference to B v2  <--------- !!!!!!! 
finished updating reference to C v1   <--------- !!!!!!! 

ref doc:
B v3
ref doc:
B.1 v2
updated child doc: B.1 v1
updated child doc: B v3


Few observations:

  • The order `document.documentReferences` seems to be non deterministic. Running this multiple times gives a different sequence of `documentReferences`
  • Occasionally after `documentReference.getLatestVersion()` object changes its pointer to another `documentReference`. In this example, we were updating reference to `B` and afterwards it changed its reference to `C` document.

Tags (2)
Message 2 of 3
in reply to: sharas_s

Hi @sharas_s .


There may be a better way, but this one works.

app.executeTextCommand(u'Commands.Start PLM360DeepRefreshDocumentCommand')


Message 3 of 3
in reply to: sharas_s

This command works quite well. Thanks! 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th

Autodesk Design & Make Report