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

Using eppy to retrieve idf objects fieldnames

asked 2016-07-26 10:21:18 -0600

andrea.botti's avatar

updated 2016-07-27 04:21:31 -0600

Hello, I am a eppy beginner and am trying to replace certain parameters with @@labels@@ in order to prepare an idf file for jeplus. The first step would be to retrieve the Z coordinates for walls and ceilings' top vertexes. Having written the code:

**surfaces = idf1.idfobjects['BUILDINGSURFACE:DETAILED']**
**surf_names = [surface.Name for surface in surfaces]** 

geometry = idf1.idfobjects['buildingsurface:detailed'.upper()]
idf_ceiling = 'RoofCeiling'
idf_wall = 'Wall' idf_floor = 'Floor'

for s in surfaces:
    if sub in s:
        print s; #print geometry[s].area

returns the error:

AttributeError: 'Idf_MSequence' object has no attribute 'fieldnames'

edit retag flag offensive close merge delete

Comments

You are trying to get the fieldnames of a sequence. You want to get the fieldnames of an object. The snippet of code you've posted doesn't explain why you are looping over surf_names or what is in surf_names. You need to loop over each of the objects in the geometry sequence and test each of those for a match.

TomB's avatar TomB  ( 2016-07-26 17:03:43 -0600 )edit

Apologies, I had only copied part of the code. See if my edit makes sense now

andrea.botti's avatar andrea.botti  ( 2016-07-27 04:22:40 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-07-27 05:36:56 -0600

updated 2016-07-27 06:59:39 -0600

It's not totally clear to me what you're trying to do but to get the maximum z-coordinate of a surface you can use the surface.coords attribute to do:

surfaces = idf.idfobjects['BUILDINGSURFACE:DETAILED']
for s in surfaces:
    max_z = max(pt[2] for pt in s.coords)
    print "%s: %.2f" % (s.Name, max_z)

If you want to to substitute the value in the maximum z-coordinates of walls and roof/ceiling to change the ceiling height:

surfaces = idf.idfobjects['BUILDINGSURFACE:DETAILED']
walls_and_roofs = [s for s in surfaces if s.Surface_Type in ['Wall', 'Roof']]
for s in surfaces:
    max_z = max(pt[2] for pt in s.coords)
    for field in s.fieldnames:  # or "for field in s.objls:" if using version <= 0.5.2
        if 'ZCOORDINATE' in field.upper() and s[field] == max_z:
            s[field] = '@@ceiling_height@@'
    print s

Will output:

BuildingSurface:Detailed, 
    MyRoof,                   !- Name
    Roof,                     !- Surface Type
    Exterior Roof,            !- Construction Name
    Zone1,                   !- Zone Name
    Outdoors,                 !- Outside Boundary Condition
    ,                         !- Outside Boundary Condition Object
    SunExposed,               !- Sun Exposure
    WindExposed,              !- Wind Exposure
    ,                         !- View Factor to Ground
    4,                        !- Number of Vertices
    2.23,                     !- Vertex 1 Xcoordinate
    2.52,            !- Vertex 1 Ycoordinate
    @@ceiling_height@@,                     !- Vertex 1 Zcoordinate
    2.23,                     !- Vertex 2 Xcoordinate
    1.02,            !- Vertex 2 Ycoordinate
    @@ceiling_height@@,                     !- Vertex 2 Zcoordinate
    3.22,                     !- Vertex 3 Xcoordinate
    1.02,            !- Vertex 3 Ycoordinate
    @@ceiling_height@@,                     !- Vertex 3 Zcoordinate
    3.22,                     !- Vertex 4 Xcoordinate
    2.52,            !- Vertex 4 Ycoordinate
    @@ceiling_height@@;                     !- Vertex 4 Zcoordinate


BuildingSurface:Detailed, 
    MyWall,                   !- Name
    Wall,                     !- Surface Type
    Exterior Wall,            !- Construction Name
    Zone1,                   !- Zone Name
    Outdoors,                 !- Outside Boundary Condition
    ,                         !- Outside Boundary Condition Object
    SunExposed,               !- Sun Exposure
    WindExposed,              !- Wind Exposure
    ,                         !- View Factor to Ground
    4,                        !- Number of Vertices
    2.23,                     !- Vertex 1 Xcoordinate
    2.52,            !- Vertex 1 Ycoordinate
    @@ceiling_height@@,                     !- Vertex 1 Zcoordinate
    2.23,                     !- Vertex 2 Xcoordinate
    2.52,            !- Vertex 2 Ycoordinate
    0.0,                      !- Vertex 2 Zcoordinate
    2.23,                     !- Vertex 3 Xcoordinate
    2.56,                     !- Vertex 3 Ycoordinate
    0.0,                      !- Vertex 3 Zcoordinate
    2.23,                     !- Vertex 4 Xcoordinate
    2.56,                     !- Vertex 4 Ycoordinate
    @@ceiling_height@@;                     !- Vertex 4 Zcoordinate
edit flag offensive delete link more

Comments

1

that is precisely what I am trying to achieve! So far I managed to write a long piece of code that I am bit embarassed to post though!

andrea.botti's avatar andrea.botti  ( 2016-07-27 05:58:25 -0600 )edit

@andrea.botti the edited code should produce what you need. It would actually be really useful to have a simple geometry editor based on eppy so there may be an easier way of doing this in the future.

Jamie Bull's avatar Jamie Bull  ( 2016-07-27 06:30:18 -0600 )edit

Jamie, thank you loads for that. I am slowly making some progress understanding eppy's rationale. However, I receive the error:

eppy.bunch_subclass.BadEPFieldError: unable to find field fieldnames

this has happened to me before (having issues with fieldnames)

andrea.botti's avatar andrea.botti  ( 2016-07-27 06:44:24 -0600 )edit

Ah, I see. I was running that code on the develop branch of eppy where I've added some "friendly" aliases for some of the internal data structures. I see it's not yet been included in the master branch. If you switch fieldnames for objls then it should work for you.

Jamie Bull's avatar Jamie Bull  ( 2016-07-27 06:57:02 -0600 )edit

You're an eppy king!!

andrea.botti's avatar andrea.botti  ( 2016-07-27 07:19: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: 2016-07-26 10:21:18 -0600

Seen: 608 times

Last updated: Jul 27 '16