Problem with plugin loading

hello everyone,
I created a test plugin but sketchup tells me that there is always an error, and I can not detect the error yet I took example on another functional plugin, then there is Does anyone who can help me thank you very much

Erreur de chargement du fichier heron_toolbox.rb
Error: #<NameError: uninitialized constant Heron::Heron_Panel::Plugin>
C:/Users/imenf/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/heron_toolbox.rb:23:in `<module:Heron_Panel>'
C:/Users/imenf/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/heron_toolbox.rb:5:in `<module:Heron>'
C:/Users/imenf/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/heron_toolbox.rb:4:in `<top (required)>

Your code isn’t properly defining/referencing Heron::Heron_Panel::Plugin
You need to add something like this inside:
Heron::Heron_Panel::Plugin

def self.run()
  ### run the code here
end

Then you ‘call’ it using Heron::Heron_Panel::Plugin.run()

this is my file :

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

module Heron
  module Heron_Panel

    # Create and Register extension
    #unless file_loaded?(__FILE__)
	
	
	
	PLUGIN_ID = File.basename(__FILE__, ".rb")
    PLUGIN_DIR = File.join(File.dirname(__FILE__),PLUGIN_ID)
	
	EXTENSION = SketchupExtension.new(
      "Heron Techniques",
      File.join(PLUGIN_DIR, "main")
    )
	
	  
	  
      EXTENSION.description = 'Boîte à outils pour la cvc/plomberie'
      EXTENSION.version     = Plugin::VERSION
      EXTENSION.copyright   = '2019'
      EXTENSION.creator     = 'LOUZA '
      Sketchup.register_extension(EXTENSION, true)
      #file_loaded(__FILE__)
    #end

  end
end

but i don’t know where i must put it .(sorry i am beginner)

the main file is :{

require 'sketchup.rb'
require_relative 'ruby/plugin.rb'

 module Heron 
    module Heron_Panel

    #Initialize the app
    #plugin = Plugin.new


	
	
	
	
    unless file_loaded?(__FILE__)

      # Setup Menu
	  
      menu = UI.menu
	  
      submenu = menu.add_submenu('Heron Techniques')
	  
	  
      submenu.add_item('tab.drawpvc.title')        {  UI.messagebox('drawpvc') }
	 

      # Setup Toolbar
	  
      toolbar = UI::Toolbar.new('HERON CVC/PLOMBERIE')
	  
      cmd1 = UI::Command.new('HERON CVC/PLOMBERIE')  { UI.messagebox('drawpvc') }
	  
	  
      cmd1.small_icon = 'img/icone1.png'
      cmd1.large_icon = 'img/icone1.png'
	  
	  
	  
      cmd1.tooltip = ('draw pvc')
	 
	  
	  
	  
	  
      cmd1.status_bar_text = ('Pour dessiner des tuyaux pvc')
	  
	  
      #cmd.menu_text = plugin.get_i18n_string('core.toolbar.command')
      toolbar = toolbar.add_item(cmd1)
	  
	  
	  
      toolbar.show

      file_loaded(__FILE__)
    end

  end
end 

So you have a file named main.rb in the subfolder named after your main module [referenced by
PLUGIN_DIR] ?
But haven’t shown any code in it which does anything ??

I can’t see anything name Heron::Heron_Panel::Plugin set up in your code [which isn’t # out] - are we seeing all of it ???

Also, why are you requiring [relatively] plugin.rb ?
It’s not needed in this simple example, in any case…

yes there is no specific code other than a messagebox, by the way I did it to see how to structure a plugin and progress slowly

Can you wrap the code with ``` characters to make the forum engine style in as code, like this?

```ruby
# Code goes here
```

The result should look like this:

# Code goes here

this would make reading a lot easier.

Edit: Accidentally tagged TIG. This was meant as a response to LOUZA.

Try this - miss out the { } around the main module code block - I only just noticed those !
And forget the require for plugin.rb
Leave your # lines alone.
Retest…

require 'sketchup.rb' 
module Heron 
module Heron_Panel

# Create and Register extension
#unless file_loaded?(__FILE__)



PLUGIN_ID = File.basename(__FILE__, ".rb")
PLUGIN_DIR = File.join(File.dirname(__FILE__),PLUGIN_ID)

