✈ Pre-Flight checks
🐞 Describe the bug
When a SmartButton's selfinit script changes the button icon using set_icon(), the icon change does not persist after a pyRevit reload. The button reverts to the icon that was parsed from disk during the initial load.
Example being the update button: after updating, the button remains orange instead of resetting.
⌨ Error/Debug Message
update button doesn't clear its orange color after updating (which triggers reloading)
♻️ To Reproduce
No response
⏲️ Expected behavior
Root Cause:
The C# loader's IconManager maintains a BitmapCache for loaded bitmap sources 1 . While the ExtensionParser clears its _iconCache during reload via ClearAllCaches() 2 , the IconManager's BitmapCache is never cleared. The ClearCache() method exists 3 but is not called in the reload sequence.
Reload Flow:
ExtensionParser.ClearAllCaches() clears the icon file path cache
- Icons are re-parsed from disk and applied via
IconManager.ApplyIcon() 4
- SmartButton
__selfinit__ runs and may call set_icon() to override the icon 5
- On next reload, step 2 re-applies the cached bitmap from the
BitmapCache, overriding the __selfinit__ changes
Comparison with Python Loader:
The legacy Python loader does not have this issue because it creates new bitmaps on every set_icon() call without a persistent cache 6 . The ButtonIcons class reads the file and creates bitmaps fresh each time 7 .
Suggested Fix:
Call IconManager.ClearCache() during the reload sequence to ensure bitmaps are reloaded from disk, similar to how the ExtensionParser clears its icon path cache.
Notes
The issue is specific to the C# loader path. The Python loader's icon handling in uimaker.py and ribbon.py does not use a persistent bitmap cache, so SmartButton icon changes via __selfinit__ work correctly in the legacy loader.
🖥️ Hardware and Software Setup (please complete the following information)
Additional context
No response
✈ Pre-Flight checks
🐞 Describe the bug
When a SmartButton's selfinit script changes the button icon using set_icon(), the icon change does not persist after a pyRevit reload. The button reverts to the icon that was parsed from disk during the initial load.
Example being the update button: after updating, the button remains orange instead of resetting.
⌨ Error/Debug Message
update button doesn't clear its orange color after updating (which triggers reloading)♻️ To Reproduce
No response
⏲️ Expected behavior
Root Cause:
The C# loader's
IconManagermaintains aBitmapCachefor loaded bitmap sources 1 . While theExtensionParserclears its_iconCacheduring reload viaClearAllCaches()2 , theIconManager'sBitmapCacheis never cleared. TheClearCache()method exists 3 but is not called in the reload sequence.Reload Flow:
ExtensionParser.ClearAllCaches()clears the icon file path cacheIconManager.ApplyIcon()4__selfinit__runs and may callset_icon()to override the icon 5BitmapCache, overriding the__selfinit__changesComparison with Python Loader:
The legacy Python loader does not have this issue because it creates new bitmaps on every
set_icon()call without a persistent cache 6 . TheButtonIconsclass reads the file and creates bitmaps fresh each time 7 .Suggested Fix:
Call
IconManager.ClearCache()during the reload sequence to ensure bitmaps are reloaded from disk, similar to how theExtensionParserclears its icon path cache.Notes
The issue is specific to the C# loader path. The Python loader's icon handling in
uimaker.pyandribbon.pydoes not use a persistent bitmap cache, so SmartButton icon changes via__selfinit__work correctly in the legacy loader.🖥️ Hardware and Software Setup (please complete the following information)
Additional context
No response