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

multiple openstudio installations

asked 2020-02-12 23:06:48 -0600

ngkhanh gravatar image

updated 2020-02-14 10:51:16 -0600

I have both OpenStudio versions 2.8.1 and 2.9.1 installed on my Mac with rbenv Ruby 2.2.4 and .bash_ profile setup as follow:

## add openstudio 
export PATH="/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_8_1/bin:$PATH"
export RUBYLIB="/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_8_1/Ruby/"

wonder how to programtically jump between 2 versions (2.8.1 and 2.9.1) for scripting works?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2020-02-13 07:26:57 -0600

updated 2020-02-13 07:27:42 -0600

I do not ever set these variables in the .bash_profile. I just symlink the openstudio CLI you want to use in /usr/local/bin (or equivalent).

For use in interactive ruby, I use pry with a .pryrc personally. (gem install pry).

You can just write ruby code to be executed before the session starts.

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.3")
  # Do something
else
  # Do something else
end

I have a prompt actually that allows me to select either openstudio installed or my local builds

print "Do you want OpenStudio (os) or os-debug (1) / os-release (2), or os-app-debug (3) / os-app-release (4): [os/1/2/3/4] "
input = gets.strip

# This typically loads a custom build installed on my computer
if input == '1'
  p = File.join(ENV["HOME"], "Software/Others/OS-build/Products/ruby/openstudio")
elsif input == '2'
  p = File.join(ENV["HOME"], "Software/Others/OS-build-release/Products/ruby/openstudio")
elseif ...

else
  p = 'openstudio' # Installed openstudio
end

require p
puts "Loading '#{p}': #{OpenStudio::openStudioLongVersion}"

In your case, you can revamp that easily to have that prompt require either 2.8.1 or 2.9.1

print "Do you want OpenStudio 2.8.1 (1) or 2.9.1 (2): [1/2] "
input = gets.strip

if input == '1':
  p = '/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_8_1/Ruby/openstudio'
else
  p = '/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_9_1/Ruby/openstudio
end

require p
puts "Loading '#{p}': #{OpenStudio::openStudioLongVersion}"
edit flag offensive delete link more
0

answered 2020-02-13 10:30:39 -0600

ngkhanh gravatar image

updated 2020-02-13 10:33:04 -0600

Thanks Julien for useful code. While I just work with one or two versions at same time, I find out this setup lauch for VS Code (other IDE would be similar). My key concern is require 'openstudio' needs proper RUBYLIB path. Not sure how to setup RUBYLIB inside script

"configurations": [
        {
            "name": "RunFile",
            "type": "Ruby",
            "request": "launch",
            "cwd": "${fileDirname}",
            "program": "${file}",
            "env":
                {  
                    "OS_291": "/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_9_1/bin/openstudio",
                    "RUBYLIB":"/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_9_1/Ruby"
                }
        }
    ]
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: 2020-02-12 23:06:48 -0600

Seen: 32 times

Last updated: Feb 13