Passing arguments on command line using Sketchup Bridge
-
Hi Guys,
I am new to this whole Sketchup programming (and Ruby in general as a matter of fact). I had a question on passing arguments into a Sketchup script.
You see, what I am trying to do is control Sketchup scripts from within an IDE (Eclipse) where I have other code in Java calling Sketchup scripts when required. Now to do this, I have downloaded the 'Sketchup Bridge' and am calling my scripts from my code like so:
"SUB.exe sketchupscript.rb"
Now, what I want to do is to pass some arguments to the Sketchup script depending on conditions in my Java program.
For example, I would like to control the zoom factor in a simple Sketchup Ruby script that just zooms. However, I cannot seem to make it work. Here is what I am doing:
Here is my simplified script:
zoominargs.rb:
zoomfactor = ARGV[0]
Sketchup.active_model.active_view.zoom(zoomfactor)I am then testing it by typing the following on the command line:
SUB.exe zoominargs.rb 1.03
However, on doing so, nothing happens, although I do sometimes get the error "wrong argument type (expected Sketchup::Entity)"
(Note that when I hardcode the value in the script, ie. "Sketchup.active_model.active_view.zoom(1.03)", it works perfectly fine)
Any ideas on how I can make this work?
-
The
ARGV
array is loaded by ruby.exe or rubyw.exe.If you were using Ruby in a normal way, as a shell scripting engine, then you COULD pass arguments into a script.
BUT.. the executable loaders are NOT used when an application loads the interpreter DLL (or framework,) as an embedded scripting engine. (So
ARGV
is empty.)Sorry.. but you need to take some of the Ruby Documentation "with a grain of salt" because most of it is written for shell scripting.
What you would need to do is have your Java script write a data file, say CSV.
Name it the same as the ruby script but with a different file extension.
Then your script opens the data file and reads the data into anArray
orHash
.Check the Code Snippets index (it's a sticky post.)
-
Hi Dan,
Thanks a lot for the reply!
Having the Java program write to a file and then having the Sketchup script read it in is a good idea. I'm going to try that. Can I use the 'File' object to accomplish this in a Sketchup script?
Having said that, for me latency is an issue, and I don't know if the time for writing and reading from the disk will slow me down - but I guess I'll only know after I try.
Actually what I am trying to accomplish is have a controller control the camera in the Sketchup model. The controller has APIs in a bunch of languages (Java, C++, Javascript), but none in Ruby. There is one interface created by a third party that uses SWIG to wrap the C++ functions and make it accessible in Ruby, but those are 'listeners', and I don't know if they would work within Sketchup Ruby.
Do you know if it is possible to have the a .rb script, run via the Sketchup Bridge from within an IDE, that acts as a listener? (Sorry if this is a bit vague - I'm don't have much experience integrating a scripting language like Ruby with something like Java or C++. Let me know if I can clarify this further).
Advertisement