I am trying to create and set a custom GCS in Microstation Connect. Manually, I am able to do so. Using code is where I currently struggle.
C# does not allow to create a GCS and set parameters, so I created a C++ "Adapter DLL" that I call from my C# code.
I interpreted the API documentation in so far, that a BaseGCS can be used to set parameters and a DgnGCS can be put into a dgn file as the acitve GCS.
I tried several ways and the least "invasive" way to define a GCS I found is as follows:
DgnModelRefP p = MdlLib::mdlModelRef_getActive(); //get active model reference, called via external C
int i0; //define error code variable
WString ws; //define error code String
BaseGCSPtr bgcs = BaseGCS::CreateGCS(); //create empty BaseGCS
bgcs->InitFromEPSGCode(&i0, &ws, 4000);//find BaseGCS from EPSG Code, first lat-long GCS picked
int i1 = bgcs->DefinitionComplete(); //signal definition finished
DgnGCSPtr dgnGCS = DgnGCS::CreateGCS(bgcs.get(),p) //hand BaseGCS over to DgnGCS
int i2 = dgnGCS->ToModel(p, true, true, false, true); //put DgnGCS to model
I receive memory addresses from the pointers but the ToModel-Function gives back an error code (random negative numer). Furthermore, reading out a GCS from a library with the DgnGCS::FromModel-Function works and I can use the DgnGCS::ToModel-Function afterwards to write it back.
Therefore, something must lack in the definition of the BaseGCS, but I cannot figure out what. Did someone in the community ever attempt to do something similar?
I did not try to create own GCS, but I am not sure whether it's necessary to create BaseGCS instance at first. DgnGCS inherits BaseGCS, so I guess it can be used as "blank GCS" directly and configured later.
Did you study mgrtestTool.cpp, where some operations with GCS (even though not exactly what you need) are demonstrated?
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
I figured out how to do some code that serves my purpose. You can indeed use the functions from the BaseGCS class on the DgnGCS class. I previously though this wasn't possible because VisualStudio doesn't show them in IntelliSense. Also, the functions are marked red, but they still work.
In the end, I can use the FromModel-function to find a GCS from the library by name, edit the parameters I need, with e.g. SetOriginLatitude or SetDescription and then set the whole thing as the active GCS with the ToModel-function.
Thank you and happy Easter