Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
5

Can I import/require OpenStudio SDK (Ruby bindings) into IRB?

asked 2016-01-22 13:15:43 -0500

Yes? No? What's the secret handshake?

edit retag flag offensive close merge delete

Comments

If you can get IRuby to work on your machine that would be my suggestion for a more pleasant IPython-like experience to IRB.

MatthewSteen gravatar imageMatthewSteen ( 2016-01-22 13:51:17 -0500 )edit

4 Answers

Sort by ยป oldest newest most voted
2

answered 2016-01-22 13:35:46 -0500

updated 2016-01-22 13:40:55 -0500

Yeah; I have an environment variable path set to C:\Program Files\OpenStudio 1.10.0\ruby-install\ruby\bin, and can require 'openstudio' from within irb to access the SDK.

...I think there are additional steps if you're not using the ruby that's shipped with OS. See the 'Optional - Install Ruby' subsection of 'Installation Steps' on this page.

edit flag offensive delete link more

Comments

Thanks! For those who care, the MacOS magic is export PATH="/Applications/OpenStudio 1.10.0/Ruby:$PATH". Works with Ruby/IRB that ships with MacOS also.

__AmirRoth__ gravatar image__AmirRoth__ ( 2016-01-22 14:31:58 -0500 )edit
3

answered 2016-01-22 21:35:48 -0500

updated 2016-01-23 10:56:16 -0500

As Kyle mentioned, there is a way to customize the irb startup configuration. You have to do the following (assuming Mac or Linux):

If ~/.irbrc does not exist, call touch ~/.irbrc to create it.

Then inside ~/.irbrc you can put

// I think this is the correct pathing    
require "/Applications/OpenStudio 1.10.0/Ruby/openstudio.rb"
require 'irb/completion'

or what I have in my ~/.irbrc file (other than different openstudio.rb path for my dev build)

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] = [] unless IRB.conf.key?(:LOAD_MODULES)
unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
  IRB.conf[:LOAD_MODULES] << 'irb/completion'
end
require "/Applications/OpenStudio 1.10.0/Ruby/openstudio.rb"

This will automatically load completion and openstudio everytime you call irb on command line.

edit flag offensive delete link more

Comments

That's cool, thanks Mark!

macumber gravatar imagemacumber ( 2016-01-23 09:52:41 -0500 )edit
2

answered 2016-01-22 14:25:35 -0500

I specify the paths on the command line like this (on Windows for version 1.10.0):

C:\Users\jdegraw>"C:\Program Files\OpenStudio 1.10.0\ruby-install\ruby\bin\irb" -I "C:\Program Files\OpenStudio 1.10.0\Ruby\openstudio"

I like doing it this way because it also works for my development build if I change out the paths.

edit flag offensive delete link more

Comments

Again, irb -I /Applications/OpenStudio 1.10.0/Ruby for enlightened Mac users.

__AmirRoth__ gravatar image__AmirRoth__ ( 2016-01-22 14:34:56 -0500 )edit

another little gem. In Ruby 2.0 and beyond, at least on Mac, irb completion stopped being loaded by default. The first thing I always do after require 'openstudio' is require 'irb/completion'. Then your tab completion will work.

Kyle Benne gravatar imageKyle Benne ( 2016-01-22 14:37:57 -0500 )edit

@Kyle Benne It is also apparently true on Windows. Thanks for pointing this out, was beginning to think something was wrong with my tab key.

Jason DeGraw gravatar imageJason DeGraw ( 2016-01-22 14:53:36 -0500 )edit

I'm pretty sure there is a way to customize irb's startup environment but I never bothered to look into it.

Kyle Benne gravatar imageKyle Benne ( 2016-01-22 15:43:30 -0500 )edit

RubyMine (mac and windows) lets you change what version of ruby you use under the run configuration.

David Goldwasser gravatar imageDavid Goldwasser ( 2016-01-22 20:28:01 -0500 )edit
1

answered 2016-01-25 01:36:54 -0500

updated 2016-01-25 01:37:23 -0500

For the sake of using the official documentation out there, specifically the "Getting Started" tutorial:

Optional - Install Ruby If you plan to use the OpenStudio SDK Ruby bindings via command prompt on Windows, you must install Ruby. OS X already has Ruby installed.

Download the Ruby 2.0.0 installer. If you have the Windows (x64) version of OpenStudio (Help>About>Compiler shows Visual Studio 12 2013 Win64), you'll need the x64 Ruby installer. If you have the Windows (x32) version of OpenStudio, you'll need the non-x64 Ruby installer.
Add `C:\Ruby200\bin` (or wherever you installed Ruby) to the PATH environment variable. Detailed instructions.

Create a text file with the following text inside:

`require 'C:\Program Files (x86)\OpenStudio 1.7.0\Ruby\openstudio.rb'`

Save the file as `openstudio.rb` here: `C:\Ruby200\lib\ruby\site_ruby\openstudio.rb` (next to the 2.0.0 folder).
Test your installation by opening a command prompt and typing: irb ENTER. Then, type require 'openstudio ENTER. If you see some QSslSocket messages and => true, it's working.

I personally have several of these files in there, usually two: openstudio.rb which points to the latest stable release, and openstudio-rc.rb which points to a release candidate. This way I can require any of these two as needed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

 



Question Tools

2 followers

Stats

Asked: 2016-01-22 13:15:43 -0500

Seen: 247 times

Last updated: Jan 25 '16