I am writting my first SketchUp plugin, and I would like to store some option in an ini file. For that purpose, I installed the IniFile Gem in SketchUp console and I have the following options.ini file in the Plugins directory:
[Options]
option1 = value1
option2 = value2
And I have the following code:
conf = IniFile.load( 'options.ini' )
options = conf["Options"]
When I run the script, for some reason the load method cannot load the ini file, and I got a runtime exception on the next line, for trying to access "Options" on a NilClass object:
Error: #<NoMethodError: undefined method `[]' for nil:NilClass>
Have somebody had the same issue before? Any help is appreciated!
I managed to find the problem. Sketchup only stores the plugins in the plugin folder, but it calls them from the Documents folder (on Windows). As a consequence, one cannot use relative path in their scripts. Adding the following solved the problem:
conf = IniFile.load( File.dirname(__FILE__) + '/options.ini' )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.