Hello everyone,
I have a problem where it's impossible to load a palette on startup, the palette just won't appear (nor be created as trying to set it to visible doesn't work).
Moreover if you try give it a docking state you get RuntimeError: 2 : InternalValidationError : pArea.
I have the problem with both the old and the new browser.
Anyone have any idea why or a workaround ?
import adsk.core, adsk.fusion, traceback, adsk.cam
handlers = []
ui = None
app = adsk.core.Application.get()
ui = app.userInterface
def run(context):
try:
app = adsk.core.Application.get()
ui = app.userInterface
paletteId = 'TestPalette'
palette = ui.palettes.itemById(paletteId)
if palette:
palette.isVisible = True
else:
palette = ui.palettes.add(
paletteId,
'test',
'palette.html',
True, #isVisible
True, #showCloseButton
True, #isResizable
300, #width
120, #height
True #is New Browser
#False
)
palette.dockingState = adsk.core.PaletteDockingStates.PaletteDockStateTop
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
# Delete the palette created by this add-in.
palette = ui.palettes.itemById('TestPalette')
if palette:
palette.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
</head>
<body>
test
</body>
</html>
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
I suspect Fusion isn't in a state where palettes can be created yet when add-ins are initially loading. However, I also tried creating the palette in the OnStartupComplete event, which should fire once everything is loaded, but that also failed. So I don't know if it's still too early or if there's some other issue I'm not aware of.
I can tell you this isn't a workflow that we considered when we added support for palettes in the API, so it hasn't been tested.
Hi @tykapl.breuil .
When I used the WorkspaceActivated event, I was able to display the palette even at startup.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-fcb72832-b3bb-4a12-b590-977e75e915ca
# Fusion360API Python Addin
import adsk.core
import adsk.fusion
import traceback
_handlers = []
_ui: adsk.core.UserInterface = None
class MyWorkspaceActivatedHandler(adsk.core.WorkspaceEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
eventArgs = adsk.core.WorkspaceEventArgs.cast(args)
ui: adsk.core.UserInterface = eventArgs.firingEvent.sender
paletteId = 'TestPalette'
palette = ui.palettes.itemById(paletteId)
if palette:
if ui.activeWorkspace.id != 'FusionSolidEnvironment':
palette.isVisible = False
else:
palette.isVisible = True
else:
palette = ui.palettes.add(
paletteId,
'test',
'palette.html',
True, #isVisible
True, #showCloseButton
True, #isResizable
300, #width
120, #height
True #is New Browser
#False
)
palette.dockingState = adsk.core.PaletteDockingStates.PaletteDockStateTop
except:
adsk.core.Application.get().log('Failed:\n{}'.format(traceback.format_exc()))
def run(context):
try:
global _ui
_ui = adsk.core.Application.get().userInterface
global _handlers
onWorkspaceActivated = MyWorkspaceActivatedHandler()
_ui.workspaceActivated.add(onWorkspaceActivated)
_handlers.append(onWorkspaceActivated)
except:
adsk.core.Application.get().log('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
global _handlers
if len(_handlers) > 0:
del _handlers[-1]
global _ui
palette = _ui.palettes.itemById('TestPalette')
if palette:
palette.deleteMe()
except:
adsk.core.Application.get().log('Failed:\n{}'.format(traceback.format_exc()))