First time here? Check out the Help page!

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

how to set day of week for start day using C#

asked 10 years ago

zhengangzhu's avatar

updated 7 years ago

I can set it using C++

openstudio::model::YearDescription yd1 = model.getUniqueModelObject<openstudio::model::YearDescription>(); yd1.setDayofWeekforStartDay("Sunday");

In C#, there is a class YearDescription But I don't know how to set it into the Model

Anyone can help? Thanks

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
4

answered 10 years ago

updated 10 years ago

This should be about the same in C# as it is in C++. You will want to get the YearDescription object from the model using the method:

getYearDescription(model) // this method is not in C++, it is added by [this SWIG macro](https://github.com/NREL/OpenStudio/blob/develop/openstudiocore/src/model/Model_Common_Include.i#L268)

Then you can call your setDayofWeekforStartDay method on it. It is a little confusing but there is another class named YearDescription which is not part of the OpenStudio model, that class is in the utilities namespace and is likely what you were seeing.

UPDATED ANSWER

It looks like you are hitting a peculiarity of the C# bindings. Because all the classes are in the OpenStudio namespace, there are some naming conflicts in C# that don't occur in C++ or Ruby. Here is some code that should work:

OpenStudio.Model model = new OpenStudio.Model();

// create the year description object, the free function is defined in the namespace
// OpenStudioModelSimulation because it is instantiated in ModelSimulation.i
// https://github.com/NREL/OpenStudio/blob/develop/openstudiocore/src/model/ModelSimulation.i
OpenStudio.OpenStudioModelSimulation.getYearDescription(model);

// openstudio::model::YearDescription class conflicts with openstudio::YearDescription in C#
// we can use the OpenStudio Model's Workspace accessor methods as a workaround
// get all objects of type "OS:YearDescription", we know there will be one since it was created above
OpenStudio.WorkspaceObjectVector yds = model.getObjectsByType(new OpenStudio.IddObjectType("OS:YearDescription"));

// we can call WorkspaceObject methods to set values on this object, 
// see the OpenStudio.idd for available fields, indexes start at 0
// https://github.com/NREL/OpenStudio/blob/develop/openstudiocore/resources/model/OpenStudio.idd
yds[0].setString(2, "Sunday");
Preview: (hide)
link

Comments

Hi Macumber,

Thank you very much. For getYearDescription(model) do you mean it's a method of Model? There is no method named getYearDescription in the Model. Only one method public SWIGTYPEpboostoptionalTopenstudiomodelYearDescriptiont yearDescription();

I don't understand the type "SWIGTYPEpboostoptionalTopenstudiomodelYearDescriptiont".

zhengangzhu's avatar zhengangzhu  ( 10 years ago )

getYearDescription(model) is not a member of the OpenStudio::Model::Model class, it is a free function in the OpenStudio::Model namespace that takes an OpenStudio::Model::Model object as input.

macumber's avatar macumber  ( 10 years ago )

I'm very sorry I have problems to use the C# API to call this function. Could you show me the code example to use this function?

With following code the function can't be recognized using OpenStudio; Model model = new Model(); getYearDescription(model);

zhengangzhu's avatar zhengangzhu  ( 10 years ago )

@zhengangzhu I hope the updated code above can help you get unstuck. If you are able to, please share what you are working on, we love to hear about what people are doing with the OpenStudio API!

macumber's avatar macumber  ( 10 years ago )

Thanks very much Macumber, due to the company policy I can't tell you the details at this stage.

zhengangzhu's avatar zhengangzhu  ( 9 years ago )

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: 10 years ago

Seen: 418 times

Last updated: Apr 29 '15