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: 

Iterating through ProductPreferencesCollection throws InternalValidationError

1 REPLY 1
Reply
Message 1 of 2
krisztian_szaboWCZZ3
74 Views, 1 Reply

Iterating through ProductPreferencesCollection throws InternalValidationError

I tried iterating through the items in a ProductPreferencesCollection in Python and got a InternalValidationError/RuntimeError as a result.

Minimal code to reproduce the issue:

applicationPreferences = app.preferences
productPreferences = applicationPreferences.productPreferences
for i in range(productPreferences.count):
    logger.info(productPreferences.item(i))

And got the following error:

[EXCEPTION]
2 : InternalValidationError : res
Traceback (most recent call last):
File "<redacted>", line 935, in notify
logger.info(productPreferences.item(i))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<redacted>/AppData/Local/Autodesk/webdeploy/production/1b7b241a4d7e74709532875784c66d9a6c8030aa/Api/Python/packages\adsk\core.py", line 14755, in item
return _core.ProductPreferencesCollection_item(self, index)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 2 : InternalValidationError : res

 

Platform: Windows 11 Pro 22H2 (22621.2283)

Fusion 360 version: 2.0.17244 x86_64

1 REPLY 1
Message 2 of 2

Hi @krisztian_szaboWCZZ3 -San.

 

I was able to avoid the error by doing it this way instead of using the item method.

# Fusion360API Python script

import traceback
import adsk.core as core

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

        applicationPreferences = app.preferences

        productPreferences = applicationPreferences.productPreferences
        for i in range(productPreferences.count):
            pref = productPreferences[i]
            if not pref:
                print(f"{i}:None")
            else:
                print(f"{i}:{pref.classType()}")

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

However, it was almost empty.

0:None
1:None
2:adsk::fusion::FusionProductPreferences
3:None
4:None
5:None
6:None
7:None
8:None
9:None
10:None
11:None

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