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

Revision history [back]

click to hide/show revision 1
initial version

openstudio python bindings

I am dabbling with using the FreeCAD BIM Workbench to generate geometry for the .OSM file. FreeCAD is very powerful and has built-in Python capability. At this point, I can generate some simple spaces. However, I'd like to check adjacent surfaces and am running into a problem transferring the boost::optional approach from Ruby to Python. In Ruby, I would do the following (more or less, I am not in Ruby right now):

model.getSurfaces().each do |surface|
  adjacent_surface = surface.adjacentSurface()
  unless adjacent_surface.empty? then
    puts surface.name
    puts adjacent_surface.get.name
  end
end

With this, I would obtain just the names (simple strings) of surface and adjacent_surface, as desired.

In Python, I am trying the following:

for surface in model.getSurfaces():
  adjacent_surface = surface.adjacentSurface()
  if adjacent_surface is not None:
    print(surface.name)
    print(adjacent_surface.get.name)

But the "get.name" part in the last line results in this error: AttributeError: 'function' object has no attribute 'name'. And if I use just "get", the following is an example output:

<bound method IdfObject.name of <openstudio.openstudiomodelgeometry.Surface; proxy of <Swig Object of type 'std::vector< openstudio::model::Surface >::value_type *' at 0x7fea7ab0f870> >>

<bound method OptionalSurface.get of <openstudio.openstudiomodelgeometry.OptionalSurface; proxy of <Swig Object of type 'openstudio::model::OptionalSurface *' at 0x7fea66d46630> >>

That is to say, not even non-boost::optional surface shows the name. Both it and boost::optional adjacent_surface just show what appears to be a type or class specification. How can I get the simple name strings here?

openstudio python bindings

I am dabbling with using the FreeCAD BIM Workbench to generate geometry for the .OSM file. FreeCAD is very powerful and has built-in Python capability. At this point, I can generate some simple spaces. However, I'd like to check adjacent surfaces and am running into a problem transferring the boost::optional approach from Ruby to Python. In Ruby, I would do the following (more or less, I am not in Ruby right now):

model.getSurfaces().each do |surface|
  adjacent_surface = surface.adjacentSurface()
  unless adjacent_surface.empty? then
    puts surface.name
    puts adjacent_surface.get.name
  end
end

With this, I would obtain just the names (simple strings) of surface and adjacent_surface, as desired.

In Python, I am trying the following:

for surface in model.getSurfaces():
  adjacent_surface = surface.adjacentSurface()
  if adjacent_surface is not None:
    print(surface.name)
    print(adjacent_surface.get.name)

But the "get.name" part in the last line results in this error: AttributeError: 'function' object has no attribute 'name'. And if I use just "get", the following is an example output:

<bound method IdfObject.name of <openstudio.openstudiomodelgeometry.Surface; proxy of <Swig Object of type 'std::vector< openstudio::model::Surface >::value_type *' at 0x7fea7ab0f870> >>

<bound method OptionalSurface.get of <openstudio.openstudiomodelgeometry.OptionalSurface; proxy of <Swig Object of type 'openstudio::model::OptionalSurface *' at 0x7fea66d46630> >>

That is to say, not even non-boost::optional surface shows the name. Both it and boost::optional adjacent_surface just show what appears to be a type or class specification. How can I get the simple name strings here?