How to extract programs and constructions

Hi there,

I am trying to deconstruct the hbjson to extract programs and constructions, but I cannot find any component that allows retrieving such information from room objects.
As far as I know, such information should be present in the hbjson file, as their names can be visualised through the appropriate visualisation components.
Does anyone know if it is possible to accomplish this?

Thanks
Matteo

Hello @chris, do you have any advice about this?

Hi @MatteoMerli,

You can get this functionality with a simple python component.

For example, starting with a model and the default GHPython component, plug the HB Model object into the x input.

Then if you open the component and add at the bottom

for room in x.rooms:
    a = room.properties.energy.program_type 

Then when you press ok, the an output of the GHPython component should give you the program types for each room.

Typing this on my phone so trying to do this from memory!

If you look here it shows you what other properties are available on each room using python, including construction_set, etc.

https://www.ladybug.tools/honeybee-energy/docs/honeybee_energy.properties.room.html

2 Likes

Thanks @charlie.brooker, it works!
I adjusted the code to get program types for each room instead of just the first one:

programs = []
for room in x.rooms:
    programs.append(room.properties.energy.program_type)
a = programs

This method only works if the input is the entire model. Do you know what changes I should make to use individual rooms as input? This could be useful for other codes with faces as well.

1 Like

Nice work @MatteoMerli!

If you’re inputting rooms then x becomes “rooms” instead of a model. So in this case you should need an even simpler bit of code removing for loop that goes through each room like so:

a = x.properties.energy.program_type

I think if you give this a list of rooms you should get a list of program_types out, without the need for appending a list, but I could be wrong.

Likewise if you make the x input faces then you can access the face properties like so

a = x.properties.energy.INSERT_FACE_PROPERTY

You can find the available face properties here:
https://www.ladybug.tools/honeybee-energy/docs/honeybee_energy.properties.face.html

2 Likes

Really glad to see you using the LBT Python SDK since that’s the ultimate answer to getting any attribute that you want for a Honeybee object (even those not exposed on the visualization components). It’s also the most efficient way to get the attribute.

I just wanted to add something in case there are some users watching this topic who are not yet at the level of using the LBT Python SDK. You can also use the HB Color Room Attributes and the HB Color Face Attributes components to get the attributes assigned to any Honeybee Room, Face or Aperture/Door. And you can see that the components return the actual object, which can be deconstructed with other components (not just the name of the attribute):


get_honeybee_attributes.gh (60.2 KB)

So you can use that if you need a solution with the existing LBT Grasshopper components.

4 Likes

Hi @charlie.brooker and @chris,

many thanks for your answers!

Best,
Matteo

1 Like

@chris .Just bumping this thread – is there a way to get almosts a topological representation of a honeybee zone model?

E.g. For each zone (node) you have a list of the zones (nodes) it is connected to, and the edges represent the surface/face they share with all the face attributes, u-values etc?

Maybe there is a different thread already talking about this

I tried this technique with latest HB tools and I only get the string name of the program object… I can’t decompose it as shown in the screenshot…

Hi @grahamjlinn ,

The above process works in version 1.8.79

If I had to guess, the issue is more likely that you are passing in the name of a Program which is not part of the default ‘built-in’ collection?

As shown above, passing a string to the ‘Decompose’ works fine, since that component searches the built-in Program collection for the name. But, if your program is not in the built-in collection, it will not be able to find it, and will raise an error. In that case, you would need to pass in the actual ProgramType object, not a string of the Program’s name.

hope that helps,
@edpmay

Example file:

example.gh (49.5 KB)

Thanks Ed!

Yeah I am using a custom construction… I wasn’t sure if only built in constructions could be referenced and now you have clarified, thank you!

As an alternative I built out a python routine to extract the program as suggested earlier in this thread. One note on this - I tried to use the basic python component but it doesn’t recognize the honeybee commands. Instead I tried the IronPython component and that has been working.

I tried to use the basic python component but it doesn’t recognize the honeybee commands.

Interesting… @chris had mentioned that the LBT libraries should be accessible from the new Python components, as well as the old GhPython ones:

“… Lastly, I’ll add that the latest Pollination installers add the Ladybug Tools core libraries to the Python paths of the Rhino 8 Script Editor. So, if you use the latest Pollination installer, you should not have any more import errors if you try pasting code from LBT’s GHPython components into a new ScriptEditor component. This means that you can technically use the LBT core libraries in the Rhino 8 script editor if you want.”
Scritping in R8, ironpython2 and python 3? - #4 by chris

I’m curious which part didn’t work in the new editor for you?

@edpmay

Here’s a side by side of the code snippet with Py3 component and IronPython component

This is my first time using any python components in grasshopper so not sure what might be happening. Reading through old forum posts I see lots of references to “ghpython” and I thought I was supposed to use that component but I can’t find it anywhere… tried to use rhino package manager, looked on food4rhino, doesn’t seem to exist anymore? Anyway I tried IronPython based on some unrelated forum suggestion and it worked

I’m on Rhino8 latest release if that helps

Ah I see - gotcha.

Yes it is definitely confusing with all the different python components and environments now. Happy to provide a little background if it is helpful:

  • Pre-Rhino 8 there was something call the GhPython component, which allowed you to write and execute python code using the IronPython interpreter. This is what all the existing Honeybee-components use.
  • Now, in Rhino-8, there is a new IronPython component, and a new Python3 component. But the ‘old’ GhPython component still exists - it is just ‘hidden’ by default though. So to access it you have to type #GhPython in Grasshopper to get access to it (note the ‘#’ symbol).
  • So while it is true you can import and use the LBT python libraries in the different editors (GhPyhon, IronPython, Python3), you cannot pass actual python ‘objects’ (in this case the ‘room’) between the different editors.
  • You can think of the different editors as existing independently and in parallel to one another. They don’t know about each other, and can’t really talk to one another well. While it is technically possible to pass some simple objects between them, it is complicated and not recommended.
  • So since the Honeybee-room is made in the ‘old’ GhPython one, you can not pass it to the ‘new’ Python3 one to pull out the program_type attribute. Since it was made in. GhPython, it has to stay in GhPython.

hope that helps!

@edpmay

4 Likes

Thanks! That’s a really helpful summary