EXTENSION = SketchupExtension.new(
  "Heron Techniques",
  File.join(PLUGIN_DIR, "main")
)

  
  
  EXTENSION.description = 'Boîte à outils pour la cvc/plomberie'
  EXTENSION.version     = Plugin::VERSION
  EXTENSION.copyright   = '2019'
  EXTENSION.creator     = 'LOUZA '
  Sketchup.register_extension(EXTENSION, true)
  #file_loaded(__FILE__)
#end

end 
end
#Initialize the app
#plugin = Plugin.new






unless file_loaded?(__FILE__)

  # Setup Menu
  
  menu = UI.menu
  
  submenu = menu.add_submenu('Heron Techniques')
  
  
  submenu.add_item('tab.drawpvc.title')        {  UI.messagebox('drawpvc') }
 

  # Setup Toolbar
  
  toolbar = UI::Toolbar.new('HERON CVC/PLOMBERIE')
  
  cmd1 = UI::Command.new('HERON CVC/PLOMBERIE')  { UI.messagebox('drawpvc') }
  
  
  cmd1.small_icon = 'img/icone1.png'
  cmd1.large_icon = 'img/icone1.png'
  
  
  
  cmd1.tooltip = ('draw pvc')
 
  
  
  
  
  cmd1.status_bar_text = ('Pour dessiner des tuyaux pvc')
  
  
  #cmd.menu_text = plugin.get_i18n_string('core.toolbar.command')
  toolbar = toolbar.add_item(cmd1)
  
  
  
  toolbar.show

  file_loaded(__FILE__)
end
` ``

THREE ` [back-ticks] are needed at the start and end of the code block, on separate lines, with ruby on the first line.


module Heron
module Heron_Panel
#Initialize the app
#plugin = Plugin.new

unless file_loaded?(__FILE__)

  # Setup Menu
  
  menu = UI.menu
  
  submenu = menu.add_submenu('Heron Techniques')
  
  
  submenu.add_item('tab.drawpvc.title')        {  UI.messagebox('drawpvc') }
 

  # Setup Toolbar
  
  toolbar = UI::Toolbar.new('HERON CVC/PLOMBERIE')
  
  cmd1 = UI::Command.new('HERON CVC/PLOMBERIE')  { UI.messagebox('drawpvc') }
  
  
  cmd1.small_icon = 'img/icone1.png'
  cmd1.large_icon = 'img/icone1.png'
  
  
  
  cmd1.tooltip = ('draw pvc')
 
  
  
  
  
  cmd1.status_bar_text = ('Pour dessiner des tuyaux pvc')
  
  
  #cmd.menu_text = plugin.get_i18n_string('core.toolbar.command')
  toolbar = toolbar.add_item(cmd1)
  
  
  
  toolbar.show

  file_loaded(__FILE__)
end


end
end
```

TIG i do with your advices but alwyas the same thing

my folder is organized as follows; the yaml folder is empty

You still have some spare ` in your example code near the end - these are only for the forum’s post formatting - NOT needed in the RB file’s code itself.

The error is occurring in heron_toolbox.rb as explained in the error message.
Is your posted code the full code that it contains ?

How is that RB getting loaded ?
It is not mentioned in any of the examples you have provided !
It should be in the matching module’s subfolder, which tour extension references as ‘main’ in earlier examples !
Does ‘main’ load it ??
Reading the error message it looks like you have that heron_toolbox.RB file placed directly into the main Plugins folder, and NOT the expected module’s subfolder, so currently it automatically loads - incorrectly…
Please re-post its full code…

thank you TIG i will try again until i make it working , if not i will return :slight_smile:

This is the line causing the error in the registrar script …

The issue is that the constant reference Plugin is not YET defined (when this file is loading,) and is only LATER defined in the third file to load ("plugin.rb".)

DAN thank you , you are great ,now all it’s ok thankyou

1 Like

@LOUZA Please check the preview of the posts you make - making sure that the formatting looks good. Otherwise it’s very hard to read your posts and code.

I have gone ahead an corrected your previous posts in this thread. Please use the Edit function of the forum if you find a mistake in your formatting after posting.

2 Likes

ok tt_su