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?
kengey
September 12, 2020, 11:28am
2
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 String s 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
kengey
September 12, 2020, 11:46am
5
Great @DanRathbun . I know it was uppercase, but didn’t care to bother on this touch screen cellphone thing, sorry
I already was happy to have added these backquotes and underscores