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

    Question about load_handler parameter from load_from_url

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 3 Posters 269 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.
    • S Offline
      Shoff
      last edited by

      That's what I was hoping, but what is the argument that you are passing doing? In the prototype on the api page, it shows that you have to pass an argument, and then it's basically just printing that p argument. What is p supposed to be conceptually?

      class LoadHandler
      
         def onPercentChange(p)
           Sketchup;;set_status_text("LOADING;    " + p.to_i.to_s + "%")
         end
      
         def cancelled?
           # You could, for example, show a messagebox after X seconds asking if the
           # user wants to cancel the download. If this method returns true, then
           # the download cancels.
           return false
         end
      
         def onSuccess
           Sketchup;;set_status_text('')
         end
      
         def onFailure(error_message)
           # A real implementation would probably not use a global variable,
           # but this demonstrates storing any error we receive.
           $last_error = error_message
           Sketchup;;set_status_text('')
         end
      
       end
      
      
      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        I assume a Float value from 0 to 100 representing the percent of the transfer that is complete. Although it may go from 0 to 1, also.

        You don't pass the value - SketchUp calls onPercentChange and provides the value to you.

        Also, p is a bad name for a variable since it is already a shortcut for the .inspect method - come on, Google.

        Hi

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

          How frequently does SketchUp call it? Can I control the interval? Or is it just that I specify the interval at which it does something inside of the onPercentchange method?

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

            @shoff said:

            How frequently does SketchUp call it?

            We on the Ruby end of things have no idea - that is something controlled internally in SketchUp.

            @shoff said:

            Can I control the interval?

            No. All you can do is perform some action with the value given to you in the onPercentChange parameter.

            def onPercentChange(the_percent)
              @your_dialog.execute_script("update_progressbar('#{the_precent}');")
            end
            
            • assumes you have a JavaScript function named "update_progressbar()" available in your WebDialog.

            Hi

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

              hmmm. Yeah, i did something very similar to your onPercentChange definition, and it doesn't look like SketchUp is calling it. I know my javascript works because if I call load_handler.onPercentChange(foo) where foo is a number, then my progress bar updates. When you run load_from_url with the optional load_handler parameter, is SketchUp calling onPercentChange for you?

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

                I think I figured out the problem. onPercentChange doesn't work on a mac. Just tried my code on a PC, and it worked. Guess that means bug report...kind of wish I tested that sooner, would have saved me a lot of time.

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

                  John, did you file a bug report? Here's the link:

                  Error 404 (Not Found)!!1

                  favicon

                  (sketchup.google.com)

                  Hi

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

                    Yes he did.

                    I'm not here much anymore.

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

                      Yeah, I posted a bug report. One more thing worth mentioning for anybody that finds this thread later. When I said that it worked on a PC, I got it to work using Sketchup.status_text=, but it wouldn't work using WebDialog.execute_script. I wrote a little script to slowly count from 1 to 100 and call my javascript each time, so that I could make sure that it wasn't some silly mistake on my end, and that worked fine. So, my assumption is that execute_script is taking forever to get called inside of onPercentChange even for the PC.

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

                        This could be done from the JavaScript too. You could use the onPercentChange to simply set a variable, then use a timer in JS to poll the Ruby script for the value of the variable.

                        Hi

                        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