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

Revision history [back]

click to hide/show revision 1
initial version

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?

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?

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?