Extension code from my dev directory won't load on starting Sketchup

(MacOS) I’m a bit of a newb and am trying to get my extension and its menu item added automatically when I start Sketchup. For git reasons it’s down a dev directory path. The only way, I know of, to get the Extension installed and the menu item in the Extensions menu is using the ‘Extension Sources’ extension. Can I do what it does programmatically?

Other than that I can debug fine in RubyMine, everything works.

Here’s what I know:

a) I’m using an Eneroth-ish load script in the Plugins directory:

#require 'sketchup.rb'
#require 'extensions.rb'

pattern = "/Users/<me>/Library/Mobile Documents/com~apple~CloudDocs/Dev/Sketchup Ruby/*/src"

Dir.glob(pattern).each do |dir|
  $LOAD_PATH << dir
  Dir.glob("#{dir}/*.rb").each { |p| require p }
end
```

b) I did do a puts on $LOAD_PATH and it getting the correct path added.

c) When ‘Dir.glob(“#{dir}/*.rb”).each { |p| require p }’ executes I am hitting a breakpoint in my registration file. Myregistration file is not the problem because the extension installs using ‘Extension Sources’.

d) cube_to_drawer/main never gets invoked to add the menu item unless I used ‘Extension Sources’

I work on a windows machine. I have made a few plugins for myself (none published). I use this code in the plugins folder and i have my own dev folder it points to and loads. Hope this helps:

ruby
=begin

Copyright: 2025, Mark Perrah, All Rights Reserved

Author: Mark Perrah

Name: MP Edge State Tool

Version 1.0.2

SU Version: 2024/5

Date: 4/8/2025

Description: Show icon change in toolbar depending state of selected edges

History:

    1.0.1 2025-04-08 first design

=end

require ‘sketchup.rb’

require ‘extensions.rb’

module MP_Extensions

module MP_Edge_State_Tool



    my_extension_loader = SketchupExtension.new( 'MP Edge State Tool' , 'mp_extensions/mp_edge_state_tool.rb')

    my_extension_loader.copyright = 'copyright 2025 by me'

    my_extension_loader.creator = 'Mark Perrah'

    my_extension_loader.version = '1.0.1'

    my_extension_loader.description = 'MP Edge State tool.'

    Sketchup.register_extension( my_extension_loader, true )



end # module MP_Edge_State_Tool

end # module MP_Extensions
```

The line “my_extension_loader = points to my subfolder. Thought possibly If the poster could use this as example to build the subfolder with his extension and point to it in this fashion.

Please edit post to properly quote code in the forum:


And BTW, your example is just a normal extension registrar file, that does not direct to a custom development path.

@mark.perrah yes, my reg file is pretty much plain vanilla and basically the same:

require 'sketchup.rb'
require 'extensions.rb'

module AdamExtensions
    module CubeToDrawer

        unless file_loaded?(__FILE__)
            ex = SketchupExtension.new('Cube To Drawer', 'cube_to_drawer/main')
            ex.description = 'SketchUp create drawer pieces from a selected cube.'
            ex.version = '1.0.0'
            ex.copyright = 'Adam Silver © 2025'
            ex.creator = 'Adam Silver'
            Sketchup.register_extension(ex, true)
            file_loaded(__FILE__)
        end

    end # module CubeToDrawer
end # module AdamExtensions
```
I did try a require 'cube_to_drawer/main' in the Eneroth-ic load file, i.e., the one in my Plugins directory, to run the 'main' module code to force adding the menu item.. but no love. And again, the load file was hitting the reg file above, but I still need to use the TT 'Extension Sources' to get the main module executed and the menu item added . How can I get my menu item added without 'Extension Sources'.

Any thoughts?


@DanRathbun It would be great if there was a tutorial on how to set up an efficient dev enviroment.

It looks like you tried to use something like the code shown here:

Basic Development Environment | developer.sketchup

  1. Is your loader.rb file in the SketchUp Plugins folder?
  2. There’s no drive shown in your file path (e.g., C:). Not a Mac user… but doesn’t seem correct.
  3. Is the path to a cloud location?

@3DxJFD Yes, [1.] my loader file is in my Plugins directory. It does work, because [using RubyMine] I can put a breakpoint in my reg file, which is in down my ‘Dev’ path, and it gets hit when I start Sketchup. So that’s ok.

[2.] Macs (macOS) is based on unix, they don’t have drive letters, instead they have ‘mounted volumes’, but none the less the initial forward slash is the ‘root’ just like ‘C:’ on a windows machine.

[3.] This is good point! And, yup, my dev directory is on my iCloud drive. But, the ‘icloud’ files, are locally cached in this case, and as evidence, I’ve got full debugging in RubyMine, with zero delay, so I think that’s ok.

Thank you for giving this attention, as far as I can tell, I’m doing everything in the Basic Development Environment | developer.sketchup

Ah well, I was just pointing to the obvious because that’s where I usually start getting off track. I did try both ways from the Basic Developemnt Environment page and they both worked for me (no GitHub). It sounds like you also know that you could run directly out of your Plugins folder with a registration file (‘registrar’ file, not the loader) but that doesn’t work for you, because Git reasons. One more wild guess: public vs. private GitHub repository? Could be a thing?

I haven’t tried loading from git, though I keep a backup copy of source code there. The attached extension, tweaked from the example in the dev github, has worked for me (it will need some edits for the folder paths where you keep your source). The ! on the registrar name causes SketchUp to load this before other extensions.

External_loader.rbz (643 Bytes)

1 Like

@3DxJFD Yes, life lesson which I seem to frequently ignore: always try the simple thing first.

@slbaumgartner Thanks, I’ll give this a try a little later.

1 Like