Problems with SketchUp 8 plugins in Sketchup 2015
-
We try to change our SketchUp 8 plugins to SketchUp 2015. But it seems not so easy. There are several problems.
For example:
%(#4000FF)[**@@menu[:top]= UI.menu("Plugins")**]
works with SketchUp 8 fine. SketchUp 2015 don´t accept that.
I can´t find the reason.
What´s the problem? -
I assume you are trying to assign a hash to a menu-reference ?
@@menu[:top]= UI.menu("Plugins")
Works fine provided thevariable={}
is predefined.
I just tried it.
You must assign@@menu={}
as the class/module is created: it needs to be done outside of any class/module's methods that will use it later...
for example:class MyClass @@menu={} def some_method() @@menu[;top]= UI.menu("Plugins") ... end end
or
module MyModule @@menu={} ### or @menu={} etc def self.some_method() @@menu[;top]= UI.menu("Plugins") ... end end
You haven't explained why it needs to be a
@@
variable ??
Why not@menu={}
?
Or it could just as easily be a Constant ?Menu={}
Without seeing and understanding all of your code it's impossible to resolve this. -
It is a little bit complex.
I don´t want to show hundreds of lines code here.
So I try it like this:# File in SketchUp-Plugins require('sketchup.rb') require('extensions.rb') module ABSBMP ### ( Toplevel namespace) module MoMo ### ( This plugin's nested namespace. ) @@relExtPfad = 'ABSBMP/mo_mo_moebel' # relative path @@ladeprogramm = 'mo_mo_load' # load script ... @@plugin = SketchupExtension.new( @@sagExt;titel],File.join@@relExtPfad,@@ladeprogramm) ) ... Sketchup.register_extension( @@plugin, true ) end # module MoMo end # module ABSBMP file_loaded('Plugins;ABSBMP_mo_mo_moebel_ext') # global method from 'Tools/sketchup.rb' # File (@@ladeprogramm 'mo_mo_load') in subdirectory (@@relExtPfad) require('sketchup.rb') module ABSBMP;;MoMo Sketchup.require(File.join(@@relExtPfad,'mo_mo_main')) end # < module ABSBMP;;MoMo file_loaded('ABSBMP;mo_mo_load') # global method from 'Tools/sketchup.rb' # File ('mo_mo_main') in subdirectory (@@relExtPfad) require('sketchup.rb') module ABSBMP;;MoMo ... @@menu[;top]= UI.menu("Plugins") ... end # module ABSBMP;;MoMo file_loaded('ABSBMP;mo_mo_main') # global method from 'Tools/sketchup.rb'
-
module ABSBMP ### ( Toplevel namespace) module MoMo ### ( This plugin's nested namespace. ) @@menu={} ### Otherwise the hash is nil !
-
Sorry, my mistake. It is not complete, I forgot something.
This should be correct:# File in SketchUp-Plugins require('sketchup.rb') require('extensions.rb') module ABSBMP ### ( Toplevel namespace) module MoMo ### ( This plugin's nested namespace. ) @@relExtPfad = 'ABSBMP/mo_mo_moebel' # relative path @@ladeprogramm = 'mo_mo_load' # load script ... @@plugin = SketchupExtension.new( @@sagExt;titel],File.join@@relExtPfad,@@ladeprogramm) ) ... Sketchup.register_extension( @@plugin, true ) end # module MoMo end # module ABSBMP file_loaded('Plugins;ABSBMP_mo_mo_moebel_ext') # global method from 'Tools/sketchup.rb' # File (@@ladeprogramm 'mo_mo_load') in subdirectory (@@relExtPfad) require('sketchup.rb') module ABSBMP;;MoMo Sketchup.require(File.join(@@relExtPfad,'mo_mo_main')) end # < module ABSBMP;;MoMo file_loaded('ABSBMP;mo_mo_load') # global method from 'Tools/sketchup.rb' # File ('mo_mo_var_get') in subdirectory (@@relExtPfad) require('sketchup.rb') module ABSBMP;;MoMo ### MODUL-VARIABLEN ( MODULE VARIABLES ) ... #{# MenĂĽs ( Menus ) # @@menu = {} # #}# ... end # module ABSBMP;;MoMo file_loaded('ABSBMP;mo_mo_var_get') # global method from 'Tools/sketchup.rb' # File ('mo_mo_main') in subdirectory (@@relExtPfad) require('sketchup.rb') module ABSBMP;;MoMo ... @@skript = ["mo_mo_var_get"] Sketchup;;require(File.join(@@relExtPfad,@@skript)) ... ... @@menu[;top]= UI.menu("Plugins") ... end # module ABSBMP;;MoMo file_loaded('ABSBMP;mo_mo_main') # global method from 'Tools/sketchup.rb'
-
Why don't you simply set up
@@menu = {}
inside the first loading file which creates
module ABSBMP::MoMo
Then the loading order of the rest of the files [which seems unnecessarily complicated!] become unimportant. -
It is a large application. Therefore it is comprehensible to declare the variable in a separate file.
But it seems, that the real problem is included elsewhere. So I've changed my method. Till now I've tried to find out what does not work. Now I am trying to find out what works.
In that process I found an error in the following code:
require('sketchup.rb') module ABSBMP;;MoMo ... ... class << self # Proxy class inside module ABSBMP;;MoMo # Create Reader methods for currently defined module variables. #{ ABSBMP;;MoMo;;class_variables.each do |varstr| kind = eval %[#{varstr}.class] attstr = varstr.gsub(/(\A@@)/,'') <-- Error; #<NoMethodError; undefined method `gsub' for ;@@relExtPfad;Symbol> # Reader Method unless ['@@sag','@@skript'].include?(varstr) eval %[def #{attstr}(); return #{varstr}; end;] if kind.is_a?(TrueClass) || kind.is_a?(FalseClass) eval %[alias_method('#{attstr}?','#{attstr}');] end end end #} do class_variables.each end # Proxy class end # module ABSBMP;;MoMo file_loaded('ABSBMP;mo_mo_var_get') # global method from 'Tools/sketchup.rb'
%(#4040FF)[The error-message is shown at the start of SketchUp 2015.
In SketchUp 8 it works well!!!] -
Perhaps:
varstr.to_s.gsub...
Since I don't understand what your code is trying to do it's not that easy to help... -
@unknownuser said:
Perhaps: varstr.to_s.gsub...
Is a good idea, but does not really works.
It works like this:
varstr = varstr.to_s attstr = varstr.gsub(/(\A@@)/,'')
The names of the module variables will be reduced by the first two "@" sign.
This names will be used later as descriptions to make the color settings. For example for cabinet sides, cabinet doors, tabletops ...We are manufacturer of office furniture.
http://www.momo-moebel.de/The application is used to create plans for office furniture.
You can get the plugins as a free download for usage with SketchUp 8 from our homepage.
http://www.momo-moebel.de/fileadmin/service/mo_mo_SketchUp_V_3_2_06.zip
We want to offer that for current sketchup Versions. Therefore, we are reworking the SketchUp plugins. -
So your code
ABSBMP::MoMo::class_variables
returns an Array of Symbols
>>> [:@@a, :@@b,...]
So you need the stepvarstr = varstr.to_s
to make it into a String.
:@@a >>> "@@a"
Then you useattstr = varstr.gsub(/^[@][@]/, "")
to strip off the initial '@@'... -
@@skript = ["mo_mo_var_get"]
should be just:
@@skript = "mo_mo_var_get"
-
@tig said:
So your code
ABSBMP::MoMo::class_variables
returns an Array of Symbols
>>> [:@@a, :@@b,...]
So you need the stepvarstr = varstr.to_s
to make it into a String.
:@@a >>> "@@a"
Then you useattstr = varstr.gsub(/^[@][@]/, "")
to strip off the initial '@@'...Many of the global query methods changed from Ruby 1.8 to Ruby 2.0.
They now return arrays of symbols (for each variable or method name.) In Ruby 1.8 they returned array of string (for each variable or method name.)
There are also many other "breaking changes" in Ruby 2.0 that need to be dealt with.
(@TIG, Was there a post here on breaking changes?)
Also garbage collection is much better under Ruby 2.0, so any menu reference will most likely only be valid during the evaluation of the file in which the reference is first made by an API call.
So the attempt to hold the reference@@menu[:top]
across multiple files may no longer work.We have been complaining about the non persistence of UI element references, for years! (Especially menu references.)
So the workaround is to save the menu NAME (as a string,) instead of the actual reference to the menu object.
@@menu[:top]= "Plugins"
... then whenever you need the object reference, use:
topmenu = UI.menu( @@menu[:top] )
or
submenu = UI.menu( @@menu[:top] ).add_submenu( "MoMo" )
Advertisement