sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Synchronizing Multiple WebDialogs

    Scheduled Pinned Locked Moved Developers' Forum
    20 Posts 6 Posters 1.6k Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      MartinRinehart
      last edited by

      Anybody have a solution for the general problem: how can I get WebDialogs to talk to each other?

      Or the specific problem? I need this sequence of events:

      Ruby opens WDFirst.
      Ruby opens WDSecond.

      WDFirst displays button. User clicks button.

      JS in WDFirst calls Ruby. Ruby prepares and returns JSON packet.

      WDSecond receives "Ready" message. (How? email? Pony Express?)

      WDSecond calls Ruby; Ruby prepares and returns second JSON packet.

      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        @martinrinehart said:

        WDSecond receives "Ready" message. (How? email? Pony Express?)

        http://code.google.com/apis/sketchup/docs/ourdoc/webdialog.html#execute_script
        It's a bit awkward - as you have to compile a Javascript snippet that gets evaluated. I used this to build a JSON string that's sent as an argument to a function. I think you had to properly escape the data as it gets parsed a few times.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • M Offline
          MartinRinehart
          last edited by

          @thomthom said:

          http://code.google.com/apis/sketchup/docs/ourdoc/webdialog.html#execute_script

          I don't understand how this solves the problem.

          I believe it's true that a WebDialog you instantiate via UI::WebDialog.new is unable to execute_script(). Only the WebDialog returned via an action callback can do so. This does not get an alert:

          
          # t.rb
          
          require 'sketchup'
          
          wd = UI;;WebDialog.new "foo", true, "", 100, 100, 100, 100, true
          
          wd.execute_script( 'alert( "hello from foo" );' )
          
          

          If this is true, it's another thing to fix in the docs. Anyone care to confirm or contradict?

          I have one idea, but it's a candidate for a Kolossal Kludge award.

          Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            I've had no problems using .execute_script outside any event callbacks.

            In that test of yours - there is no HTML. Maybe that prevents any scripts from executing..?

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              Also - in that test - the dialog isn't shown...

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                Yup - you need HTML content and show the dialog.

                
                wd = UI;;WebDialog.new "foo", true, "", 100, 100, 100, 100, true
                wd.set_html "<html><body>Hello World</body></html>"
                wd.show
                wd.execute_script( 'alert( "hello from foo" );' )
                
                

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MartinRinehart
                  last edited by

                  @thomthom said:

                  Yup - you need HTML content and show the dialog.

                  
                  > wd = UI;;WebDialog.new "foo", true, "", 100, 100, 100, 100, true
                  > wd.set_html "<html><body>Hello World</body></html>"
                  > wd.show
                  > wd.execute_script( 'alert( "hello from foo" );' )
                  > 
                  

                  I get the dialog, but no alert. Do you get an alert?

                  Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    Yes - that exact sequence give me an alert box.

                    Mind you - I tried this in the console. Maybe the dialogue isn't immediately ready for execute_script is you run this as a continuous script. Maybe some delay is required. (Or have your webdialog JS send a "ready" message back to SU once it's loaded.)
                    sigh Webdialogs isn't smooth sailing... Even though I'm comfortable with HTML/CSS/JS - the communication between SU and webdialogs is .. well... bleh! 🤢

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      MartinRinehart
                      last edited by

                      @thomthom said:

                      Yes - that exact sequence give me an alert box.

                      Mind you - I tried this in the console.

                      Bingo! In the console I get the alert. Now maybe I can bury my Kolossal Kludge.

                      Thanks.

                      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        Ok - so when communicating with Webdialogs:

                        • Initialize a Webdialog object.
                        • Populate with HTML and display the dialog
                        • Wait for a "ready" signal from the dialog before attempting any communication

                        This sounds like the check-list you have to follow in order to reliably establish communication? One for your Webdialog gotacha-thread.

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          RickW
                          last edited by

                          One thing I've learned is to include a callback at the end of my html telling the script that the WebDialog is ready to receive communication, as you mentioned, and as I have mentioned in other threads. 😄

                          RickW
                          [www.smustard.com](http://www.smustard.com)

                          1 Reply Last reply Reply Quote 0
                          • chrisglasierC Offline
                            chrisglasier
                            last edited by

                            @rickw said:

                            One thing I've learned is to include a callback at the end of my html telling the script that the WebDialog is ready to receive communication, as you mentioned, and as I have mentioned in other threads. 😄

                            Precisely, if you need a web dialog the web dialog has to run the show. Anything else is a pas de deux to nowhere.

                            With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                            1 Reply Last reply Reply Quote 0
                            • M Offline
                              MartinRinehart
                              last edited by

                              @rickw said:

                              One thing I've learned is to include a callback at the end of my html telling the script that the WebDialog is ready

                              I don't understand. Maybe you are solving a different problem. Here's my situation, simplified to a single WebDialog.

                              User clicks button. (There is no button to click until the <body> is built, so calls from a button click can't happen prematurely - I think.) JS calls Ruby callback requesting data. Ruby fetches data and returns it to JS.

                              I think the "Ruby, data please" call also implies "Ruby, I'm ready". No? What am I missing?

                              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                              1 Reply Last reply Reply Quote 0
                              • thomthomT Offline
                                thomthom
                                last edited by

                                Ah! Didn't notice that the .show and .show_modal where block methods. That's useful to know. Saves that extra callback from the webdialog.

                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 Reply Last reply Reply Quote 0
                                • C Offline
                                  cjthompson
                                  last edited by

                                  This gets an alert from a file, at least for me:

                                  wd = UI;;WebDialog.new "foo", true, "", 100, 100, 100, 100, true
                                  wd.set_html "<html><body>Hello World</body></html>"
                                  wd.show{
                                  wd.execute_script( 'alert( "hello from foo" );' )
                                  }
                                  

                                  What problem are you having, exactly?

                                  1 Reply Last reply Reply Quote 0
                                  • M Offline
                                    MartinRinehart
                                    last edited by

                                    @cjthompson said:

                                    What problem are you having, exactly?

                                    Thomthom didn't have a problem. I did.

                                    The problem was that if you called wd.execute_script() after wd.show() (instead of in a block passed to wd.show() ) it failed.

                                    Thank you for your clear code. Do you happen to know any more about when the show() block is actually executed than what the docs report?

                                    Thanks.

                                    Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                    1 Reply Last reply Reply Quote 0
                                    • C Offline
                                      cjthompson
                                      last edited by

                                      not really. I pretty much just stumbled across it, and saw that it worked.

                                      I don't really know much about DOM events or even html in general. Maybe you know how to execute a script that will show what state the browser is in, and execute that on show?

                                      1 Reply Last reply Reply Quote 0
                                      • J Offline
                                        Jim
                                        last edited by

                                        @martinrinehart said:

                                        Do you happen to know any more about when the show() block is actually executed than what the docs report?

                                        I assume it would be possible to devise some tests to track when it happens, using a javascript logger or something.

                                        Hi

                                        1 Reply Last reply Reply Quote 0
                                        • M Offline
                                          MartinRinehart
                                          last edited by

                                          @jim said:

                                          I assume it would be possible to devise some tests to track when it happens, using a javascript logger or something.

                                          Jim, this is a sensitive and tender area! My VisMap did not originally support the Mac because of timing/thread issues. The simple answer was to postpone the start of Ruby/JS chat by forcing the user to click an otherwise unnecessary startup button.

                                          If you find a tool that actually lets you step through the states of the browser, it would be invaluable.

                                          Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                          1 Reply Last reply Reply Quote 0
                                          • chrisglasierC Offline
                                            chrisglasier
                                            last edited by

                                            @martinrinehart said:

                                            If you find a tool that actually lets you step through the states of the browser, it would be invaluable.

                                            ... for whom?

                                            "This is commercial, for-profit work. At some point there will be a send-me-money feature added. At this point (mid-summer, 2009) that feature does not exist. The whole price right now is feedback. Tell me what works and what's unclear. Major mistakes and minor typos." [source]

                                            Free content/editing from feedback seems as bad as free designs from competitions (much despised around here - example).

                                            With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                                            1 Reply Last reply Reply Quote 0
                                            • 1 / 1
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement