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

Can I merge multiple buildings (.osm files) into one .osm file ?

asked 2025-05-15 04:48:58 -0500

Oussama's avatar

updated 2025-05-15 07:07:34 -0500

Hi Everyone , I am a beginner at Building energy modeling, so forgive me if my question is not formulated well. So, I have different buildings geometry (each with thermal zones and spaces...) as .osm files and I wonder whether I can merge them all in one single .osm file so that I can simulate the whole village later ? If it is possible could you please guide me on how to do so ? Thank you all in advance.

edit retag flag offensive close merge delete

Comments

1

You need to be a bit more specific on your OpenStudio toolkit and workflow. Are you mainly working with the OpenStudio Application (App)? Are you using the SketchUp Plugin? Have you tried interacting with the SDK yet?

I'm pretty sure one can't merge multiple OSM geometries using the App or Plugin. Do-able with the SDK (e.g. a single Ruby or Python script). This involves opening existing OSMs (as an array), looping through the array and copy/pasting their zones, spaces, surfaces, subsurfaces over to a newly instantiated OSM (series of loops).

Denis Bourgeois's avatar Denis Bourgeois  ( 2025-05-15 07:57:37 -0500 )edit

Thank you for your answer Denis, Yes I am using the SketchUp Plugin to define the geometry of each building, my goal is to design a village (cluster of buildings) and then pass the .osm file to OpenStudio (APK) for the simulation, but the problem is that I have them (buildings) in separate .osm files !

Oussama's avatar Oussama  ( 2025-05-15 08:52:06 -0500 )edit

APK? You may have already tried running simulations with the OpenStudio CLI, using e.g. PowerShell (Windows) or Terminal (MacOS). Taking advantage of the SDK (e.g. API), either interactively or via scripting (e.g. Ruby, Python), opens the door wide open for customization and automation (see below) ... although there's definitely a learning curve.

Denis Bourgeois's avatar Denis Bourgeois  ( 2025-05-16 07:35:29 -0500 )edit

Thank you so much Denis for taking the time to answer my question . I truly appreciate your support and the clarity of your explanation. I will definitely try out the solution you suggested and see how it works out for me. Thanks again for your guidance.

Best regards.

Oussama's avatar Oussama  ( 2025-05-16 11:52:59 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2025-05-15 15:23:07 -0500

Below is a basic Ruby script that merges the geometry of 2x OSMs:

Both models should be downloaded to the same folder as the script.

require "openstudio"

translator = OpenStudio::OSVersion::VersionTranslator.new
model = OpenStudio::Model::Model.new

fileA = File.join(__dir__, "warehouse.osm")
pathA = OpenStudio::Path.new(fileA)
modlA = translator.loadModel(pathA).get

fileB = File.join(__dir__, "smalloffice.osm")
pathB = OpenStudio::Path.new(fileB)
modlB = translator.loadModel(pathB).get

[modlA, modlB].each_with_index do |modl, i|
  modl.getSpaces.each do |sp|
    space = OpenStudio::Model::Space.new(model)
    space.setDirectionofRelativeNorth(sp.directionofRelativeNorth)

    if i.zero?
      space.setXOrigin(sp.xOrigin)
      space.setYOrigin(sp.yOrigin)
      space.setZOrigin(sp.zOrigin)
    else
      space.setXOrigin(sp.xOrigin + 100)
      space.setYOrigin(sp.yOrigin)
      space.setZOrigin(sp.zOrigin)
    end

    sp.surfaces.each do |srf|
      surface = OpenStudio::Model::Surface.new(srf.vertices, model)
      surface.setSpace(space)
      surface.setOutsideBoundaryCondition(srf.outsideBoundaryCondition)
      surface.setSurfaceType(srf.surfaceType)
      surface.setSunExposure(srf.sunExposure)
      surface.setWindExposure(srf.windExposure)

      srf.subSurfaces.each do |sb|
        sub = OpenStudio::Model::SubSurface.new(sb.vertices, model)
        sub.setSurface(surface)
        sub.setSubSurfaceType(sb.subSurfaceType)
      end
    end

    zone = OpenStudio::Model::ThermalZone.new(model)
    space.setThermalZone(zone)

    sys = OpenStudio::Model::ZoneHVACIdealLoadsAirSystem.new(model)
    sys.addToThermalZone(zone)
  end
end

spaces = OpenStudio::Model::SpaceVector.new(model.getSpaces)
OpenStudio::Model.intersectSurfaces(spaces)
OpenStudio::Model.matchSurfaces(spaces)

file = File.join(__dir__, "final.osm")
model.save(file, true)

Running the script generates a "final.osm".

image description

No errors running a test simulation using the App. You do need to first assign a (complete) default construction set to the building to actually run a test simulation. You can adapt the script to your needs (e.g. use your own OSMs). If needed, you can email me the (zipped) OSMs - I'll merge the zipped OSMs using the very same script.

The script is just a demo. You can further develop the script so it copies/pastes other items (e.g. loads, schedules). I also suggest going over past related UMH posts (such as this one) - plenty of caveats to consider when dealing with an OSM holding multiple pavilions (e.g. separate meters, shared plant/systems).


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Question Tools

1 follower

Stats

Asked: 2025-05-15 04:48:58 -0500

Seen: 212 times

Last updated: May 15