sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    WebDialog.write_image troubles.

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 507 Views 5 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.
    • B Offline
      bwerst
      last edited by

      I'm trying to create web dialogs to display component information that I would like to be able to save as an image which can then be placed into a model. The purpose is to get rich text instead of the limitations of the text box or 3D text tools.

      The idea was started after pondering a suggestion of ThomThom's to use WebDialogs.

      So I created a really generic html file called 'wrwtools/generictest.html':

      
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      	<head>
      		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      		<title>Generic HTML Test Page</title>
      	</head>
      	<body>
      		<h1>Basic Web Dialog</h1>
      		<table>
      			<tr><th>&nbsp;</th><th>Value</th></tr>
      			<tr><td>DMX Address</td><td>123</td></tr>
      			<tr><td>Channel</td><td>101</td></tr>
      			<tr><td>Fixture Number</td><td>32</td></tr>
      		</table>
      	</body>
      </html>
      
      

      Then I created a very generic test application script:

      
      require 'sketchup.rb'
      
      #-----------------------------------------------------------------------------
      module WRW_textpanes
        # Global variable for where export images will go.
        # Global variable for where template files are stored.
      
        ### MENU & TOOLBARS ### --------------------------------------------------
        
        unless file_loaded?( File.basename(__FILE__) )
          root_menu = ($wrw_menu) ? $wrw_menu ; UI.menu('Plugins')
          root_menu.add_item('Web Dialog Write Test')  { self.webdialogwritetest }
        end
        
        def self.webdialogwritetest
          html_dialog = UI;;WebDialog.new("Web Dialog Test", true,"", 700, 600, 150, 150, true);
          path = Sketchup.find_support_file "wrwtools/generictest.html","Plugins"
          html_dialog.set_file path
          html_dialog.show
          
          # Simple html dialog shown now see if it will save.
      
           html_dialog.write_image "c;/production/sketchup/wrwtesting/shouldbewebdialog.jpg"
        end
          
      end #module
      #-----------------------------------------------------------------------------
      file_loaded( File.basename(__FILE__) )
      

      I was hoping shouldbewebdialog.jpg would be an image of the simple html instead I'm getting an image that is blank tan box about 300x300 in size. Its kind of like an empty messages portion of the "ruby console" dialog box.

      I did have additional x,y,height,width type values after the filename, but removed them after reading this post http://forums.sketchucation.com/viewtopic.php?f=180&t=17047&start=285#p231504 but I'm still getting the same results.

      I'd appreciate any help.

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

        I'm guessing that the Webdialog is not given time to generate the content before you try to make a screenshot of it.

        I think you need to add a JS that uses the window.onload to make a callback back to your Ruby script telling you it's ready.

        You could also try to provide a block with WebDialog.show - but I'm not sure if this event is triggered after the content loaded. And I've had problems with this on OSX.

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

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Using dialog.show{###do the stuff} does run 'the stuff' after the dialog loads, you can always add a sleep(0.333) as the first thing in the {} block so that things are definitely visible...

          TIG

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

            @tig said:

            Using dialog.show{###do the stuff} does run 'the stuff' after the dialog loads, you can always add a sleep(0.333) as the first thing in the {} block so that things are definitely visible...

            Won't sleeping the Ruby script prevent the webdialog from doing anything as well?

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

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              NO... the html is loaded separately and ignores the sleep().
              You can see this if you have a simple html - let it set a piece if text with an id="text1" and value="cat" in the html.
              Then need a ' populate()' def in your ruby script that changes that id "text" to value="dog".

              def populate()
                js=("document.getElementById(\"text1\").setAttribute(\"value\",\"dog\");")
                @dlg.execute_script(js)
              end
              

              Then you use something like...
              @dlg.show{sleep(5);self.populate()}
              The html's web-dialog opens and it says 'cat'... then after 5 seconds it changes to say 'dog'... πŸ˜‰

              TIG

              1 Reply Last reply Reply Quote 0
              • AdamBA Offline
                AdamB
                last edited by

                you sure, TIG?

                I'm certain I tried doing a html+js progress bar and found its actually run from inside the Ruby execution loop.

                Developer of LightUp Click for website

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

                  Hold everything... your all going down the wrong path.

                  It's a bug in the write_image method.
                  I detailed all the funky things that didn't work in one of the topics.. likely the API docs topic.

                  Ok link: UI::WebDialog.write_image (API Doc typos and questions)

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    @adamb said:

                    you sure, TIG?
                    I'm certain I tried doing a html+js progress bar and found its actually run from inside the Ruby execution loop.

                    Yes I've just done it!
                    Sleeping will slow the changes to the displayed dialog but it won't stop it loading as it is currently set...

                    TIG

                    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