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

Module depth: Good Practices

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 4 Posters 680 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.
  • H Offline
    hsmyers
    last edited by 21 May 2016, 01:28

    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
    • S Offline
      sdmitch
      last edited by 21 May 2016, 13:35

      @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 21 May 2016, 20:20

        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
        • H Offline
          hsmyers
          last edited by 21 May 2016, 20:26

          @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 21 May 2016, 21:59

            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
            1 / 1
            • First post
              5/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement