Revision history [back]
Assign building unit to spaces?
Hello, Could some one can tell me how can I assign the building unit to the spaces using ruby scripts. I tried to do something as follows, but it doesn't work
class AssignBuildingUnitToSpaces < OpenStudio::Ruleset::ModelUserScript
def name
return 'Assign building unit to spaces based on spaces name'
end
def arguments(model)
args = OpenStudio::Ruleset::OSArgumentVector.new
return args
end
def run(model, runner, user_arguments)
super(model, runner, user_arguments)
if !runner.validateUserArguments(arguments(model), user_arguments)
return false
end
spaces = model.getSpaces
unit = OpenStudio::Model::BuildingUnit.new(model)
unit.setBuildingUnitType("Residential")
spaces.each do |space|
space_name = [] # space name as a list
if space.name.to_s.include? '_'
space_name = space.name.to_s.split('_') # split space name
else
space_name[0] = space.name.to_s
end
if ["A","B","C","D","M"].any? {|prefix| space_name[0].include? prefix}
if space.buildingUnit.empty? || !space.buildingUnit.get.name.to_s.include?(space_name[0])
unit.setName(space_name[0])
space.setBuildingUnit(unit)
end
end
end
return true
end
end
AssignBuildingUnitToSpaces.new.registerWithApplication
I am a very newbie in using OpenStudio and Openstudio SDK.
Thanks
Long
Assign building unit to spaces?
Hello, Could some one can tell me how can I assign the building unit to the spaces using ruby scripts. I tried to do something as follows, but it doesn't work
if !runner.validateUserArguments(arguments(model), user_arguments)
end end
AssignBuildingUnitToSpaces.new.registerWithApplication
I am a very newbie in using OpenStudio and Openstudio SDK.
Thanks
Long
Assign building unit to spaces?
Hello, Could some one can tell me how can I assign the building unit to the spaces using ruby scripts. I tried to do something as follows, but it doesn't work
class AssignBuildingUnitToSpaces < OpenStudio::Ruleset::ModelUserScript
def name return 'Assign building unit to spaces based on spaces name' end
def arguments(model) args = OpenStudio::Ruleset::OSArgumentVector.new return args end
def run(model, runner, user_arguments) super(model, runner, user_arguments)
if !runner.validateUserArguments(arguments(model), user_arguments)
return false
end
spaces = model.getSpaces
unit = OpenStudio::Model::BuildingUnit.new(model)
unit.setBuildingUnitType("Residential")
spaces.each do |space|
space_name = [] # space name as a list
if space.name.to_s.include? '_'
space_name = space.name.to_s.split('_') # split space name
else
space_name[0] = space.name.to_s
end
if ["A","B","C","D","M"].any? {|prefix| space_name[0].include? prefix}
if space.buildingUnit.empty? || !space.buildingUnit.get.name.to_s.include?(space_name[0])
unit.setName(space_name[0])
space.setBuildingUnit(unit)
end
end
end
return true
end end
AssignBuildingUnitToSpaces.new.registerWithApplication
I am a very newbie in using OpenStudio and Openstudio SDK.
Thanks
Long
Assign building unit to spaces?
Hello, Could some one can tell me how can I assign the building unit to the spaces using ruby scripts. I tried to do something as follows, but it doesn't work
class AssignBuildingUnitToSpaces < OpenStudio::Ruleset::ModelUserScript
def name return 'Assign building unit to spaces based on spaces name' end
def arguments(model) args = OpenStudio::Ruleset::OSArgumentVector.new return args end
def run(model, runner, user_arguments) super(model, runner, user_arguments)
if !runner.validateUserArguments(arguments(model), user_arguments)
return false
end
spaces = model.getSpaces
unit = OpenStudio::Model::BuildingUnit.new(model)
unit.setBuildingUnitType("Residential")
spaces.each do |space|
space_name = [] # space name as a list
if space.name.to_s.include? '_'
space_name = space.name.to_s.split('_') # split space name
else
space_name[0] = space.name.to_s
end
if ["A","B","C","D","M"].any? {|prefix| space_name[0].include? prefix}
if space.buildingUnit.empty? || !space.buildingUnit.get.name.to_s.include?(space_name[0])
unit.setName(space_name[0])
space.setBuildingUnit(unit)
end
end
end
return true
end end
AssignBuildingUnitToSpaces.new.registerWithApplication
I am a very newbie in using OpenStudio and Openstudio SDK.
Thanks
Long