Sketchup_json gem for sketchupRuby API
-
hello there everyone. I an just a novice self taught programmer and I am making a plugin that could pass data to my java code.
my problem is that when I type( require 'sketchup_json') in the ruby console, it gives a lot of errors. ( I have typed require 'rubygems' which returns true )
I've searched the web that json could be the key to pass data from ruby to java, and I further searched that there is this sketchup_json gem for sketchup . I do not know if this is the right gem for my objective . I have also transfered the msvcrt-ruby18.dll file to the googlesketchup folder to make the ruby version into 1.8.7 cuz sketchup has 1.8.6. and I cant download it.
here is a part of my code:
$LOAD_PATH << "C:/Ruby186/lib/ruby/1.8"
$LOAD_PATH << "C:/Ruby186/lib/ruby/site_ruby/1.8"
$LOAD_PATH << "C:/Ruby186/lib/ruby/1.8/i386-mingw32"
$LOAD_PATH << "C:/Ruby187/lib/ruby/gems/1.8/gems/sketchup_json-0.1.1/lib"
$LOAD_PATH << "C:/Ruby187/lib/ruby/gems/1.8/gems/sketchup_json-0.1.1/lib/sketchup_json"require 'rubygems'
require 'sketchup_json'
the error is:
C:/Ruby187/lib/ruby/gems/1.8/gems/sketchup_json-0.1.1/lib/sketchup_json.rb:1: warning: already initialized constant APP_BASE_PATH
C:/Ruby187/lib/ruby/gems/1.8/gems/sketchup_json-0.1.1/lib/sketchup_json/generator.rb:2: warning: already initialized constant JSONEncodeError
Error: #<TypeError: C:/Ruby187/lib/ruby/gems/1.8/gems/sketchup_json-0.1.1/lib/sketchup_json/generator.rb:39: Array is not a class>
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:ingem_original_require' C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
require'
C:/Ruby187/lib/ruby/gems/1.8/gems/sketchup_json-0.1.1/lib/sketchup_json.rb:5
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:ingem_original_require' C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
require'
(eval):63and I just do not know why it gives this errors when it works fine with interactive ruby.
can anyone help me give a clue on how to fix this?cuz I do not know if this problem had already been discussed in this forum. -
(1) I have never heard of anyone successfully getting RubyGems to run inside SketchUp embedded Ruby in the 1.8.x trunk. That means ALL SketchUp versions before 2014. (It WILL work with SketchUp 2014 and higher, which uses Ruby 2.0, which comes with the standard library and RubyGems already loaded.)
If you are still using SketchUp v 8 Make (Free,) there is no reason why you should not have upgraded to SketchUp 2014. (.. and even SketchUp 2013 before this!)(2) Why would you ever think you can mix together code from Ruby v 1.8.6 and Ruby v 1.8.7 within the same process, without errors ?
(I am not surprised.)
Upgrade to SketchUp 2014 if you wish to use gems. All the load paths are preset and you do not need to append them.
Also there is a json extension that comes with the standard library. Use it if at all possible. (But beware if it changes base classes! Any plugin that changes Ruby Base classes or SketchUp API classes [or modules,] is likely to be blacklisted or quarantined by the community, and not allowed in the Extension Warehouse.)(3) Before you can
require
a gem, it usually must be installed.
From a system shell, you'd use gem.bat:
%(#004000)[gem install sketchup_json-0.1.1]
.. or from within Ruby (after successfully getting RubyGems to load:
Gem::install "sketchup_json"
-
.
FYI see topic: JSON in (SketchUp) Ruby
-
.
I had a look at the code in the sketchup_json-0.1.1 gem, and yes it modifies many Ruby base classes.
Most of the mods are addingto_json()
method wrappers around all these classes'to_s()
method. This is rather clunky IMHO. (Ie, it is unnecessary.)Also it does not help the API classes that could benefit from json conversion.
-
I notice that under SketchUp 2014 and Ruby 2.0, that
Object
has been extended.At the console:
Object.ancestors%(darkgreen)[>> [Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]]
-
Hello again Dan. Thanks for the reply.. I have already download sketchup 14 and I took your advice. it is just too great..I did got the gems and json without and effort.
but there is this little problem that I have encountered, I cant seem to parse a json file to sketchup.
here is a sample code that I have written.I wrote this JSON file named input.json(I saved it inside the Tools folder):
{ "name":"Stephen"
"age": 22 }and I wrote this simple ruby code in the Tools folder name testing.rb:
require 'rubygems'
require 'json'
require 'pp'json = File.read('C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/input.json')
obj = JSON.parse('json')PP obj
and this is the error that I got in the ruby console:
Error: #<JSON::ParserError: 757: unexpected token at 'json'>
C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/json/common.rb:155:inparse' C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/json/common.rb:155:in
parse'
C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/tesing.rb:6:in<top (required)>' <main>:in
load'
<main>:in<main>' -e:1:in
eval'
nildo you have any Idea how to fix this . I mean how to let sketchup read seperate json files .
-
@penpendrum said:
(I saved it inside the Tools folder):
The "Tools" folder is a OEM (Trimble) ONLY folder.
You should stay out of that folder.Any "user" data files (or materials, styles, modles, etc.,) should be saved in your user path.
Either under the %AppData% path, or under your documents path. -
@penpendrum said:
I wrote this JSON file named input.json(I saved it inside the Tools folder):
{ "name";"Stephen" > "age"; 22 }
Each sub-object in JSON must be separated with a comma (
,
).
This is resulting in the unexpected token when parsing, because it sees the 2nd "age" token object while it is trying to isolate the 1st "name" token.It should be like:
{ "name" ; "Stephen" , # <-- comma seapartor "age" ; 22 }
@penpendrum said:
and I wrote this simple ruby code in the Tools folder name testing.rb:
require 'rubygems'
This is not needed (but harmless,) as the Ruby loader already loads RubyGems for Ruby 2.x
Advertisement