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

    A few newbie questions...

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 6 Posters 393 Views 6 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.
    • F Offline
      Frankn
      last edited by

      Let me start by apologizing for what will undeniably be a series of easy things for anyone here to do... but I've searched and tested for answers for the last few days and can't seem to figure these out.

      First... I know how to add an item to a menu and even creat a submenu. But how do I add servel scripts/items to a menu I already created? Example... I created a series of 3(so far) ruby scripts but I'd like for all of them to be in the same submenu... Plugins -> SUBMENU -> ITEM1 -> ITEM2...

      Second... and this one I haven't even figured out at all!!! How do I create components? Example... my script creates a cabinet, how do I make every panel a seperate component?

      Third... how can I call or the scripts from a subfolder within the plugins folder? I want to put all the scripts I create inside a sinlge folder for better organization.

      If it's any help I'm working with the cab.rb script and trying to modify it for my needs...

      Thanks in advance for your time,
      Frank

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


        More...

        6) Read: [code] SketchupExtension and rbs rubies

        Take note of the sections:

        • Manage your "filespace"* Manage your "namespace"

        7) MODULES

        • [info] Using Ruby Modules
        • [talk] Using Ruby Modules
        • Modules - are they needed if ...

        😎 See my post at Google Groups on File Spanning:

        File Spanning (start at post 4)

        I'm not here much anymore.

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

          1) It would be best if you separate each of your different questions into separate posts, with a specific "topical" question as the title.

          2) But first... try to use the forum search box to see if there are already topic threads on each specific question. Read those first, and if you have more questions, reply post to the end of that thread (rather than start a new one.)

          3) Visit my Ruby Newbie's Guide to Getting Started

          Follow the advice, read the tutorials for standard Ruby, and those specific to Sketchup. Collect the references (CHMs and PDF books, etc.)

          4) Look at the examples available through the Code Snippets sticky post, take note that I have a "work in process" By Subject index, as the 2nd post in that thread.

          5) Read the Ruby code, written by the better authors (especially those who use modules to wrap their code.) Beware, many, if not all of the Google examples, do not follow best practices.

          I'm not here much anymore.

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

            @frankn said:

            First... I know how to add an item to a menu and even creat a submenu. But how do I add servel scripts/items to a menu I already created? Example... I created a series of 3(so far) ruby scripts but I'd like for all of them to be in the same submenu... Plugins -> SUBMENU -> ITEM1 -> ITEM2...

            The best example for you to read, would be one I helped "cleanup" for another guy (Andrew,) who was experienced coding, but not in Ruby.

            Get the plugin here: [Plugin] Voxelize

            and:

            1. Look at how it's double Module wrapped in a plugin namespace, within the author's toplevel namespace.

            2. How we have constants at the top for "tweeking" the menus, and how we use module variables (they begin with "@@",) to hold a reference to the menus and submenus, that are used later to add items.

            "Later" can also mean in other scripts by the same author, that are are wrapped within the same module namespace.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • F Offline
              Frankn
              last edited by

              Thanks for all the links Dan I really do appreciate your help and time you took to show me how things work around here. Like they say, give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Looks like I have a lot of reading to do. πŸ˜„

              In my defense I have zero programming experience and I've search a whole lot but just haven't been able to find answers that made sense to my newbie brain. πŸ˜„

              Frank

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

                @frankn said:

                In my defense I have zero programming experience and I've search a whole lot but just haven't been able to find answers that made sense to my newbie brain.

                We all were newbies once. Take it slow and start by doing simple things first to gain confidence. Then experiment with more complex advanced projects. Sometimes it requires re-reading something several times until it "sinks" in.

                BTW.. the Voxelize plugin has an example of creating Components also.

                I'm not here much anymore.

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

                  @frankn said:

                  Third... how can I call or the scripts from a subfolder within the plugins folder? I want to put all the scripts I create inside a sinlge folder for better organization.

                  To load something only once use the Ruby method require()

                  Assume you have an author subdir named "FrankFolder", and a script in that folder named "cubeutil.rb":
                  require('FrankFolder/cubeutil.rb')

                  The require() method uses the $LOAD_PATH array (aka $:,) to find files. The paths to the standard Plugins and Tools folders are added to the $LOAD_PATH by Sketchup.
                  The method also checks the $LOADED_FEATURES array (aka $",) and does not reload the script if it has already been loaded.

                  If you wished to reload a script, regardless of whether it had been loaded before, you would use the Ruby method load() (unless it's a scrambled rbs file, then you must use the Sketchup.load() method.):

                  load('FrankFolder/cubeutil.rb')
                  or
                  Sketchup.load('FrankFolder/cubeutil.rbs')

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    archidave
                    last edited by

                    Do you know if this is still the case?
                    I'm trying to reload an rbs file to perform a live patch of some methods;

                    Sketchup.load('file_path.rbs') returns 0 the first time, then false on subsequent calls, same as Sketchup::require

                    Is there a global equivalent to $" that SU stores the list of files in, that I can delete the file name from to force a reload?

                    thanks

                    SU 8.0 M2, Mac

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

                      @archidave said:

                      Do you know if this is still the case?
                      I'm trying to reload an rbs file to perform a live patch of some methods;

                      Sketchup.load('file_path.rbs') returns 0 the first time, then false on subsequent calls, same as Sketchup::require

                      Is there a global equivalent to $" that SU stores the list of files in, that I can delete the file name from to force a reload?

                      thanks

                      SU 8.0 M2, Mac

                      $loaded_files

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

                        The $loaded_files global is used as a "menu guard" to guard against duplicating menu items when re-loading plugins. Sketchup#load does not look at $loaded_files as far as I know.

                        If I remember, Sketchup#load is an alias for Sketchup#require, so looks at $LOADED_FEATURES global for loaded files.

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • tt_suT Offline
                          tt_su
                          last edited by

                          @jim said:

                          If I remember, Sketchup#load is an alias for Sketchup#require, so looks at $LOADED_FEATURES global for loaded files.

                          Correct. Annoyingly Sketchup::load call Sketchup::require - we have a bug filed for that.
                          And $LOADED_FEATURES is indeed where you want to remove the entry from the RBS you want to reload.

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

                            And depending upon version, either the relative or absolute path, or both script path(s), (sometimes downcased,) were pushed into the $LOADED_FEATURES array.

                            Sometimes we need a table to keep track of things like this from version to version.

                            I'm not here much anymore.

                            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