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

Using C++ Cast in OpenStudio Python SDK

asked 2015-02-18 12:39:41 -0500

updated 2015-07-11 13:40:03 -0500

I'm trying to create HVAC nodes using the Python bindings for the OpenStudio SDK. I'm running into a challenge with casting the ModelObject type to a Node type. It seems relatively simple in C++, but I'm unsure of the Python commands. I'm currently trying to follow this example from the OpenStudio source code.

 Node fanInletNode = fan.inletModelObject()->cast<Node>();
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
9

answered 2015-02-18 14:00:33 -0500

You can cast in Python but the syntax is slightly different compared to C++ and Ruby/C# bindings.

from openstudio import model
# model namespace (OpenStudio::Model::toNode), not an instance of model
fan_inlet_node = model.toNode( fan.inletModelObject().get() ).get() 
# have to use .get() since both functions return optionals

There are no convenience methods yet for Python to do fan.inletModelObject().toNode() or anything like that.

edit flag offensive delete link more

Comments

Thanks @mark-adams, I thought there was something but missed that, here is the relevant wrapping code

macumber's avatar macumber  ( 2015-02-18 15:02:22 -0500 )edit

@Mark Adams. That is exactly what I needed. Thanks.

jmcneill's avatar jmcneill  ( 2015-02-18 15:33:44 -0500 )edit
3

answered 2015-02-18 12:46:00 -0500

I don't think that casting has been implemented for Python yet, if it was it would go here or here.

If you are able to use IronPython you can use the C# bindings which have a larger feature set. Otherwise, we'll just have to add a feature request for this.

edit flag offensive delete link more

Comments

@macumber unfortunately, IronPython isn't ideal due to the other python libraries that I am using. Is there another way to is used to determine the nodes defined on an HVAC component? My understanding is that is the reason for using casting. Is my understanding correct?

jmcneill's avatar jmcneill  ( 2015-02-18 12:50:51 -0500 )edit

@kyle-benne might be able to provide some alternatives

macumber's avatar macumber  ( 2015-02-18 12:56:55 -0500 )edit

@jmcneill Im not sure what you are trying to accomplish but you could retrieve all of the nodes from a system, in order, with something like air_loop.supplyComponents(OpenStudio::Model::Node::iddObjectType()). This will return them as generic ModelObject instances which you could at least call ModelObject::name() on. This is Ruby like syntax, but you can probably translate to Python. I think the most direct answer to your question is what Mark said. He is the Python wizard of OpenStudio.

Kyle Benne's avatar Kyle Benne  ( 2015-02-18 15:03:11 -0500 )edit

@jmcneill Secondly you mentioned creating nodes. In general this is not a great idea. It is better to call HVACComponent::addToNode and let OpenStudio create new adjacent nodes if necessary and make the connections. While it is possible to create nodes through the API and connect things together it is very likely to break assumptions that OpenStudio makes about how models are constructed. Plus when it comes to the topology of connections OpenStudio will let you do most or all of what is possible in EnergyPlus. If you want to elaborate on your use case I can answer more specifically.

Kyle Benne's avatar Kyle Benne  ( 2015-02-18 15:06:31 -0500 )edit

@jmcneill and if you do want to ask a question about HVAC assembly / connections consider asking in the form of a completely separate question. I think this one was nicely asked by you and answered by Mark. A nice concise addition to the Unmet Hours forum. It just sounds like there might be a different question lurking here.

Kyle Benne's avatar Kyle Benne  ( 2015-02-18 15:09:55 -0500 )edit

Your Answer

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

Add Answer

Careers

Question Tools

1 follower

Stats

Asked: 2015-02-18 12:39:41 -0500

Seen: 334 times

Last updated: Feb 18 '15