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!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Module depth: Good Practices

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 726 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.
    • hsmyersH Offline
      hsmyers
      last edited by

      I've a extension naming question regarding module nesting. Which is it, 1, or 2 levels? I.E.:

      
      Module HSMNameOfModule
      
      

      or,

      
      Module HSM #Author namespace
        Module NameOfModule #extension namespace
      
      

      I have foggy memories of seeing 3 deep nesting but have forgotten the details.

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @hsmyers said:

        I've a extension naming question regarding module nesting. Which is it, 1, or 2 levels? I.E.:

        
        > Module HSMNameOfModule
        > 
        

        or,

        
        > Module HSM #Author namespace
        >   Module NameOfModule #extension namespace
        > 
        

        I have foggy memories of seeing 3 deep nesting but have forgotten the details.

        Option 2 is usually recommended.

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

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

          The first level keeps your namespace clear of anybody elses.
          The second level keeps this extension's namespace clear of your other extensions (it happens! I just had a collision between two of my extensions when I forgot about a name I had used already)
          I think a third level would be needed only in a complex suite of extensions such as Fredo6 or TomTom develop - though of course any class you define inside the second level creates a third namespace.

          1 Reply Last reply Reply Quote 0
          • hsmyersH Offline
            hsmyers
            last edited by

            @slbaumgartner said:

            The first level keeps your namespace clear of anybody elses.
            The second level keeps this extension's namespace clear of your other extensions (it happens! I just had a collision between two of my extensions when I forgot about a name I had used already)
            I think a third level would be needed only in a complex suite of extensions such as Fredo6 or TomTom develop - though of course any class you define inside the second level creates a third namespace.

            Useful explanation with war story 😉 The last bit reminded me where I'd seen the third level, so quite helpful!

            1 Reply Last reply Reply Quote 0
            • G Offline
              Garry K
              last edited by

              I use a modified template that Dan Rathburn created. I also use his file naming convention for the loader etc.

              You could strip this down. But I like to place my plugins in a shared folder so I can test a single plugin on 6 versions of Sketchup SU7 through SU2016

              
              require('extensions.rb')
              
              module YourCompany    # Proprietary TopLevel Namespace; No Trespassing!
              
                module ThisPlugin   # Namespace for THIS plugin
                  # Create an entry in the Extension list that loads script called;
                  # "gkware_doormaker_loader.rb"
                  APP_VERSION = '1.0.1'
              
                  @plugin = SketchupExtension.new('Company Plugin Description', File.join('PluginName', 'Company_PluginName_loader'))
              
                  @plugin.creator = 'Your Name'
                  @plugin.copyright = '(c)2013-2016 by YourCompany'
                  @plugin.version = APP_VERSION
                  @plugin.description = 'Plugin does something - optional url to your website'
              
                  unless @plugin.class.method_defined?(;path)
                    #
                    # Define a singleton method for @plugin to access the @path attribute.
                    # (... because the API did not do it in extensions.rb !!)
                    #
                    def @plugin.path()
                      instance_variable_get(;@path)
                    end
                  end # unless
              
                  # Create local path and filename constants;
              
                  PATH = @plugin.path()
                  LOADER_SUFFIX = '_loader'
                  LOADER = File.basename(PATH)
                  tmp = LOADER.split('_')
                  RBSFILE = tmp[0] + '_' + tmp[1] + '.rbs'
              
                  # RELDIR is relative to Plugins dir, OR the dir from
                  # the $LOAD_PATH array that require used to find it.
                  RELDIR = File.dirname(PATH)
              
                  ROOT = $LOAD_PATH.find(false) do |abspath|
                    Kernel.test(?d, File.join(abspath, RELDIR))
                  end
              
                  if ROOT
                    ABSDIR = File.join(ROOT, RELDIR)
                  else
                    # assume the target dir is directly below, the dir that THIS file is in.
                    ABSDIR = File.join(File.dirname(__FILE__), RELDIR)
                  end
              
                  # Register this extension with the Sketchup;;ExtensionManager
                  Sketchup.register_extension(@plugin, true)
              
                end # module YourCompany;;ThisPlugin
              
              end # module YourCompany
              
              
              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