Sketchup2014 - undefined method `GetString'
-
I've downloaded Sketchup2014 and tried running the plugin I'm working on but, as the title suggests, I get Error: #<NoMethodError: undefined method `GetString' for nil:NilClass>.
I searched for a solution and the only thing I could find was in this thread but no solution was given...
http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=9460%26amp;p=464586%26amp;hilit=getstring#p464586 -
That means it is calling "GetString" on a nil object. It would have been a little more helpful if you posted the full error message. But essentially it gave you a line number in there. On that line, you are calling GetString. At that moment, what ever you are calling getstring on, is nil. And getstring is not a method for the nil object. Does that help?
If you post the full error message, I could help determine what line is actually the problem line.
Chris
-
I was going to say LanguageHandler isn't documented and was never meant for user plugins, but that would be incorrect as of v2014.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/languagehandler
-
@chris fullmer said:
That means it is calling "GetString" on a nil object. It would have been a little more helpful if you posted the full error message. But essentially it gave you a line number in there. On that line, you are calling GetString. At that moment, what ever you are calling getstring on, is nil. And getstring is not a method for the nil object. Does that help?
If you post the full error message, I could help determine what line is actually the problem line.
Chris
Hi Chris,
My bad, here's the full error message...
Error: #<NoMethodError: undefined methodGetString' for nil:NilClass> C:/Users/Frank/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/FN/CabinetBuilder/cabBuilder.rb:4245:in
onMouseMove'And here's the actual line of code...
msg << $uStrings.GetString("Name;") + " #{(selected_comp_name)}"
Weird thing is in all the other versions of Sketchup I don't get the error message and everything works fine.
-
$uStrings
is only defined IF the user has installed the Utilities plugin.
Since SU2013, it no longer distros with SketchUp. Users must explicitly install it from the Extension Warehouse.ALSO... it is bad programming etiquette to create global vars for use by a single plugin.
We have been bitchin' at the Trimble team to move their myraid of global vars into their plugin namespaces as class/module vars.
SO.. you should not rely upon global vars created by other plugins (even SketchUp team plugins.)If you need to access any of the Resources strings files, you can do so temporarily, and store the strings your plugin uses, in a hash inside your plugin's namespace.
@say = Hash.new {|hash, key| key } lf = LanguageHandler.new("utilities.strings") @say["Name;"]= lf.GetString("Name;") lf = LanguageHandler.new("Components.strings") @say["Components"]= lf.GetString("Components") lf = LanguageHandler.new("examples.strings") @say["Width"]= lf.GetString("Width") @say["Height"]= lf.GetString("Height") @say["Depth"]= lf.GetString("Depth") lf = nil # release the last LanguageHandler object for GC # use them later in your code; msg << "#{@say["Name;"]} #{(selected_comp_name)}"
HOWEVER.. I just noticed that the "utilities.strings" file (and therefore the
$uStrings
object, does NOT have an entry "Name:" !!!Did you think that a
LanguageHandler
hash-wrapper object would just magically contain the strings you need ?It does not work like that. You have to create the translations for all the strings files that your plugin will need.
-
@dan rathbun said:
$uStrings
is only defined IF the user has installed the Utilities plugin.
Since SU2013, it no longer distros with SketchUp. Users must explicitly install it from the Extension Warehouse.ALSO... it is bad programming etiquette to create global vars for use by a single plugin.
We have been bitchin' at the Trimble team to move their myraid of global vars into their plugin namespaces as class/module vars.
SO.. you should not rely upon global vars created by other plugins (even SketchUp team plugins.)If you need to access any of the Resources strings files, you can do so temporarily, and store the strings your plugin uses, in a hash inside your plugin's namespace.
@say = Hash.new {|hash, key| key } > > lf = LanguageHandler.new("utilities.strings") > @say["Name;"]= lf.GetString("Name;") > > lf = LanguageHandler.new("Components.strings") > @say["Components"]= lf.GetString("Components") > > lf = LanguageHandler.new("examples.strings") > @say["Width"]= lf.GetString("Width") > @say["Height"]= lf.GetString("Height") > @say["Depth"]= lf.GetString("Depth") > > lf = nil # release the last LanguageHandler object for GC > > # use them later in your code; > > msg << "#{@say["Name;"]} #{(selected_comp_name)}" > >
HOWEVER.. I just noticed that the "utilities.strings" file (and therefore the
$uStrings
object, does NOT have an entry "Name:" !!!Did you think that a
LanguageHandler
hash-wrapper object would just magically contain the strings you need ?It does not work like that. You have to create the translations for all the strings files that your plugin will need.
Thanks for the reply Dan,
This part of the code is from the querytool plugin and other then changing a few things to play around with and try and learn ,like adding "Name:", I never got around to doing much with it and like I said this worked in other versions of sketchup including 2013 ,so yeah magically everything worked till now without me having to do much at all.
From your reply, which honestly for a non programmer half hack like me is more confusing then my original question, ha!, if I check out the utilities plugin it's a good example of how LanguageHandler works?
Looks like I'll be learning something new once again!
Frank
-
@dan rathbun said:
ALSO... it is bad programming etiquette to create global vars for use by a single plugin.
We have been bitchin' at the Trimble team to move their myraid of global vars into their plugin namespaces as class/module vars.
SO.. you should not rely upon global vars created by other plugins (even SketchUp team plugins.)Indeed - we have a lot of cleanup ahead of us. Take note of what Dan said about using globals or anything else defined by the internals of another plugin - even ours. They are subject to change. I'm personally very eager to zap those globals to kingdom come.
I guess the LanguageHandler would make for a nice blog post. I'll forward this to my team.
-
The best way to know how
LanguageHandler
works is to read the "LangHandler.rb" file in the "Tools" folder.Or the API doc: http://www.sketchup.com/intl/en/developer/docs/ourdoc/languagehandler
Note thatGetString
still must be used for version <14, otherwise use[]
(they are aliases for each other.) -
Thanks for the replies and help guys!
So I read up on LanguageHandler and looked at LangHandler.rb, utilities.rb and utilities.string. From my understanding what LanguageHandler is used for is if you want the plugin to be multilingual?
So if someone wanted there plugin to be readable in English, French and Chinese he would create the appropriate .string file to translate between languages and use .GetString to retrieve the proper language?
I haven't had time to test this so I might be way off track here...
But all this made me realize that I don't need LanguageHandler to get what I want done, for now anyways. Everytime I think I'm done with my plugin I think of other things to add to complicate my life.
Frank
-
@frankn said:
From my understanding what LanguageHandler is used for is if you want the plugin to be multilingual?
YES
@frankn said:
So if someone wanted there plugin to be readable in English, French and Chinese he would create the appropriate .string file to translate between languages ...
FILES. One file for each language:
%(#004000)["Plugins/FN_CabinetBuilder/Resources/en-US/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/fr/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/zh-CN/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/zh-TW/cabBuilder.str"]
@frankn said:
... and use
.GetString
to retrieve the proper language?Yes, or
[]
for SketchUp 2014+. -
@dan rathbun said:
FILES. One file for each language:
%(#004000)["Plugins/FN_CabinetBuilder/Resources/en-US/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/fr/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/zh-CN/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/zh-TW/cabBuilder.str"]
@frankn said:
... and use
.GetString
to retrieve the proper language?Yes, or
[]
for SketchUp 2014+.Ok gotcha for the files, thanks Dan.
As far as using .GetString or [], does .GetString still work in 2014 so that it's compatible with older versions of Sketchup?
Later on when I'm done with my plugin(yeah right!) this might be something cool to add as a feature.
Thanks again for the info!
-
@frankn said:
As far as using
.GetString
or[]
, does.GetString
still work in 2014 so that it's compatible with older versions of Sketchup?Yes the renamed the getter method
[]
, then aliased it asGetString
.
Advertisement