sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Sketchup2014 - undefined method `GetString'

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 5 Posters 2.7k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      Frankn
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        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

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          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

          Hi

          1 Reply Last reply Reply Quote 0
          • F Offline
            Frankn
            last edited by

            @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 method GetString' 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.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              $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.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • F Offline
                Frankn
                last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  @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.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    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 that GetString still must be used for version <14, otherwise use [] (they are aliases for each other.)

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • F Offline
                      Frankn
                      last edited by

                      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

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @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+.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • F Offline
                          Frankn
                          last edited by

                          @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!

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            @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 as GetString.

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • 1 / 1
                            • First post
                              Last post
                            Buy SketchPlus
                            Buy SUbD
                            Buy WrapR
                            Buy eBook
                            Buy Modelur
                            Buy Vertex Tools
                            Buy SketchCuisine
                            Buy FormFonts

                            Advertisement