openstudiocore/sketchup_plugin/openstudio/sketchup_plugin/user_scripts/On Demand Template Generators/SpaceTypeAndConstructionSetWizard.rb
#define what happens when the measure is run
define what happens when the measure is run
define what happens when the measure is run
def run(model, runner, user_arguments)
    super(model, runner, user_arguments)
    if not runner.validateUserArguments(arguments(model), user_arguments)
      return false
    end
    building_type = runner.getStringArgumentValue("buildingType",user_arguments)
    template = runner.getStringArgumentValue("template",user_arguments)
    climate = runner.getStringArgumentValue("climateZone",user_arguments)
    createSpaceTypes = runner.getBoolArgumentValue("createSpaceTypes",user_arguments)
    createConstructionSet = runner.getBoolArgumentValue("createConstructionSet",user_arguments)
    setBuildingDefaults = runner.getBoolArgumentValue("setBuildingDefaults",user_arguments)
    starting_spaceTypes = model.getSpaceTypes
    starting_constructionSets = model.getDefaultConstructionSets
    runner.registerInitialCondition("The building started with #{starting_spaceTypes.size} space types and #{starting_constructionSets.size} construction sets.")
    puts "The building started with #{starting_spaceTypes.size} space types and #{starting_constructionSets.size} construction sets."
    path_to_standards_json = "#{File.dirname(__FILE__)}/resources/OpenStudio_Standards.json"
    path_to_master_schedules_library = "#{File.dirname(__FILE__)}/resources/Master_Schedules.osm"
    space_type_generator = SpaceTypeGenerator.new(path_to_standards_json, path_to_master_schedules_library)
    construction_set_generator = ConstructionSetGenerator.new(path_to_standards_json)
    standards = {}
    temp = File.read(path_to_standards_json)
    standards = JSON.parse(temp)
    space_types = standards["space_types"]
    construction_sets = standards["construction_sets"]
    default_space_type = Hash.new
    default_space_type["FullServiceRestaurant"] = "Dining"
    default_space_type["Hospital"] = "PatRoom"
    default_space_type["LargeHotel"] = "GuestRoom"
    default_space_type["MidriseApartment"] = "Apartment"
    default_space_type["Office"] = "OpenOffice"
    default_space_type["Outpatient"] = "Exam"
    default_space_type["PrimarySchool"] = "Classroom"
    default_space_type["QuickServiceRestaurant"] = "Dining"
    default_space_type["Retail"] = "Retail"
    default_space_type["SecondarySchool"] = "Classroom"
    default_space_type["SmallHotel"] = "GuestRoom"
    default_space_type["StripMall"] = "WholeBuilding"
    default_space_type["SuperMarket"] = "Sales/Produce"
    default_space_type["Warehouse"] = "Bulk"
    if createSpaceTypes
      for t in space_types.keys.sort
        next if not t == template
        for c in space_types[template].keys.sort
          next if not space_type_generator.is_climate_zone_in_climate_zone_set(climate, c)
          for b in space_types[template][c].keys.sort
            next if not b == building_type
            runner.registerInfo("Creating Space Types for: #{t}, #{c}, #{building_type}.")
            for space_type in space_types[template][c][building_type].keys.sort
              result = space_type_generator.generate_space_type(template, c, building_type, space_type, model)
              runner.registerInfo("Creating '#{result[0].name}'.")
              default = default_space_type["#{building_type}"]
              if default == space_type and setBuildingDefaults
                runner.registerInfo("Setting Default Space Type for the Building.")
                puts "Setting Default Space Type for the Building."
                model.getBuilding.setSpaceType(result[0])
              end
            end 
          end 
        end 
      end 
    end
    climateConst = construction_set_generator.find_climate_zone_set(template, climate, building_type, "")
    if createConstructionSet
      for t in construction_sets.keys.sort
        next if not t == template
        for c in construction_sets[template].keys.sort
          next if not c == climateConst
          for b in construction_sets[template][climateConst].keys.sort
            next if not b == building_type
            for space_type in construction_sets[template][climateConst][building_type].keys.sort
              result = construction_set_generator.generate_construction_set(template, climateConst, building_type, space_type, model)
              runner.registerInfo("Creating Construction Set: #{result[0].name}")
              constructions = OsLib_Constructions.reportConstructionSetConstructions(result[0])
              constructions.uniq.each do |construction|
                runner.registerInfo("Creating '#{construction.name}'")
              end
              if setBuildingDefaults
                runner.registerInfo("Setting Default Construction Set for the Building.")
                model.getBuilding.setDefaultConstructionSet(result[0])
              end
            end 
          end 
        end 
      end 
    end
    finishing_spaceTypes = model.getSpaceTypes
    finishing_constructionSets = model.getDefaultConstructionSets
    runner.registerFinalCondition("The model has #{finishing_spaceTypes.size} space types and #{finishing_constructionSets.size} construction sets.")
    return true
  end
