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: 

Error retrieving dataFile in unopened folder

Message 1 of 7
1144 Views, 6 Replies

Error retrieving dataFile in unopened folder

Good morning all,


The API is throwing an Internal Validation Error when I try and retrieve the dataFile from an XRef component, under some very specific circumstances.  


It occurs under the following conditions:

1) You have at least 5 levels of nested XRef components (!)

2) The XRef components are in a different or sub folder in the project.

3) The folder containing the file in question has never been opened in the data panel.


#3 is true if it's the first time you open the project on a new computer, or if you clear the cache.  In either case, running the script below raises the error when you try and retrieve the dataFile for the deepest XRef.  As soon as you open the folder in the dataPanel, the validation error goes away.


Here is test script I am running:

            app = adsk.core.Application.get()
            ui = app.userInterface
                curDesign = adsk.fusion.Design.cast(app.activeDocument.products.itemByProductType('DesignProductType'))

                occs = curDesign.rootComponent.allOccurrences
                for occ in (occ for occ in occs if occ.isReferencedComponent):
                    pd = occ.component.parentDesign.parentDocument
                    df = pd.dataFile
                if ui:
                    ui.messageBox('command executed failed: {}'.format(traceback.format_exc()))

Here is the test model:

And here is a screencast showing the behavior:

The error occurs on the line "df = pd.dataFile"


I admit the test case looks a little convoluted, but I promise I came by this situation honestly!  This is the simplest set of data with which I can recreate a situation I am encountering on one of our real product designs.


Obviously the workaround right now is to open every folder in my project before running the real script. But that's quite cumbersome so I'm hoping we can either get this logged as bug and fixed, or maybe someone can suggest a script-based workaround (i.e. is there a way to load/preview the folders from within my script, mimicking what happens when we view it in the data panel)?


Thanks for your help.




Message 2 of 7
in reply to: p.seem

I tried your script with the sample data you provided but did not notice any problem. But for me all the sub-assemblies are lying in the same folder as of main assembly. May be archiving does not care for folders of parts in an assembly. Then I decided to create my own sample assembly with few sub parts in different folder but again I am not able to reproduce this issue. Is it possible for you to share a project with me containing a problematic assembly?


My email id is:



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 7
in reply to: goyals



Thanks for looking into this.  When I went to create a fresh project for you, I found I couldn't reproduce the behavior, either.  Not even in my original test model.  Frustratingly, it still happens on our production data, but that isn't something I'm able to share.


I'll have to keep trying to hone in on what's going wrong when I have spare time, and see if I can recreate a simplified test case. In the mean time you can consider this closed.  I'll accept your answer, and make a new post in the future if I can narrow it down further.





Message 4 of 7
in reply to: goyals



You are right that exporting and importing an F3Z removes all of the folder structure, which is critical to reproduce this bug.  I still can't tell what has changed in my test case that no longer shows the error, but I have created a much-reduced version of the main model which _does_ show the error.


"Full" is our complete model, which shows the problem but is quite large and so would be annoying for you to work with.  "Reduced" is a stripped-down model which still shows the problem.  "Test" is the test case, which used to, but no longer, shows the problem.  So presumably you want to focus on "Reduced."  In each case the main assembly is in the named folder, and the linked assemblies are in a subfolder called "Sub." If I clear my cache, open the main "MW3_test" model without viewing the Sub folder, then run the script in question, I get an internal validation error when pulling the dataFile. As soon as I view the folder in the data panel, the error goes away (until I next clear my cache).


Thank you for your help with this.  I have just sent an invite to the project to your email address, so you should have that soon.


Message 5 of 7
in reply to: p.seem

On the off chance any one else encounters this issue, it turns out there is a way to programatically pre-cache the contents of all your folders.  Before posting I had tried iterating through the all the project folders and retrieving all of their data files, but that wasn't enough to force the system to recognize that the dataFile existed (i.e. when I requested the dataFile for certain documents, Fusion 360 still threw the Internal Validation Error I described above).


What I missed is that taking some action on each dataFile (e.g. retrieving its ID and storing it) is enough to update whatever internal structure/cache/unicorn-farm in which the dataFile needs to be found in in order to avoid the error.


So quick and dirty function like: 

def previewFolder(topFolder, ids):     
    for childFolder in topFolder.dataFolders:
        previewFolder(childFolder, ids)
    for df in topFolder.dataFiles:
        ids[] = df

run on the top folder in the project (with 'ids' as an initially empty dictionary) made all subsequent retrievals of a documents' dataFile successful.


Hopefully no one else finds themselves in the this situation, but if you do at least you have a temporary workaround available.

Message 6 of 7
in reply to: p.seem

I hit this folder problem with the new "Editable documents" feature for personal users.


  1. Start Fusion 360
  2. Click on "x of 10" on the top right
  3. Click My editable documents
  4. Open a file from the "My editable documents" "folder"
  5. Add-ins cannot get the datafile for that document (InternalValidationError)


I will try p.seem's workaround when I find the time.

Message 7 of 7
in reply to: p.seem

If only the Editable Documents is needed (might be good first guess for a personal license file):



For full recursion, I found that I did not need to assign the id to any variable:

def previewFolder(topFolder):     
    for childFolder in topFolder.dataFolders:
    for df in topFolder.dataFiles:

for p in
    root = p.rootFolder




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