diff --git a/src/model/Model.hpp b/src/model/Model.hpp index 1c45d6b7bf1..f3f80343003 100644 --- a/src/model/Model.hpp +++ b/src/model/Model.hpp @@ -302,7 +302,7 @@ class MODEL_API Model : public openstudio::Workspace { * speed up the search. This method will only work for concrete model objects (leaves in the * ModelObject inheritance tree), hence the name. */ template - std::vector getConcreteModelObjects() const + std::vector getConcreteModelObjects(bool sorted=false) const { std::vector result; std::vector objects = this->getObjectsByType(T::iddObjectType()); @@ -311,6 +311,9 @@ class MODEL_API Model : public openstudio::Workspace { std::shared_ptr p = it->getImpl(); if (p) { result.push_back(T(p)); } } + if (sorted) { + std::sort(result.begin(), result.end()); + } return result; } diff --git a/src/model/Model_Common_Include.i b/src/model/Model_Common_Include.i index ad63066ef12..f318b2ccb01 100644 --- a/src/model/Model_Common_Include.i +++ b/src/model/Model_Common_Include.i @@ -72,7 +72,7 @@ %init %{ rb_eval_string("OpenStudio::IdfObject.class_eval { define_method(:to_" #_name ") { OpenStudio::Model::to" #_name "(self); } }"); rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name ") { |handle| OpenStudio::Model::get" #_name "(self, handle); } }"); - rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "s) { OpenStudio::Model::get" #_name "s(self); } }"); + rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "s) { | sorted = false | OpenStudio::Model::get" #_name "s(self, sorted); } }"); rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "ByName) { |name| OpenStudio::Model::get" #_name "ByName(self, name); } }"); rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "sByName) { |name, exactMatch| OpenStudio::Model::get" #_name "sByName(self, name, exactMatch); } }"); %} @@ -202,7 +202,7 @@ boost::optional<_name> to##_name(const openstudio::IdfObject& idfObject); boost::optional<_name> get##_name(const Model &t_model, const openstudio::Handle &t_handle); - std::vector<_name> get##_name##s(const Model &t_model); + std::vector<_name> get##_name##s(const Model &t_model, bool sorted); boost::optional<_name> get##_name##ByName(const Model &t_model, const std::string &t_name); std::vector<_name> get##_name##sByName(const Model &t_model, const std::string &t_name, bool t_exactMatch); } @@ -216,11 +216,11 @@ boost::optional<_name> get##_name(const Model &t_model, const openstudio::Handle &t_handle) { return t_model.getModelObject<_name>(t_handle); } - std::vector<_name> get##_name##s(const Model &t_model) { + std::vector<_name> get##_name##s(const Model &t_model, bool sorted) { %#if _isConcrete - return t_model.getConcreteModelObjects<_name>(); + return t_model.getConcreteModelObjects<_name>(sorted); %#else - return t_model.getModelObjects<_name>(); + return t_model.getModelObjects<_name>(sorted); %#endif } boost::optional<_name> get##_name##ByName(const Model &t_model, const std::string &t_name) {