Error in 'require' when running via Sketchup Bridge
-
OK, parts of this question have been posted in various forms across these forums, but for a Ruby newbie like me, it's a little bit confusing. So I hope you guys will bear with me and help me through this.
What I am trying to do is to run a script via the Sketchup Bridge executable on Windows 7. I am able to run it successfully with with my normal Ruby install, but when I try to run it using sub.exe, I get an error that it could not find a file that exists in the '../lib' folder from where I am running the script and the exe (i have put them both in the same folder).
(Note that this required file is part of some gem, but as far as I can tell, the error is occurring at the level of requiring this file, and it hasn't yet gotten to the point where it is trying to use a gem)
Now first thing I did was to try and append the path of my Ruby directory to the load path (as mentioned in http://sketchucation.com/forums/viewtopic.php?f=180&t=18712). I even outputted the new load path via the messagebox, and confirmed it was correct. But that did not seem to work, and I got the same error.
The next thing I did was to move the folder to the Sketchup Plugins folder, and I moved the file I needed from the ../lib address to the folder where the script is. However, that too did not seem to work.
At this point, according to whatever I read on the forums, I think it might have to do something with my Ruby version. My normal ruby.exe resides in a 'Ruby200-x64', so I guess that means I have version 2.0.0 for my 64 bit system installed. As per http://sketchucation.com/forums/viewtopic.php?f=180&t=29412 and http://sketchucation.com/forums/viewtopic.php?f=180&t=29544, it seems like Sketchup uses Ruby version 1.8.X, and that I need to install that version of ruby and then copy the msvcrt-ruby18.dll from my Ruby install directory to my Sketchup directory.
However, before I do carry out this operation, I would like to know - is this really the problem? Because to me it makes no sense why a script, once given the correct load paths, is not able to run on 'any' interpreter. I'd appreciate if someone could show me what I'm missing.
(As an aside, if I go ahead and install Ruby version 1.8.X, and copy the msvcrt-ruby18.dll into the Sketchup folder, will I then be able to see puts output on the command line, and be able to access installed gems as long as I have the load path right?)
-
OK, so like a good, enthusiastic little programmer, I went ahead and installed an older version of Ruby and copied the dll, but I am still having the same issue. Here are the steps I took:
- I uninstalled Ruby version 2.0.0 from my system and installed the latest version 1.8.7-p374 from here: http://rubyinstaller.org/downloads/ (Note that I did not install version 1.8.6 because I needed to install the DevKit for my gem and I was having issues doing that for the 1.8.6 version)
- I went ahead and installed DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe from the same site.
- I installed my gem, and tested it from the command line.
- I copied the LOAD PATH script from http://sketchucation.com/forums/viewtopic.php?f=180&t=29412, and put it in the Plugins folder. I restarted Sketchup and I confirmed that the paths tot he ruby directory were added.
- I moved the existing msvcrt-ruby18.dll in the Sketchup folder to a "Backup" folder and copied the msvcrt-ruby18.dll in my ruby187/bin directory to the Sketchup directory, as mentioned in http://sketchucation.com/forums/viewtopic.php?f=180&t=25233&hilit=+interpreter+dll#p217030.
I restarted Sketchup and ran the script using sub.exe, but I still get the same error. The error is
@unknownuser said:
<eval>:2:in 'require' : no such file to load -- leap-motion-ws
The file I am running is called 'motion_sample.rb', and here are the first few lines:
$;.unshift "../lib" require 'leap-motion-ws'
The directory structure is of the key files is as such:
@unknownuser said:
C:\Users\Pratik\Development\SketchupLeap\LeapFiles\ruby-leap-motion-ws-master\samples\motion_sample.rb
@unknownuser said:
C:\Users\Pratik\Development\SketchupLeap\LeapFiles\ruby-leap-motion-ws-master\samples\sub.exe
@unknownuser said:
C:\Users\Pratik\Development\SketchupLeap\LeapFiles\ruby-leap-motion-ws-master\lib\leap-motion-ws.rb
Note that the leap-motion-ws gem is already installed, and the same folder as 'leap-motion-ws-master' exists in
@unknownuser said:C:\Ruby187\lib\ruby\gems\1.8\gems\leap-motion-ws-0.0.2
My windows version is Windows 7, and my Sketchup is he Pro Version 8.0.4811.
What am I missing here?
(P.S. I noticed something strange - to test if it would work, I removed the existing msvcrt-ruby18.dll from the Sketchup folder, and opened Sketchup without copying the new DLL (ie. there was NO version of msvcrt-ruby18.dll in the Sketchup folder). Despite this, Sketchup opened correctly AND ran the load path script I copied above. Does this mean my Sketchup is using some other DLL as the interpreter?)
-
Here's a little update: After my last post, I went ahead and pasted the leap-motion-ws.rb directly into the plugins folder, and voila, I started getting error messages about the requires in it! So I went ahead and moved all the folders into the plugin directory and got to a point where I was getting a require error on 'rubygems'.
At this point, my first observation is that the
$;.unshift "../lib"
command did NOT add the '../' path to the load paths. Any idea why?
So continuing on, I checked the location of my rubygems file, and realized it was in the 'site_ruby' folder. I therefore went ahead and uncommented that line from the load path script. I also made sure the path to the ruby folder was correct and case-sensitive.
Now, something strange happens:
On restarting Sketchup, I get the following message in the 'Load Errors' dialog:@unknownuser said:
Error Loading File leap-motion-ws.rb
no such file to load -- rubygemsBUT, when I run the motion_sample.rb script using sub.exe, I get NO such error. What I do get though is a server timeout, but I think that might be due to this script being an event listener and sub.exe timing out somehow (I don't really know how the guts of it works).
In any case, I'd be interested to know why:
- The 'unshift' command didn't seem to work
- SketchUp was still able to execute ruby scripts despite not having anyversion of msvcrt-ruby18.dll in the SketchUp folder (and whether this could be related to why I'm still not seeing any puts output on the console)
- Why Sketchup gives me an error in loading --rubygems when starting up, yet is able to run a script that references rubygems through the same file succesfully.
- Why I am getting a server timeout from Sketchup Bridge (although this might be worthy of putting in a different topic)
By the way, if anyone here thinks this discussion is not specific enough or is rambling, please let me know and I can take it down. I respect the sanctity of this forum and don't wish to be a nuisance in any respect.
-
@pratikthaker said:
At this point, my first observation is that the
$;.unshift "../lib"
command did NOT add the '../' path to the load paths. Any idea why?
This is problem 1
You are assuming the current working dir is your lib directory.
Any script that runs before yours can change it. And I think the SketchUp initialization also trys to set it to the User's %HOME% dir. (%UserProfile% on PC.)So IF you had an string var holding your base lib path:
basedir
Then you need to do:
basedir = %q[C:\Users\Pratik\Development\SketchupLeap\LeapFiles\ruby-leap-motion-ws-master] $:.unshift File.join(basedir,"lib") $:.unshift File.join(basedir,"samples")
%q
is a special interpreter function that means single-quoted string.
%
and%Q
mean double quoted string.
You can choose any delimiter char (or bracket set,) you like.Ruby path strings use slashes. Backslashes are special characters in double-quoted strings.
For example.. the "\r" in your double-quoted path string would come out as a Return character. ("\n" is a newline, "\t" is a tab, etc.)
This is why I say use single-quoted strings for paths, or you can escape the slashes, by using double slashes. ie
"C:\\ruby187\\bin"
-
@pratikthaker said:
- SketchUp was still able to execute ruby scripts despite not having anyversion of msvcrt-ruby18.dll in the SketchUp folder (and whether this could be related to why I'm still not seeing any puts output on the console)
When you installed Ruby 187, it should have prepended the
"C:\Ruby187\bin"
path to your environment %PATH% var, or perhaps set some ruby specific env vars.Use the
%(#800080)[set]
command, in a cmd shell to see what's set.However you really should have SketchUp loading the DLL from it's own program dir.
And also it is best (I am told,) to use a Ruby distro that is compiled with MS Visual Studio. The one you downloaded was compiled with the minGW compiler, which may result in a incorrect path for the platform specific sub-dir, of the standard ruby lib path (if the constant
RUBY_PLATFORM
is used to build that path.) -
@pratikthaker said:
So continuing on, I checked the location of my rubygems file, and realized it was in the 'site_ruby' folder. I therefore went ahead and uncommented that line from the load path script. I also made sure the path to the ruby folder was correct and case-sensitive.
This is the normal place for gems to be installed, in a normal ruby installation.
"site-ruby" really means "user"@pratikthaker said:
Now, something strange happens:
On restarting Sketchup, I get the following message in the 'Load Errors' dialog:@unknownuser said:
Error Loading File leap-motion-ws.rb
no such file to load -- rubygemsOK.. no one that to know of has gotten rubygems to work YET, under any embedded ruby environment like SketchUp or DoubleCAD.
It wasn't really meant to.
It would be better to convert your gem (if it is already built,) into a SketchUp plugin.
Put it's files into a sub-dir of the "Plugins" folder.And comment out any lines that try to load rubygems.
-
Hi Dan, you're a trove of information. Thank you!
Regarding the 'unshift ../lib' issue, I'll go ahead and save the path to a basedir var like you mention. For the time being though I've gotten through the issue by copying the leap-motio-ws.rb file into the Skethcup plugins directory.
And as far as the gems, I'll go ahead and move them directly to the plugins folder like you suggested. I was under the impression that installing a Ruby gem actually 'installed' it the way programs get installed. But if it just copies the files to the gems folder, then I can do the same in the Sketchup plugins folder.
However, the the question I now have is regarding the Ruby dll. I checked my 'set' variables, and you are right - the "C:\Ruby187\bin" string is set in my PATH. So does this mean that by default the dll file in my Ruby187\bin folder is being used? In this case it doesn't matter if I copy the dll into the Sketchup folder right?
Let me tell you my main aim right now - what I am trying to do is get some sort of printed output to show up,preferably by having puts to output to my commandline when I run my script using the Sketchup Bridge executable. I assume using the full ruby dll will let me do this - am I correct? If not, please let me know the best way to do this.
And the reason this is important for me is that the script I am running works fine when I run it on normal Ruby, but it doesn't work in Sketchup (it causes sub.exe to return a 'server timeout' and directly loading the script in Sketchup causes it to crash). Without the puts output, it's impossible to know whats going wrong.
P.S. The script I am trying to run is 'motion_sample.rb' in the 'samples' folder in the following github repository: https://github.com/glejeune/ruby-leap-motion-ws. Esentially it is an event listener that listens for data coming through a websocket connection. If anyone can identify a potential problem with running a script like this in Sketchup please let me know.
-
@pratikthaker said:
And as far as the gems, I'll go ahead and move them directly to the plugins folder like you suggested.
I really meant to convert them to a SketchUp extension.
See the API doc on theSketchupExtension
class.All extensions go in their OWN subdir of the "Plugins" dir.
-
@pratikthaker said:
However, the the question I now have is regarding the Ruby dll. I checked my 'set' variables, and you are right - the "C:\Ruby187\bin" string is set in my PATH. So does this mean that by default the dll file in my Ruby187\bin folder is being used? In this case it doesn't matter if I copy the dll into the Sketchup folder right?
That is what I am speculating, yes.
-
@pratikthaker said:
Let me tell you my main aim right now - what I am trying to do is get some sort of printed output to show up,... please let me know the best way to do this.
You should open SketchUp's Ruby console. The menu item is on the Window menu.
From code:
Sketchup.send_action("showRubyPanel:")
or use the global method defined in "sketchup.rb":
require("sketchup.rb") show_ruby_panel()
After the console is open, you will see all
puts
output.You can also use the Ruby built-in File class to write output to a logfile.
-
You're not going to believe me, but the puts wasn't working in the Ruby console for the past 2 days, but it just started working right now. Ghost in the machine I guess.
I'm still getting a crash when I run the motion_sample.rb script I mentioned above. I think it might have to do with not being able to access the gems, although there is no error message. I'm investigating it and will get back with any questions.
Thanks again!
Advertisement