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

C# Template OSM/ gbXML & IDF import

asked 2021-07-25 19:37:27 -0600

Redline's avatar

updated 2021-07-31 12:57:31 -0600

In the Open Studio UI its fairly straightforward to Open an OSM that's seeded with sensible defaults. And then import geometry from an external gbxml file.

But in C# doing this programmatically seems non trivial.

I have an .OSM set already :

Path p = new Path(OpenStudio.OpenStudioUtilitiesCore.toPath(Application.Properties.Resources.OpenStudioTemplateFile));           

            OpenStudio.Model osm = new OpenStudio.Model(); //create a new blank OSM           

            OpenStudio.OptionalModel optionalModel = OpenStudio.Model.load(p); 

           osm = optionalModel.get();

This is all fine and my template OSM has many defaults, and schedules etc in it already. I could at this point add spaces and geometry etc programmatically, but want to now import geometry via gbXML. Again this is fairly trivial

 GbXMLReverseTranslator gbRT = new GbXMLReverseTranslator();
            Path _gbXMLIPPathStr = new Path(OpenStudio.OpenStudioUtilitiesCore.toPath(Application.Properties.Resources.ImportgbXMLfile));
            OpenStudio.OptionalModel om = gbRT.loadModel(_gbXMLIPPathStr);

            osm = om.get();

But now I have an entirely new model and the original opened model is is either overwritten, or IF I define it separately then I'll have two disparate models set-up.

What I need to be able to do is Import this data into an existing model object, rather than create an entirely new model object via a Reverse translator.

I will likely also have need to something similar with external IDF files, for example to import selected constructions etc from an an external file .

The only possible solution I can think of is to have two unique OSM models, then iterate the geometry of the one containing the geometry , and programmatically iterate thru the geometry , and write out the details of each item to the desired OSM model. Is there no other way to perhaps access the UI of OS which has the ability to do this, which as far as I can see isn't exposed anywhere?

edit retag flag offensive close merge delete

Comments

The method I will use in the absence of any other Import, is to create two OSM model files. Then add to the Model created from external gbxml Geometry, iterate the external template OSM and add the items of interest like schedules , constructions etc individually in a series of loops. Then dispose of the template OSM. Bit longwinded but that will get me all I need into a single *.OSM file..

Redline's avatar Redline  ( 2021-07-25 22:54:39 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-07-26 10:13:27 -0600

updated 2021-07-26 10:14:31 -0600

You may want to try out ModelMerger class that merges to models. I don't have an example of that code in C# but here is ruby example https://github.com/NREL/openstudio-mo...

You may ned to add this code to match surfaces and optionally intersect. I can't remember if model merger maintains matched surfaces or not. https://github.com/NREL/openstudio-mo...

edit flag offensive delete link more

Comments

Thanks its not too hard to read the intent of a Ruby Script and mentally transpose to C#. Looks like there isn't direct access to an import. So the ruby script or my method will have to be the way to merge one model into another. Thanks for the link

Redline's avatar Redline  ( 2021-07-27 19:16:42 -0600 )edit

ModelMerger is in essence acting like an importer.

David Goldwasser's avatar David Goldwasser  ( 2021-07-28 14:43:58 -0600 )edit

Your Answer

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

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2021-07-25 19:37:27 -0600

Seen: 262 times

Last updated: Jul 26 '21