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

    Help with WebDialogs

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 164 Views 3 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.
    • J Offline
      joshb
      last edited by

      Hi,
      I'm trying to follow the techniques outlined in the link below to interact between ruby and a web dialog
      http://sketchupapi.blogspot.com/2008/02/sharing-data-between-sketchup-ruby-and.html

      I've got the Javascript to Ruby callbacks working just fine but am running into some weirdness going the other way. My code is below. Whats happening is that as is, the javascript doesnt execute. If I uncomment the messagebox line, then it does. Are there any known quirks to be aware of? Or is the messagebox line doing something that is required and can be accomplished in some other way?

      I'm new to ruby and appreciate the help.
      Thanks,
      Josh

      def LaunchGenericEditor

      create a new web dialog

      editor = UI::WebDialog.new("Generic Editor", false, "Generic Editor", 275, 100, 50, 50, true)

      load the editor html and show the web dialog

      html_path = File.dirname(File.expand_path(FILE))
      html_path << "/GenericEditor.html"
      editor.set_file(html_path)

      editor.show

      strCommand = "addRowTest(5)"
      #UI.messagebox strCommand
      editor.execute_script(strCommand)
      end

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

        You need to wait for the HTML to load.

        I use a callback from the JS in the WebDialog to SketchUp when the HTML DOM has loaded. When the DOM has loaded you can start using wedialog.execute_script.

        For more reading on WebDialogs: http://forums.sketchucation.com/viewtopic.php?f=180&t=23445&p=324694

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

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          Josh.. ONLY class and module identifiers are capitalized camel-case. Methods are lowercase with underscore separated words.

          And you need to keep the 'handle' to the dialog outside the method. (or the dialog will go out of scope when the method call ends.) I usually have the dialog setup method return the handle as the last statement.

          I'll use a instance var or a module var to hold the handle.

          module Josh
            module WebEditor
          
              @@editor = nil
          
              class << self
                def launch_generic_editor()
                  # setup code here
                  return editor
                end #def
              end # proxy class
          
              # further down
          
              if not @@editor
                @@editor = launch_generic_editor()
              end
          
              @@editor.show()
          
            end # WebEditor
          end # Josh
          

          I'm not here much anymore.

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

            Thanks guys! Calling back to ruby from the onload did the trick. I'm obviously new to ruby and appreciate all the pointers.

            Thanks again for the help
            Josh

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @joshb said:

              I'm obviously new to ruby and appreciate all the pointers.

              Pay attention to the "Sticky" threads at the top of the forum. (They have the "S" in them.)

              This will get you going:
              Ruby Newbie's Guide to Getting Started

              I'm not here much anymore.

              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