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

    Dialog box showing counter

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 2 Posters 764 Views 2 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.
    • D Offline
      driven
      last edited by

      hi

      I made an experimental one that counts items as they are created, is this the sort of thing you mean?
      I see if I can find the link to the discussion...

      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        this is the one I can find at the moment, it's just a countdown from 40...

        it should be wrapped in your namespace, but runs as a snippet...

        there's a 'typematic' example somewhere on this forum that shows one way of extending this code...

        I'll keep digging, but I often loose these sorts of experiments...

        john

        
           @bars = ""
           @count = []
           @maxtimes = 40 #this value can be calculated
           @dlg = UI;;WebDialog.new()
           @dlg.set_size(100,100)
           RUBY_PLATFORM =~ /(darwin)/ ? @dlg.show_modal() ; @dlg.show()
        
        
           def html(run=true)
              html =  %Q(
                 <!DOCTYPE html>
                 <html>
                 <head>
                    <meta http-equiv="content-type" content="charset=UTF-8" />
                    <meta http-equiv="MSThemeCompatible" content="Yes" />
                    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
                    <style>
                    body {
                       background-color;grey;
                       color;white;
                       font-family;sans-serif;
                       font-style;bold;
                       font-size;40px;
                    }
                    .upd {
                       height;40px;;
                       margin-left; auto ;
                       margin-right; auto ;
                       text-align;center;
                    }
                    </style>
                 </head>
                 <body>
                 <div class="upd">
                 #{@bars}
                 </div>
                    <script>
                       var run = #{run};
                       if (run) setTimeout(function(){window.location='skp;auto2ruby';}, 200);
                    </script>
                 </body>
                 </html>
              )
              html
           end
        
           def addbar
               @bars = (@maxtimes - @count.length).to_s
               @count << %Q( )
           end
        
           def do_this
              addbar
              #add more features...
              if  @count.length > @maxtimes
                 @dlg.set_html(html(false))
              elsif  @count.length == @maxtimes
                 @dlg.set_html(html(false))
                 @dlg.close
              else
                 @dlg.set_html(html)
              end
           end
        
           @dlg.add_action_callback("auto2ruby") {|d,params|
               do_this
           }
        
           @dlg.set_html(html)
        
        
        

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          I reconstructed this one, to show geometry counting...
          Click to run gif...

          @vec2 = []
          
            def self.rubyaction
              ents = Sketchup.active_model.active_entities
              gp = ents.add_group() # Square Polygon
              pts = [ Geom;;Point3d.new(-5,-5,0), Geom;;Point3d.new(5,-5,0), Geom;;Point3d.new(5,5,0), Geom;;Point3d.new(-5,5,0) ] 
              vec = [10,0,0] 
              tr = Geom;;Transformation.new( vec ) 
              # Create som polygons for testing.. 
              polys = {} 
              @vec2.empty? ? (@vec2 = vec.clone) ; (@vec2 = @vec2) 
              polys[0] = pts.collect{|pt| pt.offset(@vec2) } 
              @vec2.offset!([15,10,0]) 
              # Mesh 
              msh = Geom;;PolygonMesh.new 
              for k,v in polys 
                msh.add_polygon(v) 
              end 
          
              group = Sketchup.active_model.active_entities.add_group 
              group.entities.fill_from_mesh(msh, true, 12)
              Sketchup.send_action("viewZoomExtents;") 
            end
             
          @bars = "" 
          @count = [] 
          @maxtimes = 40 #this value can be calculated 
          @dlg = UI;;WebDialog.new() 
          @dlg.set_size(100,100)
          @dlg.set_position(100,100) 
          RUBY_PLATFORM =~ /(darwin)/ ? @dlg.show_modal() ; @dlg.show() 
          
             def html(run=true)
                html =  %Q(
                   <!DOCTYPE html>
                   <html>
                   <head>
                      <meta http-equiv="content-type" content="charset=UTF-8" />
                      <meta http-equiv="MSThemeCompatible" content="Yes" />
                      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
                      <style>
                      body {
                         background-color;grey;
                         color;white;
                         font-family;sans-serif;
                         font-style;bold;
                         font-size;40px;
                      }
                      .upd {
                         height;40px;;
                         margin-left; auto ;
                         margin-right; auto ;
                         text-align;center;
                      }
                      </style>
                   </head>
                   <body>
                   <div class="upd">
                   #{@bars}
                   </div>
                      <script>
                         var run = #{run};
                         if (run) setTimeout(function(){window.location='skp;auto2ruby';}, 200);
                      </script>
                   </body>
                   </html>
                )
                html
             end
             
          def addbar 
            @bars = (@maxtimes - @count.length).to_s
            @count << %Q( ) 
            rubyaction
          end 
          
          def do_this
            addbar #add more features... 
            if @count.length > @maxtimes 
              @dlg.set_html(html(false))
            elsif @count.length == @maxtimes
              @dlg.set_html(html(false))
              @dlg.close 
            else 
              @dlg.set_html(html) 
            end 
          end 
               
               @dlg.add_action_callback("auto2ruby") {|d,params| do_this } 
               @dlg.set_html(html)
          

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            found the one with the cubes...web_dlg_progress_singles.rb

            john

            learn from the mistakes of others, you may not live long enough to make them all yourself...

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              glad it helped and sorry I couldn't find a fully commented version as I made loads of variants...

              the show/show_modal was there to stop the dialog disappearing on a mac if you carried on modelling whilst it ran...

              the format is an shorthand if statement signified by the ? and the else by the colon...
              as a one-liner it is equivalent to

              if RUBY_PLATFORM =~ /(darwin)/ ; puts "mac SU version"; else puts "PC SU version"; end
              
              RUBY_PLATFORM =~ /(darwin)/ ? (puts "mac SU version") ;  (puts "PC SU version")
              

              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 Reply Last reply Reply Quote 0
              • S Offline
                sepultribe
                last edited by

                @sawdust_online said:

                Hi Driven,

                What you gave me is far more than I expected. Don't apology. Such short code is not so hard to understand but at first glance I didn't understand why using an array as counter and some other constructions. I had never met html+Javascrit+Ruby as well. That's why I felt a bit confused but your answers make all that clear in my mind.

                another issue
                Do you know how to refresh the dlg content from a script. something like

                
                > for i in 0..2	
                > 	@count += 1
                > 	@dlg.set_html(dlg_html_content())
                > 	
                > 	#how to refresh the dlg content?	
                > 	#dlg.refresh is not available
                > 	#is there a way to force a refresh?
                > 	sleep (1.0/2.0)
                > end	
                > @dlg.close
                > 
                

                Have a good Sunday

                Hi. You can send javascript code to execute it inside the webdialog from sketchup ruby with the execute_script() method.

                if dlg is your webdialog instance object then

                js_command = "location.reload()"
                dlg.execute_script(js_command)

                something like this should work

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  @sawdust_online said:

                  Do you know how to refresh the dlg content from a script.

                  in a more traditional webDialog you can use

                   @dlg.execute_script("window.location.reload();") # forces a reload...
                  
                  

                  the whole point of my original example was to show that you can update a dialog content dynamically without the blocking associated with sleep...
                  using @dlg.set_html(dlg_html_content()) is replacing the page content each time with a fresh eval of dlg_html_content()...
                  so any embedded ruby variables like our #{@count}, #{@one_more_time} will be re-evalued each time the JS timer runs out...

                  For longer delays adjust that timer, using sleep on the ruby side will block SU...
                  this won't, it will simply delay the call back to ruby by 5000 milliseconds...

                  if (run) setTimeout(function(){window.location='skp;auto2ruby';}, 5000);
                  

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    driven
                    last edited by

                    @sawdust_online said:

                    Nevertheless I would have liked to save that bunch of files without blocking SU, webdialog box or not.

                    what type of files are you saving? images, components?
                    I think you can you the same approach as the two geometry making versions I posted...

                    @unknownuser said:

                    the following code seems to do the job! what's your take about it ? may it lead to crash ?

                    for a mac it would be better if you used

                    RUBY_PLATFORM =~ /(darwin)/ ? @dlg.show_modal() ; @dlg.show()
                    

                    bring_to_front doesn't achieve the same thing unless it was show_modal before the any focus change...

                    I don't see why you need the timer, any short wait will happen anyway while the file is being written...

                    BTW. sleep(0.25) will work the same as, but looks more like ruby than the fractional floats to me...

                    john

                    learn from the mistakes of others, you may not live long enough to make them all yourself...

                    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