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

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

asked 2015-04-28 02:05:12 -0500

zhengangzhu gravatar image

updated 2017-08-05 13:24:28 -0500

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-28 15:27:59 -0500

updated 2015-04-29 22:54:56 -0500

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](

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.


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

// 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
yds[0].setString(2, "Sunday");
edit flag offensive delete link more


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 gravatar image zhengangzhu  ( 2015-04-28 20:05:47 -0500 )edit

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 gravatar image macumber  ( 2015-04-29 11:21:24 -0500 )edit

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 gravatar image zhengangzhu  ( 2015-04-29 21:33:22 -0500 )edit

@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 gravatar image macumber  ( 2015-04-29 22:52:07 -0500 )edit

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

zhengangzhu gravatar image zhengangzhu  ( 2015-05-20 03:38:44 -0500 )edit

Your Answer

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

Add Answer


Question Tools

1 follower


Asked: 2015-04-28 02:05:12 -0500

Seen: 258 times

Last updated: Apr 29 '15