• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Passing arguments on command line using Sketchup Bridge

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 851 Views 2 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.
  • P Offline
    pratikthaker
    last edited by 1 Oct 2013, 19:47

    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?

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 2 Oct 2013, 11:21

      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 an Array or Hash.

      Check the Code Snippets index (it's a sticky post.)

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • P Offline
        pratikthaker
        last edited by 3 Oct 2013, 18:44

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

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

        Advertisement