<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Palette Sample not working? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/palette-sample-not-working/m-p/8529421#M18349</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I tried to run Palette Sample on my Windows PC, but it doesn't work as expected. Palette Dialog doesn't show up.&lt;/P&gt;
&lt;P&gt;I have read related topics on this forum, but so far no success. The script show only small dialog with 'Stop addin' message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the sample code from&amp;nbsp;current (January, 17th, 2019) this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-F0068478-49F0-4E5E-9BAD-3116D8FCBCAF" target="_blank"&gt;Programming Interface/Sample Programs/User Interface/General/Palette Sample&lt;/A&gt;&amp;nbsp;web page updated and correct? Or should I use the code from the post above?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The .html file is in the same directory as the .py code. Anyhow I tried to trace the python code. I set a break point into the&amp;nbsp;ShowPaletteCommandExecuteHandler.notify. It looks like the code doesn't even reach the method. (the handler is never called)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How is the correct string-path for the html file?&amp;nbsp; Relative path works? How to write absolute path?&lt;/P&gt;
&lt;P&gt;Is for example this correct on Windows PC:&amp;nbsp; &amp;nbsp;'D:\\GitHub\\Fusion360\\Scripts\\ApiSamplePalette\\palette.html'&amp;nbsp; &amp;nbsp;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jan 2019 11:47:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-01-17T11:47:17Z</dc:date>
    <item>
      <title>Palette Sample not working?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/palette-sample-not-working/m-p/6998051#M18347</link>
      <description>&lt;P&gt;I'm not sure what I've done wrong, but I can't seem to get the palette sample to work. I've made an add in from the code here:&lt;A href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-c97b8ed2-e1da-11e6-af4c-3417ebc87622" target="_blank"&gt;http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-c97b8ed2-e1da-11e6-af4c-3417ebc87622&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I didn't make any changes, but when I try to use the 'send info to Palette' button I get the error pictured. When I click the 'click to send info to Fusion' button on the palette nothing happens. What could cause this if I didn't edit the sample code?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/341663i07164B9DCD263A09/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 17:23:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/palette-sample-not-working/m-p/6998051#M18347</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-05T17:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Palette Sample not working?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/palette-sample-not-working/m-p/6998832#M18348</link>
      <description>&lt;P&gt;Thank you for reporting this.&amp;nbsp; I can reproduce it and have found the problems.&amp;nbsp; The good news is that the problem isn't with Fusion but was with the sample code.&amp;nbsp; I made a couple of last minute changes as I was publishing it and apparently I broke it.&amp;nbsp; I've fixed it in the help system so it will be available&amp;nbsp;with the next&amp;nbsp;Fusion update.&amp;nbsp; Until then here's the updated html and py source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;palette.html&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;p id='p1'&amp;gt;Click the button below or use the "Send info to HTML" command in the ADD-INS panel.&amp;lt;/p&amp;gt;
        &amp;lt;button type='button' onclick='sendInfoToFusion()'&amp;gt;Click to send info to Fusion&amp;lt;/button&amp;gt; 
        &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;
    &amp;lt;/body&amp;gt;
    &amp;lt;script&amp;gt;
        function sendInfoToFusion(){
            var args = {
                arg1 : "Sample argument 1",
                arg2 : "Sample argument 2"
            };
            adsk.fusionSendData('send', JSON.stringify(args));
        }
        
        window.fusionJavaScriptHandler = {handle: function(action, data){
            try {
                if (action == 'send') {
					// Update a paragraph with the data passed in.
					document.getElementById('p1').innerHTML = data;
				}
				else if (action == 'debugger') {
                    debugger;
				}
				else {
					return 'Unexpected command type: ' + action;
                }
            } catch (e) {
                console.log(e);
                console.log('exception caught with command: ' + action + ', data: ' + data);
            }
            return 'OK';
        }};
    &amp;lt;/script&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Python Source&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, traceback
import json

# global set of event handlers to keep them referenced for the duration of the command
handlers = []
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
num = 0


