2

Measure written in Python

Does the measure have to be written in Ruby?

I noticed there is a python version of measure file in OpenStudio Example directory, but when I run it returns the error message “Can’t find measure xxx” in initialization state.

Not sure if I can use python to write measure instead of Ruby.

Kunyu's avatar
57
Kunyu
asked 2023-03-03 01:32:25 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

2

At the moment you cannot write a Measure in python, it has to be written in Ruby if you want to use it as part of a Workflow (OSW).

There is some very experimental support in the labs subcommand of the openstudio command line interface (CLI). You can also write python scripts (or use the python REPL / jupyter notebooks) using the python bindings though.

Julien Marrec's avatar
29.7k
Julien Marrec
answered 2023-03-06 02:57:56 -0500
edit flag offensive 0 remove flag delete link

Comments

Merci Julien.

I got another question: how does the measure XML file be created? Should I code it by hand or is there any command in openstudio-sdk to do the conversion?

Kunyu's avatar Kunyu (2023-03-06 03:33:54 -0500) edit

You should get an XML when you generate a new measure using the BCL Template (using the OpenStudioApplication for example). Otherwise you can copy an existing one, but make sure you change the the <uid>(get one at https://www.uuidgenerator.net/version4 otherwise) so it's unique and doesn't clash with another measure.

To update the measure.xml use the CLI: openstudio measure --update <measure_dir>. It'll update the name, descriptions, arguments etc. The only things it won't touch are the things that are not in your measure.rb file, so tags, eventually the minimum openstudio version.

Julien Marrec's avatar Julien Marrec (2023-03-06 04:00:42 -0500) edit

Note that you can also generate a new measure from the template like the OSApp does using the OpenStudio CLI: openstudio -e "OpenStudio::BCLMeasure.new('My measure is cool', 'MyNewMeasure', File.expand_path('./MyNewMeasure'), 'Envelope.Fenestration', 'ModelMeasure'.to_MeasureType, 'This is my measure description', 'This is the developer description', 'Ruby'.to_MeasureLanguage)".

cf SDK documentation at: https://openstudio-sdk-documentation....

Julien Marrec's avatar Julien Marrec (2023-03-06 04:02:03 -0500) edit
1

got it! Merci beacoup!

Kunyu's avatar Kunyu (2023-03-07 20:12:37 -0500) edit
add a comment see more comments