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

How do you create or alter a subsurface in OS measure

asked 2015-09-02 13:58:45 -0600

updated 2017-08-05 13:04:08 -0600

I'm trying to write a measure to scale my existing windows according to a scale factor.

I've worked out the math. I have the new coordinates (x,y,z, either as is, in a Vector (from matrix) or an OpenStudio::Model::Point3d) of each point of said subsurface.

I just can't figure how to alter the subsurface, or to delete it and recreate one. Any help?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2015-09-02 14:05:35 -0600

updated 2015-09-02 14:06:02 -0600

This code snippet from the measures repo should help you:

# create a new set of vertices
newVertices = OpenStudio::Point3dVector.new

# get the existing vertices for this interior partition
vertices = surface.vertices

vertices.each do |vertex|

  # initialize new vertex to old vertex
  x = vertex.x
  y = vertex.y
  z = vertex.z - 1

  # add point to new vertices
  newVertices << OpenStudio::Point3d.new(x,y,z)
end

# set vertices to new vertices
surface.setVertices(newVertices) #todo check if this was made, and issue warning if it was not. Could happen if resulting surface not planar.
edit flag offensive delete link more

Comments

I had just figured it out in the meantime. I think I suck at reading the online documentation, or it's cryptic, or both (examples, including in ruby, would help a ton with making it more usable)

Julien Marrec's avatar Julien Marrec  ( 2015-09-02 14:22:41 -0600 )edit

We have talked about making one or more of our measure repositories public. This would allow you to take an OpenStudio object or method, and then search for any measures that use that object or method. Having a block of functioning code as reference is really helpful. That could be something you add as a user voice request.

David Goldwasser's avatar David Goldwasser  ( 2015-09-02 20:00:43 -0600 )edit

Oh I thought the measures repo was public sorry for the non-functioning link.

macumber's avatar macumber  ( 2015-09-02 20:32:51 -0600 )edit
1

answered 2015-09-02 14:21:02 -0600

Another case of asking a question and finding the answer right after.

Each surface (and subsurface) has a setVertices method which accepts a vector of Point3d.

Let's say you want to only change the third vertices of a triangle. s is a Surface or SubSurface

# First two points stay the same
a = s.vertices[0]
b = s.vertices[1]

# Create a new point at (x, y, z) = (0, 1, 2)
c_prime = OpenStudio::Point3d.new(0, 1, 2)

# Do the change
s.setVertices([a, b, c_prime])
edit flag offensive delete link more

Comments

2

Does:

s.setVertices([a, b, c_prime])

work? In that case you are actually passing a Ruby Array to setVertices. In my example, you create a Point3dVector and pass that to setVertices. The C++ method expects a Point3dVector. If you example works then SWIG has gotten even fancier about converting from Ruby types to C++ types :-)

macumber's avatar macumber  ( 2015-09-02 14:47:06 -0600 )edit

Yep, as far as I can tell it works! No error is thrown, and the resulting point3d seems to have the intended x, y, z coordinates

Julien Marrec's avatar Julien Marrec  ( 2015-09-02 17:54:12 -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: 2015-09-02 13:58:45 -0600

Seen: 234 times

Last updated: Sep 02 '15