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

Can I run a measure by c#

asked 2016-01-28 02:03:17 -0600

gg_student's avatar

updated 2017-04-16 14:43:33 -0600

I want to create a model by using c#. This is working. But now I want to run some measures before I start the simulation. I found the class BLCMeasure (link text) to get the Measure with his Path into the c# - project. But is there a way to run it or connect it to the model to run it automatically?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
4

answered 2016-01-28 07:55:35 -0600

Take a look at how unit testing is done, it gives you a framework to do just that. When you create a new measure, there's automatically a folder 'tests' created with it.

Basically, you can translate the following ruby code to c#.

If your measure.rb starts with :

 class NameOfMyMeasureClass< OpenStudio::Ruleset::ModelUserScript

Then here's basically how you would run a measure on a model:

# create an instance of the measure
measure = NameOfMyMeasureClass.new

# create an instance of a runner
runner = OpenStudio::Ruleset::OSRunner.new

# get arguments
arguments = measure.arguments(model)
argument_map = OpenStudio::Ruleset.convertOSArgumentVectorToMap(arguments)

# create hash of argument values.
# If the argument has a default that you want to use, you don't need it in the hash
args_hash = {}
args_hash["space_name"] = "New Space"
# using defaults values from measure.rb for other arguments

# populate argument with specified hash value if specified
arguments.each do |arg|
  temp_arg_var = arg.clone
  if args_hash.keys.include?(arg.name)
    assert(temp_arg_var.setValue(args_hash[arg.name]))
  end
  argument_map[arg.name] = temp_arg_var
end

# run the measure (supposes you already have your current model in the variable `model`)
measure.run(model, runner, argument_map)
result = runner.result

# show the output
show_output(result)

# assert that it ran correctly
assert_equal("Success", result.value.valueName)
edit flag offensive delete link more

Comments

thank you for your answer I tried to translate it. But there is no way to translate the measure.run(model,runner,argument_map, therefore it seems to be impossible to run a measure.

gg_student's avatar gg_student  ( 2016-02-01 05:24:07 -0600 )edit

Your measure written in C# must have a run method, no? If you're asking how you can run a measure written in Ruby from c#, that's another can of worm I dare not open...

Julien Marrec's avatar Julien Marrec  ( 2016-02-01 07:35:09 -0600 )edit

I have a solution. You can´t run a measure for his own. But you can load it to your model and OpenStudio will run it before simulation. That´s the easiest way to do this. Here is the code (very simple^^):

OpenStudio.Path Path = new Path("MeasurePath");
BCLMeasure.load(Path); //Now it is in OpenStudio
BCLMeasure measure = new BCLMeasure(Path);
measure.doSomthing();
gg_student's avatar gg_student  ( 2016-02-14 07:59:07 -0600 )edit

Your Answer

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

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2016-01-28 02:03:17 -0600

Seen: 237 times

Last updated: Jan 28 '16