Palette Send Info to HTML Error

Palette Send Info to HTML Error

Anonymous
Not applicable
1,034 Views
4 Replies
Message 1 of 5

Palette Send Info to HTML Error

Anonymous
Not applicable

Hi,

I implemented a palette using the Palette Sample code. However, clicking my sendInfoToHTML button causes an error. I have attached a screenshot of the error down below as well as a screenshot of the string I am trying to send as the argument in the line 

palette.sendInfoToHTML('send', string1).

 

Thank you.

0 Likes
1,035 Views
4 Replies
Replies (4)
Message 2 of 5

marshaltu
Autodesk
Autodesk

Hello,

 

From the error information, it looked you didn't return a string from html/js back to Fusion. In our sample, we just return "OK". 

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi,

 

I also returned 'OK' at the end of my palette.html file. I have attached a screenshot of my code below. Could there be any other reason for that error?

0 Likes
Message 4 of 5

marshaltu
Autodesk
Autodesk

Hello,

 

Unfortunately I cannot think other reasons out. It would be great if you can send me(marshal dot tu at autodesk dot com) or post a sample script to reproduce the issue.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi,

 

I don't think I could send the sample script to reproduce the issue as it utilizes classes from many different files but I have attached the HTML file for the assertion palette below. I have checked that a non empty string is passed by the sample script to the function in the HTML file so I believe the error is not in the script. I hope this helps.

 

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <p id='p1'>Click the button below or use the "Send info to HTML" command in the ADD-INS panel.</p>
        <!-- <button type='button' onclick='sendInfoToFusion()'>Click to send info to Fusion</button>  -->
        <br /><br />

    </body>
    <script>
        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.
					if(typeof(data)=="string"){
						var string1 = data.substring(1, data.length-1);
						var parent_list = string1.split("}");
						var assertions_text = "Assertion Tracker <br>";
						for(i=0; i<parent_list.length; i++){
                            var s = parent_list[i];
                            var parent = s.substring(1, s.indexOf(": ")-1);
                            assertions_text = assertions_text + parent + "<br>";
                            var assert_list = (s.substring("{"+1)).split(",");
                            for(i=0, i<assert_list.length; i++){
                                var t = assert_list[i];
                                var assertion = t.substring(1, s.indexOf(": ")-1);
                                var state = t.substring(t.indexOf(":")+1, t.length);
                                if(state.indexOf('false')!=-1){
                                    state = "passed";
                                }
                                else{
                                    state = "violated";
                                }
                                assertions_text = assertions_text + assertion + " " + state + "<br>";
                            }
						}
						document.getElementById('p1').innerHTML = assertions_text;
					}
					else{
						document.getElementById('p1').innerHTML = typeof(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';
        }};
    </script>
</html>

 

0 Likes