def run ( model , runner , user_arguments ) super ( model , runner , user_arguments ) if not runner . validateUserArguments ( arguments ( model ) , user_arguments ) return false end building_type = runner . getStringArgumentValue ( "buildingType" , user_arguments ) template = runner . getStringArgumentValue ( "template" , user_arguments ) climate = runner . getStringArgumentValue ( "climateZone" , user_arguments ) createSpaceTypes = runner . getBoolArgumentValue ( "createSpaceTypes" , user_arguments ) createConstructionSet = runner . getBoolArgumentValue ( "createConstructionSet" , user_arguments ) setBuildingDefaults = runner . getBoolArgumentValue ( "setBuildingDefaults" , user_arguments ) starting_spaceTypes = model . getSpaceTypes starting_constructionSets = model . getDefaultConstructionSets runner . registerInitialCondition ( "The building started with #{starting_spaceTypes.size} space types and #{starting_constructionSets.size} construction sets." ) puts "The building started with #{starting_spaceTypes.size} space types and #{starting_constructionSets.size} construction sets." path_to_standards_json = "#{File.dirname(__FILE__)}/resources/OpenStudio_Standards.json" path_to_master_schedules_library = "#{File.dirname(__FILE__)}/resources/Master_Schedules.osm" space_type_generator = SpaceTypeGenerator . new ( path_to_standards_json , path_to_master_schedules_library ) construction_set_generator = ConstructionSetGenerator . new ( path_to_standards_json ) standards = { } temp = File . read ( path_to_standards_json ) standards = JSON . parse ( temp ) space_types = standards [ "space_types" ] construction_sets = standards [ "construction_sets" ] default_space_type = Hash . new default_space_type [ "FullServiceRestaurant" ] = "Dining" default_space_type [ "Hospital" ] = "PatRoom" default_space_type [ "LargeHotel" ] = "GuestRoom" default_space_type [ "MidriseApartment" ] = "Apartment" default_space_type [ "Office" ] = "OpenOffice" default_space_type [ "Outpatient" ] = "Exam" default_space_type [ "PrimarySchool" ] = "Classroom" default_space_type [ "QuickServiceRestaurant" ] = "Dining" default_space_type [ "Retail" ] = "Retail" default_space_type [ "SecondarySchool" ] = "Classroom" default_space_type [ "SmallHotel" ] = "GuestRoom" default_space_type [ "StripMall" ] = "WholeBuilding" default_space_type [ "SuperMarket" ] = "Sales/Produce" default_space_type [ "Warehouse" ] = "Bulk" if createSpaceTypes for t in space_types . keys . sort next if not t == template for c in space_types [ template ] . keys . sort next if not space_type_generator . is_climate_zone_in_climate_zone_set ( climate , c ) for b in space_types [ template ] [ c ] . keys . sort next if not b == building_type runner . registerInfo ( "Creating Space Types for: #{t}, #{c}, #{building_type}." ) for space_type in space_types [ template ] [ c ] [ building_type ] . keys . sort result = space_type_generator . generate_space_type ( template , c , building_type , space_type , model ) runner . registerInfo ( "Creating '#{result[0].name}'." ) default = default_space_type [ "#{building_type}" ] if default == space_type and setBuildingDefaults runner . registerInfo ( "Setting Default Space Type for the Building." ) puts "Setting Default Space Type for the Building." model . getBuilding . setSpaceType ( result [ 0 ] ) end end end end end end climateConst = construction_set_generator . find_climate_zone_set ( template , climate , building_type , "" ) if createConstructionSet for t in construction_sets . keys . sort next if not t == template for c in construction_sets [ template ] . keys . sort next if not c == climateConst for b in construction_sets [ template ] [ climateConst ] . keys . sort next if not b == building_type for space_type in construction_sets [ template ] [ climateConst ] [ building_type ] . keys . sort result = construction_set_generator . generate_construction_set ( template , climateConst , building_type , space_type , model ) runner . registerInfo ( "Creating Construction Set: #{result[0].name}" ) constructions = OsLib_Constructions . reportConstructionSetConstructions ( result [ 0 ] ) constructions . uniq . each do | construction | runner . registerInfo ( "Creating '#{construction.name}'" ) end if setBuildingDefaults runner . registerInfo ( "Setting Default Construction Set for the Building." ) model . getBuilding . setDefaultConstructionSet ( result [ 0 ] ) end end end end end end finishing_spaceTypes = model . getSpaceTypes finishing_constructionSets = model . getDefaultConstructionSets runner . registerFinalCondition ( "The model has #{finishing_spaceTypes.size} space types and #{finishing_constructionSets.size} construction sets." ) return true end
define what happens when the measure is run
define what happens when the measure is run
#use the built-in error checking #assign the user inputs to variables #reporting initial condition of model # added for the benefit of SketchUp UserScript workflow #setup resources #create generators #load the data from the JSON file into a ruby hash #define default space types for each building type (I was going to require CreateTemplateModels, but that created issues, so I just copied the hash I need) # add space types #generate space type #if space type matches hash for this building type set as building default # added for the benefit of SketchUp UserScript workflow #next space type #next building type #next climate #next template # get climate zone set from specific climate zone for construction set # add construction set #generate construction set # list constructions used in construction set # set default construction set #next space type #next building type #next climate #next template # thermostat schedules are brought in but cant be assigned until later on when there are thermal zones #reporting final condition of model # updated for the benefit of SketchUp UserScript workflow
model
<not_specific>
runner
<not_specific>
user_arguments
<not_specific>