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

Undefined Method for #

asked 2019-01-15 15:42:42 -0500

ParticleSwarm gravatar image

Hello Unmet!

I am trying to manipulate model object fields via a measure and have found the object that I need to modify, However whenever I attempt to use any of the method names for that object ie. "Set" I get an error saying "Undefined method [insert method name here] for #. I know I have the correct object variable because I am able to use the .name and print to the console.

It seems there must be a bridge to the Hash and the fields of the object.

edit retag flag offensive close merge delete


Unmet! Love it!

__AmirRoth__ gravatar image__AmirRoth__ ( 2019-01-15 19:42:04 -0500 )edit

I'd bet your object isn't a "Class" but "OptionalClass", eg it's zone a "ThermalZone" but an "OptionalThermalZone", which you have to .get() (after checking if .empty() of course) before you can access its methods.

Julien Marrec gravatar imageJulien Marrec ( 2019-01-16 05:42:45 -0500 )edit

Another possible cause in addition to what @Julien Marrec mentioned is if you are looping through schedules using model.getSchedules.each do and then try to use a method specific to scheduleRuleset like schedule.defaultDaySchedule. You would have to do schedule.to_ScheduleRuleset.get.defaultDaySchedule. Should of course check if it is initialized before using .get.

David Goldwasser gravatar imageDavid Goldwasser ( 2019-01-16 13:24:04 -0500 )edit

thank you guys for all of your help! I've tried different solutions to now avail. I am currently now using the model.getObjectByName("RefrigerationWalkInZoneBoundry"), checking .empty? and then using the .get and it's throwing the "Optional not Initialized" error. Is the name of my object off?

ParticleSwarm gravatar imageParticleSwarm ( 2019-01-17 11:46:07 -0500 )edit

Use model.getClassNames to retrieve a list of objects of class ClassName, eg: first_walkin = model.getRefrigerationWalkInZoneBoundarys[0]. Alternatively, use model.getRefrigerationWalkInZoneBoundaryByName("The Name of Your Walkin Object")

Julien Marrec gravatar imageJulien Marrec ( 2019-01-21 02:43:57 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-01-15 15:57:29 -0500

Call .class on the object and see what class it is.

The .name method is part of a base class that your object inherits, so just because the correct name shows doesn't mean you have the correct class. You can manipulate it to the correct class with .to_ClassName.get.

edit flag offensive delete link more



Where can we find the available generic methods? Most of the methods that I use in my measures come from reading other measures. I know we can use the SDK to find the methods available for a certain class, but where in the documentation would I find .to_ClassName?

luisclv gravatar imageluisclv ( 2019-01-15 17:02:21 -0500 )edit

The API reference is here, which is accessible from the openstudio developer page. If you click on model, you can see a list of all model objects. When you navigate to a specific object, you can expand the inheritance diagram to see which objects they inherit methods from. .name is a method in the base class IdfObject.

Also, .to_ClassName is meant to show you convert to objects with the object name in CamelCase, e.g. .to_ThermalZone.

mdahlhausen gravatar imagemdahlhausen ( 2019-01-15 19:27:35 -0500 )edit

Your Answer

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

Add Answer


Question Tools

1 follower


Asked: 2019-01-15 15:42:42 -0500

Seen: 65 times

Last updated: Jan 15