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

Execute_script trouble

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 5 Posters 244 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.
  • K Offline
    kdasilva
    last edited by 20 Feb 2011, 01:04

    Hello, I am starting to get the hang of the webdialogs when being used to makes changes in Sketchup, however I have hit a snag while attempting to use the execute_script.

    How do I format the information I am trying to pass to JS through the a functions parameters. In my simple test of just trying to pass a string in the parameters and having it printed in the HTML file i keep getting an error message stating: 'test' is undefined, sounds to me like its not taking its value as a string...or I'm not formating it right..or defining it? (from what i have looked at I haven't seen a need to define it)

    Ruby (this is inside an action_callback that works fine)

    
        updated_visions_div = "test"
        js_update_command = "UpDateVisionList("+ updated_visions_div +")"
        web_dialog.execute_script(js_update_command)
    
    

    JavaScript

    
    function UpDateVisionList(incoming)
     {
     	document.getElementById("field_of_visions").innerHTML = incoming;
     }
    
    

    Once I hit the button that triggers the command a scripting error in the webdialog appears telling me "test" is undefined

    I have played with a few different ways, but from what I have read I don't see why this is not working. Most likely I am missing something obvious! 9 time out of 10 thats the case anyways. Could someone please educate me on whats up?

    Cheers~
    Korbin

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 20 Feb 2011, 01:10

      Try making
      js_update_command = "UpDateVisionList("+ updated_visions_div +")"
      as
      js_update_command = "UpDateVisionList(\""+updated_visions_div+"\")"

      TIG

      1 Reply Last reply Reply Quote 0
      • K Offline
        kwalkerman
        last edited by 20 Feb 2011, 01:45

        Not sure if this is what is tripping you up, but I usually use a ";" at the end of my javascript command. JS is pretty picky about semi colons:

        js_update_command = "UpDateVisionList("+ updated_visions_div +");"

        1 Reply Last reply Reply Quote 0
        • K Offline
          kdasilva
          last edited by 20 Feb 2011, 02:38

          @tig said:

          Try making
          js_update_command = "UpDateVisionList("+ updated_visions_div +")"
          as
          js_update_command = "UpDateVisionList(\""+updated_visions_div+"\")"

          awesome! that totally worked, and i know i wouldn't of thought to do that myself.

          So do those escapes keep the quotations around the word so JS knows its a string and not some undeclared variable?

          Thanks a ton TIG

          (It worked without adding the ;, but thanks for the response)

          1 Reply Last reply Reply Quote 0
          • T Offline
            tbd
            last edited by 20 Feb 2011, 10:21

            OT: speaking of semicolons - they are not needed unless a very specific case - see http://mislav.uniqpath.com/2010/05/semicolons/

            SketchUp Ruby Consultant | Podium 1.x developer
            http://plugins.ro

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 20 Feb 2011, 14:04

              @kdasilva said:

              So do those escapes keep the quotations around the word so JS knows its a string and not some undeclared variable?

              Yes. The string you send to execute_script is processed by JS eval() in the webdialog. So remember that all strings you send to execute_script is processed and evaluated twice, once in Ruby and once in JS.

              Though, the code will be easier to re4ad and understand if you avoid escaping quotes.
              js_update_command = "UpDateVisionList('#{updated_visions_div}')"

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

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

              Advertisement