First time here? Check out the Help page!
1 | initial version |
As usual, the solution is really easy once you know how to do it. Here's the code
# define what happens when the measure is run
def run(workspace, runner, user_arguments)
super(workspace, runner, user_arguments)
# use the built-in error checking
if !runner.validateUserArguments(arguments(workspace), user_arguments)
return false
end
#array to hold new IDF objects
string_objects = []
string_objects << "
AirLoopHVAC,
DOAS, !- Name
DOAS Controllers, !- Controller List Name
DOAS Availability Managers, !- Availability Manager List Name
autosize, !- Design Supply Air Flow Rate {m3/s}
DOAS Branches, !- Branch List Name
, !- Connector List Name
DOAS Air Loop Inlet, !- Supply Side Inlet Node Name
DOAS Return Air Outlet, !- Demand Side Outlet Node Name
DOAS Supply Path Inlet, !- Demand Side Inlet Node Names
DOAS Supply Fan Outlet; !- Supply Side Outlet Node Names
"
.
.
.
MANY MORE OBJECTS ADDED TO string_objects
.
.
.
DONE ADDING OBJECTS
idfobjects_vector = []
string_objects.each do |string_object|
idfObject = OpenStudio::IdfObject::load(string_object)
object = idfObject.get
idfobjects_vector.push(object)
end
workspace.addObjects(idfobjects_vector)
return true
end
The significant difference was using addObjects() PLURAL instead of addObjects() SINGULAR.
The loop converts all the IDF objects in text file format to IDFObjects objects and puts all those IDFObjects into a vector called idfobjects_vector. The idfobjects_vector is then passed to the addObjects() PLURAL outside the loop.
I'm guessing that addObject(idf_object) SINGULAR function checks the validity of all fields of the idf_object being added to the IDF every time. Fields that were invalid were left blank. On the other hand, the addObjects(idfobjects_vector) PLURAL still checks the validity of all the objects being added, but is checking field validity of all objects at once, instead of one at a time like my previous attempts. This means the order of the objects written in text format in the measure does not matter, which is very, VERY nice for the severely interconnected airloops, plantloops, etc.