# Event handler for the palette HTML event.
class MyHTMLEventHandler(adsk.core.HTMLEventHandler😞
def __init__(self😞
super().__init__()
def notify(self, args😞
global _ui, _app, num
_app = adsk.core.Application.get()
_ui = _app.userInterface
doc = _app.activeDocument
products = doc.products
product = products.itemByProductType('CAMProductType')
_cam = adsk.cam.CAM.cast(product)
try:
htmlArgs = adsk.core.HTMLEventArgs.cast(args)
data = json.loads(htmlArgs.data)
if data['action']=='verze':
palette = _ui.palettes.itemById('myPalette')
if palette :
_ui.messageBox(_app.version)
if data['action']=='count':
if palette :
palette = _ui.palettes.itemById('myPalette')
palette.sendInfoToHTML('send', 'value I need to send')
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def run(context😞
try:
global _ui, _app
_app = adsk.core.Application.get()
_ui = _app.userInterface
# Add a command that displays the panel.
showPaletteCmdDef = _ui.commandDefinitions.itemById('showPalette')
if not showPaletteCmdDef:
showPaletteCmdDef = _ui.commandDefinitions.addButtonDefinition('showPalette', 'Zobrazit CAM CS+ Tools', 'Show the custom palette', '')
# Connect to Command Created event.
onCommandCreated = ShowPaletteCommandCreatedHandler()
showPaletteCmdDef.commandCreated.add(onCommandCreated)
handlers.append(onCommandCreated)
# Add the command to the toolbar.
panel = _ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cntrl = panel.controls.itemById('showPalette')
if not cntrl:
panel.controls.addCommand(showPaletteCmdDef)
# Create and display the palette.
palette = _ui.palettes.itemById('myPalette')
if not palette:
palette = _ui.palettes.add('myPalette', 'Tools', 'palette.html', True, True, True, 300, 200)
# Dock the palette to the right side of Fusion window.
palette.dockingState = adsk.core.PaletteDockingStates.PaletteDockStateRight
# Add handler to HTMLEvent of the palette.
onHTMLEvent = MyHTMLEventHandler()
palette.incomingFromHTML.add(onHTMLEvent)
handlers.append(onHTMLEvent)
# Add handler to CloseEvent of the palette.
onClosed = MyCloseEventHandler()
palette.closed.add(onClosed)
handlers.append(onClosed)
else:
palette.isVisible = True
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('myPalette')
if palette:
palette.deleteMe()
# Delete controls and associated command definitions created by this add-ins
panel = _ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cmd = panel.controls.itemById('showPalette')
if cmd:
cmd.deleteMe()
cmdDef = _ui.commandDefinitions.itemById('showPalette')
if cmdDef:
cmdDef.deleteMe()
cmd = panel.controls.itemById('sendInfoToHTML')
if cmd:
cmd.deleteMe()
cmdDef = _ui.commandDefinitions.itemById('sendInfoToHTML')
if cmdDef:
cmdDef.deleteMe()
#_ui.messageBox('Stop addin')
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))