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: 

Error retrieving dataFile in unopened folder

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
p.seem
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
            try:
                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
                    ui.messageBox(pd.name)
                    df = pd.dataFile
                    
                ui.messageBox('done')    
                
            except:
                if ui:
                    ui.messageBox('command executed failed: {}'.format(traceback.format_exc()))

Here is the test model: https://a360.co/2PebFhh

And here is a screencast showing the behavior:  https://autode.sk/2zr9pbN

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.

 

PS

 

6 REPLIES 6
Message 2 of 7
goyals
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:  shyamsunder.goyal@autodesk.com

 

Thanks.



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

goayls,

 

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.

 

Thanks,

 

PS

Message 4 of 7
p.seem
in reply to: goyals

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
p.seem
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.id] = 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
thomasa88
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
thomasa88
in reply to: p.seem

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

if app.data.personalUseLimits:
    app.data.personalUseLimits.editableFiles

 

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:
        previewFolder(childFolder)
    for df in topFolder.dataFiles:
        df.id

for p in app_.data.dataProjects:
    root = p.rootFolder
    previewFolder(root)

 

 

 

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