Loading file problem

Dear friends,

#    unless file_loaded?("wall.rb")
    UI.menu("Plugins").add_item("Wall") {
    Sketchup.active_model.select_tool(Wall.new)
    }
#    file_loaded("wall.rb")
#    end
if I active 3 line codes, ruby send me "Nil result (no result returned)" but it works well when these 3 lines are deactivated. Can you tell me what is my problem?

Are you talking about the 3 lines in comment? (With the # in front of it)

I am on my phone right now, but, could another dev please add __file__ instead of wall.rb

2 Likes

How many other plugins might also use the simple filename "wall.rb" ?

The methods file_loaded() and file_loaded?() are global methods that put text Strings into a shared global array named $loaded_files.

This means you will need to use a unique filepath string to test with.

  unless file_loaded?(File.join(__dir__,"wall.rb"))
    UI.menu("Plugins").add_item("Wall") {
      Sketchup.active_model.select_tool(Wall.new)
    }
    file_loaded(File.join(__dir__,"wall.rb"))
  end

Secondly, this code snippet must be within the module where the Wall class is defined.

1 Like

It is actually __FILE__, and I showed using Ruby 2.x’s __dir__ method.

So … @majid866 you can also use …

  unless file_loaded?(__FILE__)
    UI.menu("Plugins").add_item("Wall") {
      Sketchup.active_model.select_tool(Wall.new)
    }
    file_loaded(__FILE__)
  end

By the way @majid866, this comes right from the example in the API documentation.

1 Like

Great @DanRathbun. I know it was uppercase, but didn’t care to bother on this touch screen cellphone thing, sorry :slight_smile:

I already was happy to have added these backquotes and underscores