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

Undefined Method for #

asked 2019-01-15 15:42:42 -0600

ParticleSwarm's avatar

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

Comments

Unmet! Love it!

__AmirRoth__'s avatar __AmirRoth__  ( 2019-01-15 19:42:04 -0600 )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's avatar Julien Marrec  ( 2019-01-16 05:42:45 -0600 )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's avatar David Goldwasser  ( 2019-01-16 13:24:04 -0600 )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's avatar ParticleSwarm  ( 2019-01-17 11:46:07 -0600 )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's avatar Julien Marrec  ( 2019-01-21 02:43:57 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
4

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

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

Comments

1

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?

Luis Lara's avatar Luis Lara  ( 2019-01-15 17:02:21 -0600 )edit
1

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's avatar mdahlhausen  ( 2019-01-15 19:27:35 -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

2 followers

Stats

Asked: 2019-01-15 15:42:42 -0600

Seen: 718 times

Last updated: Jan 15 '19