C# Template OSM/ gbXML & IDF import
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?
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..