Create and Set custom Geographic Coordinate System

Dear Community,

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?

Kind Regards

Matthias Lammer