• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Loading script without restarting?

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 3 Posters 278 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.
  • W Offline
    Wo3Dan
    last edited by 26 Mar 2009, 22:29

    How do I replace a script in my SU's plugins menu without restarting SU.
    Right now when using load'scrip't.rb' through ruby console it adds to the menu the "new option" by applying UI.menu("PlugIns").add_item("new option") in the script.
    Does this mean there is also a stack of loaded scripts after a while. Or is only the text "new option" added to the menu.

    In other words, how can I be sure the script is completely replaced by entering code through ruby console?

    Bear with me, I'm just starting/trying to learn writing ruby.
    Thanks in advance.
    Wo3Dan

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 26 Mar 2009, 22:43

      When you load the script again, it will generally overwrite the old loaded version. There are exceptions. If you had a method defined in the old script that is no longer in the new script, the method will still be active in SU until you reboot SU. But most code changes will get updated. Also, if you are not checking to see if the script has been loaded before adding it to the menu, you will end up with multiple listings of your script in the menu. They will all run the newest loaded version of the script though. And they go away once you restart SU.

      I tend to write code snippets in Jim's awesome webconsole. It lets you not worry about making menu items to run the script. Just hit execute each time you want to test your code. Then once I get a nuch of working code, I take it over to an editor (notepad++ for me). Then once its in there I just save and reopen SU everytime I want to test changes. Or I go back to the webconsole to keep working snippet by snippet. And then go plug the pieces back into my big code in notepad++.

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • W Offline
        Wo3Dan
        last edited by 26 Mar 2009, 23:11

        Thanks for the quick response, Chris.
        So you are saying that you cannot avoid getting multiple listings of the reloaded script. Well, good to hear that the code is updated.
        I can understand about a skipped method still being active although I wasn't expecting that.
        My problem is (and I guess it will be for a long time) to get the syntax memorized in my grey brain cells and see how things are put together. So I need to take apart simple examples, modify them to see what happens until I "see the light". ☀

        What exactly is Jim's awesome webconsole. Where do I find it and how can it help me in understanding what scripts/script changes do in SU?

        Thanks again.
        Wo3Dan

        1 Reply Last reply Reply Quote 0
        • C Offline
          Chris Fullmer
          last edited by 26 Mar 2009, 23:32

          Jim websoncole is here:

          Link Preview Image
          Plugin: WebConsole

          2010-05-22 * Eliminated the Results textarea in favor of SketchUp's Ruby Console. * Automatic resize of the code textarea. * Changed ...

          favicon

          (sketchuptips.blogspot.com)

          Install it and I think you'll love it. While the ruby console allows only a single line of code at a time, the webconsole lets you type in all you want, and then just click execute to run it all.

          So I rarely set up menus in the webconsole. I don't want to load the snippet into a menu, just test it out - repeatedly.
          ` model = Sketchup.active_model
          ents = model.entities
          sel = model.selection

          puts "--"
          puts sel
          puts "--"
          puts sel.to_a
          puts "--"`

          I often do much more than that, but somtimes it only take 5 or 10 lines to figure out what I want.

          And for the menus, yes you can keep it from loading repeatedly. This is in the utilities.rb plugin that comes with sketchup. It checks to see if it was loaded already with the if( not file_loaded?(__FILE__) ) line. If its not loaded, then it adds the menu items. After that, it then adds the file to the list of loaded files with the file_loaded(__FILE__) line.

          # Add an Animations sub-menu to the Camera menu
          if( not file_loaded?(__FILE__) )
              add_separator_to_menu("Plugins")
              animation_menu = UI.menu("Plugins").add_submenu("SubMenu")
              animation_menu.add_item("Plugin Title") {methodname}
          end
          
          file_loaded(__FILE__)
          

          That is how you should load full plugins so that they register themselves with Sketchup's loaded plugins and then they won't keep adding themselves to the menu system.

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • W Offline
            Wo3Dan
            last edited by 27 Mar 2009, 08:12

            Good morning Chris and all,

            Just woke up, thank you for the link to the webconsole.
            It looks like this being the best of both worlds for what I'm doing.
            (didn't like the one liners nor the restart etc.)
            So I'm going to try it. It might take some time for any next questions for I like trying things out to get a better understanding.
            Who knows, one day I might even come up with my own usefull script here.
            One step at the time though!

            I realy appreciate your help!!!
            Wo3Dan

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 27 Mar 2009, 12:04

              One trick I've used is to create the menu item in the Ruby console, and have it just load a file.

              So in the Ruby console, you enter something like:

              
              UI.menu("Plugins").add_item("Snippet Loader") { load "snippet.rb" }
              
              

              And then in your snippet.rb file...

              
              # snippet.rb
              m = Sketchup.active_model
              e = m.entities
              s = m.selection
              
              puts "=" * 25 # add a divider for visual separation in the output
              
              # Do your test...
              
              

              So now you get to use your favored editor to edit the snippet.rb file, and assign a shortcut to load it and run it.

              Hi

              1 Reply Last reply Reply Quote 0
              • W Offline
                Wo3Dan
                last edited by 27 Mar 2009, 12:50

                Jim,

                I see you are the creater of this webconsole script.
                Thank you for this great tool.

                What you just wrote in previous post, is this about creating route different from the webconsole in SU, to let you write outside SU and then run these snippets inside SU?
                I'll have a better look and see if I can get it to work if I understand.
                The webconsole is a huge improvement for a poor soul like me.
                (I must have missed it since it is from 2006)

                Thanks again,
                Wo3Dan

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

                Advertisement