• Login
sketchucation logo sketchucation
  • Login
Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

[Code] custom file_loaded() and file_loaded?() v2.0.0

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 4 Posters 6.3k Views 4 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
    Dan Rathbun
    last edited by 21 Jun 2012, 03:47

    Ok I guess I need to explain how to use a mixin module, using the global include() method.

    In the example below (and in the template,) you change the word "Author", to YOUR toplevel module name.

    This LoadUtil module is written FOR PRIVATE USE. append_features will not let it be included into any one else's namespace.
    It makes Author::LoadUtil a private module !!

    YOU use it by including it in your sub-modules.

    # file; "Author/NiftyPlugin/Setup.rb"
    module Author;;NiftyPlugin
    
      require("Author/LoadUtil")
      include(Author;;LoadUtil)
    
      unless file_loaded?("NiftyPlugin;Setup")
        # do code to setup menus
        # do code to setup toolbars
        file_loaded("NiftyPlugin;Setup")
      end
    
    end
    

    In the above code sample, the file_loaded and file_loaded? that get called, are the ones you mixed in (which LOCALLY overrode the global ones, that are defined in "Tools/sketchup.rb")

    You have your OWN @@loaded_files array, up in module Author, that you keep all to yourself, and there will never be any clashes caused by OTHER people's scripts. (Now you can make a mistake and cause a clash, but you can fix it, without having to get someone else to change their code.)

    I'm not here much anymore.

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 21 Jun 2012, 07:12

      πŸ‘ πŸ‘

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

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 24 Jun 2012, 10:59

        The only purpose of file_loaded appears to be as "menu guards" that prevent duplicate menu items from being created if the file is loaded more than once. This is helpful when developing a plugin, but what is the point in a released plugin? Better to not add elements to either a global $loaded_files or a namespaced equivalent.

        Hi

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 24 Jun 2012, 21:35

          Sometimes it's easier to just "go with the flow.."

          Keeping two editions (a debug, and a release,) for every script and plugin just confuses things.

          Also there has been historical "bugs" and "quirks" in the way the Ruby's require worked. Remember that until SU 8.x, everyone was still running on the PC with 1.8.0, which had a require that works a bit differently than it does in later versions.

          So.. a historical part of this issues, was also dealing with require's wanting to load the same file more than once.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • A Offline
            Anton_S
            last edited by 27 Jun 2012, 23:20

            Here is jst a little mistake in the script:
            error.png
            script.png
            In append_features, mod.name returns "". Where first interacted mod itself is #<Class:Anton>.

            Since, I quite don't know what should there be, I can't fix it. So Dan fix it please πŸ˜„

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 28 Jun 2012, 06:22

              Anton, I set you a personalized copy of v2.0.0 by Private Message.

              Everyone else... you can get the generic template v2.0.0 update, in the first post.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • D Offline
                Dan Rathbun
                last edited by 28 Jun 2012, 06:23

                Now.. that said.. yes there are alternatives.

                Sometimes I use defined?

                If the module var is going to be @@menu, then I use:

                unless defined?(@@menu)
                  @@menu=UI.menu('Plugins')
                  # define items, etc
                end
                

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Dan Rathbun
                  last edited by 28 Jun 2012, 06:24

                  @anton_s said:

                  In append_features, mod.name returns "". Where first interacted mod itself is #<Class:Anton>.

                  I did say it was not tested.. so it's at concept level.

                  It cannot get past the mod.name test, because I tried to include it into module Anton's proxy class, which is anonymous, so it has no name. (That is why mod.name == "") I thought it would call the name method of the Anton module, but it did not.

                  I will have to modify the tests a bit.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Anton_S
                    last edited by 28 Jun 2012, 07:07

                    @dan rathbun said:

                    Anton, I set you a personalized copy of v2.0.0 by Private Message.

                    Lol, I feel speacial now.

                    πŸ‘ πŸ‘ πŸ‘

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Dan Rathbun
                      last edited by 30 Jun 2012, 06:25

                      OK.. so, for those you who have read the thread.. looked at the template, and scratch your head and wonder why all the complexity to control a private array ??

                      Answer.. it's just an example, of a private library mixin module.

                      In practice, you can rename the mixin module to whatever you like... and insert whatever proprietary functionality you wish to include in only YOUR plugins (ie, methods in the mixin sections, other class variables and constants, etc.) whilst not allowing some other "hack" to use those features in their plugins.

                      I'm not here much anymore.

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

                      Advertisement