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

# Revision history [back]

### Understanding code for "Adding EnergyPlus Workspace Objects"

From the OpenStudio Measure Writer's Reference Guide, I am trying to understand, in detail, what this code does from the "Adding EnergyPlus Workspace Objects" section.

  # array to hold new IDF objects
string_objects = []

# create sorted (.sort) list of unique (.uniq) constructions from all
# constructions in model, adding ComponentCost:LineItem for each

used_constructions_names.sort.uniq.each do |used_construction_name|

#IDF object text for ComponentCost:LineItem
string_objects << "
ComponentCost:LineItem,
#{used_construction_name}_TakeOff,    !- Name
,                                     !- Type
Construction,                         !- Line Item Type
#{used_construction_name},            !- Item Name
,                                     !- Object End Use Key
,                                     !- Cost per Each {$} 0.000000000001; !- Cost per Area {$/m2}
"
end

# add all of the strings to workspace to create IDF objects
string_objects.each do |string_object|
object = idfObject.get
end


In particular, I'm trying to understand what these three lines do.

    idfObject = OpenStudio::IdfObject::load(string_object)
object = idfObject.get


The first line is the function

static boost::optional<IdfObject> openstudio::IdfObject::load(const std::string & text)


which can be viewed at this LINK.

I then got stuck because on the second line

    object = idfObject.get


there is no reference to "get" in the IdfObject Class, which is the object type returned by the first line. Nor is there a "get" in the WorkspaceObject Class from the "Inheritance diagram for openstudio::IdfObject.

But looking up the workspace.addObject(object) from the third line in the documentation HERE, the second line most likely returns an openstudio::IdfObject. But that would be strange since the first line already returned an openstudio::IdfObject. Not really sure what the second line does.

The the third add the object to the workspace, which is obvious from the function name. This somehow gets the object into the IDF file. This raises another question though. What is the workspace exactly? I was unable to find what the workspace object in a measure intuitively contains or represents. Or maybe better said, what the workspace object can and can't do.