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

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

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

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

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

OpenStudio::Ruleset::ModelUserScript def name return 'Assign building unit to spaces based on spaces name' end

end def arguments(model) args = OpenStudio::Ruleset::OSArgumentVector.new return args end

end def run(model, runner, user_arguments) super(model, runner, user_arguments)

user_arguments)

    if !runner.validateUserArguments(arguments(model), user_arguments)
   return false
end

    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

    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

    end

    return true
  end
end

AssignBuildingUnitToSpaces.new.registerWithApplication

end end

AssignBuildingUnitToSpaces.new.registerWithApplication

I am a very newbie in using OpenStudio and Openstudio SDK.

Thanks

Long