# Event handler for the commandExecuted event.
class ShowPaletteCommandExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            # Create and display the palette.
            palette = _ui.palettes.itemById('myPalette')
            if not palette:
                palette = _ui.palettes.add('myPalette', 'My Palette', '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:
            _ui.messageBox('Command executed failed: {}'.format(traceback.format_exc()))


# Event handler for the commandCreated event.
class ShowPaletteCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()              
    def notify(self, args):
        try:
            command = args.command
            onExecute = ShowPaletteCommandExecuteHandler()
            command.execute.add(onExecute)
            handlers.append(onExecute)                                     
        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))     


# Event handler for the commandExecuted event.
class SendInfoCommandExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            # Send information to the palette. This will trigger an event in the javascript
            # within the html so that it can be handled.
            palette = _ui.palettes.itemById('myPalette')
            if palette:
                global num
                num += 1
                palette.sendInfoToHTML('send', 'This is a message sent to the palette from Fusion. It has been sent {} times.'.format(num))                        
        except:
            _ui.messageBox('Command executed failed: {}'.format(traceback.format_exc()))


# Event handler for the commandCreated event.
class SendInfoCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()              
    def notify(self, args):
        try:
            command = args.command
            onExecute = SendInfoCommandExecuteHandler()
            command.execute.add(onExecute)
            handlers.append(onExecute)                                     
        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))     


# Event handler for the palette close event.
class MyCloseEventHandler(adsk.core.UserInterfaceGeneralEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            _ui.messageBox('Close button is clicked.') 
        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


# Event handler for the palette HTML event.                
class MyHTMLEventHandler(adsk.core.HTMLEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            htmlArgs = adsk.core.HTMLEventArgs.cast(args)            
            data = json.loads(htmlArgs.data)
            msg = "An event has been fired from the html to Fusion with the following data:\n"
            msg += '    Command: {}\n    arg1: {}\n    arg2: {}'.format(htmlArgs.action, data['arg1'], data['arg2'])
            _ui.messageBox(msg)
        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', 'Show custom palette', 'Show the custom palette', '')

            # Connect to Command Created event.
            onCommandCreated = ShowPaletteCommandCreatedHandler()
            showPaletteCmdDef.commandCreated.add(onCommandCreated)
            handlers.append(onCommandCreated)
        
         
        # Add a command under ADD-INS panel which sends information from Fusion to the palette's HTML.
        sendInfoCmdDef = _ui.commandDefinitions.itemById('sendInfoToHTML')
        if not sendInfoCmdDef:
            sendInfoCmdDef = _ui.commandDefinitions.addButtonDefinition('sendInfoToHTML', 'Send info to Palette', 'Send Info to Palette HTML', '')

            # Connect to Command Created event.
            onCommandCreated = SendInfoCommandCreatedHandler()
            sendInfoCmdDef.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)

        cntrl = panel.controls.itemById('sendInfoToHTML')
        if not cntrl:
            panel.controls.addCommand(sendInfoCmdDef)
    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()))&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Apr 2017 23:07:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/palette-sample-not-working/m-p/6998832#M18348</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2017-04-05T23:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Palette Sample not working?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/palette-sample-not-working/m-p/8529421#M18349</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I tried to run Palette Sample on my Windows PC, but it doesn't work as expected. Palette Dialog doesn't show up.&lt;/P&gt;
&lt;P&gt;I have read related topics on this forum, but so far no success. The script show only small dialog with 'Stop addin' message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the sample code from&amp;nbsp;current (January, 17th, 2019) this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-F0068478-49F0-4E5E-9BAD-3116D8FCBCAF" target="_blank"&gt;Programming Interface/Sample Programs/User Interface/General/Palette Sample&lt;/A&gt;&amp;nbsp;web page updated and correct? Or should I use the code from the post above?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The .html file is in the same directory as the .py code. Anyhow I tried to trace the python code. I set a break point into the&amp;nbsp;ShowPaletteCommandExecuteHandler.notify. It looks like the code doesn't even reach the method. (the handler is never called)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How is the correct string-path for the html file?&amp;nbsp; Relative path works? How to write absolute path?&lt;/P&gt;
&lt;P&gt;Is for example this correct on Windows PC:&amp;nbsp; &amp;nbsp;'D:\\GitHub\\Fusion360\\Scripts\\ApiSamplePalette\\palette.html'&amp;nbsp; &amp;nbsp;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 11:47:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/palette-sample-not-working/m-p/8529421#M18349</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-01-17T11:47:17Z</dc:date>
    </item>
  </channel>
</rss>

