04-10-2018 12:45 AM - edited 04-10-2018 12:46 AM
Hello,
i allready had created a cadfile server. However it wont work to add this csd to GeoMedia. I used this code to import this csd into GeoMedia.
csd = csd.Replace(".csd", "");
gm = (Intergraph.GeoMedia.GeoMedia.Application)Marshal.GetActiveObject("GeoMedia.Application");
mw = (Intergraph.GeoMedia.GeoMedia.MapWindow)gm.ActiveWindow;
Intergraph.GeoMedia.MapviewLib.GMMapView view = (Intergraph.GeoMedia.MapviewLib.GMMapView)mw.MapView;
doc = (Intergraph.GeoMedia.GeoMedia.Document)gm.Document;
conns = (Intergraph.GeoMedia.PClient.Connections)doc.Connections;
Connection pConn = new Connection
{
Application = gm,
CoordSystemsMgr = view.CoordSystemsMgr,
ConnectionName = csd,
Description = description,
Location = tFileInfo,
Mode = 0,
Name = csd,
Type = "GCAD.GDatabase"
};
pConn.Connect(); // I already could connect to the connection.
foreach (string Layer in layerNames)
{
if (Layer != "0" && Layer != "Default" && Layer != "Standart")
{
LegendEntry legendEntry = new LegendEntry();
legendEntry = gm.CreateService("GeoMedia.LegendEntry");
legendEntry.GeometryFieldName = "CompoundGeometry";
legendEntry.Title = Layer;
legendEntry.Name = Layer;
legendEntry.Locatable = true;
legendEntry.InputRecordset = GetRecordset(pConn, Layer.Replace(" ", "_"), "");
//Style
StyleDefinition style = new StyleDefinition();
StyleService styleService = new StyleService();
styleService = gm.CreateService("Geomedia.StyleService");
styleService.GetStyle("Compound Style", out style);
legendEntry.Style = style;
view.Legend.LegendEntries.Append(legendEntry);
legendEntry.LoadData();
conns.Append(pConn); // If I understood this right that will add the before defiende connection to the warehouse connections. But every time I'll add this to my GeoMedia I got this Exeception : "No such interface supported". That connection is also displayed under the other connctions...
}
}
I guess I missed something, but I dont got it. ~
Regards
04-10-2018 01:05 AM
Hi JanArz,
it looks like a driving GeoMedia type application. In this case, you must create all objects using Application.CreateService method, which you mostly do, except the Connection object. So create your Connection object using Application.CreateService and it will most likely fix a part of your problems.
Furthermore, you add the Connection object to GeoMedia's Connections collection in a loop, which means that you will attempt to insert the same object multiple times. Only one connection object with given name can be inserted to Connections collection. So add your connection object only once, the best place is just after you call the Connect() method.
Also if you create an object using the CreateService method, you don't need to initialize it with "new" first. This is what you do for LegendEntry and StyleService object. And the Style object also does not need to be initialized. It should rather be initialized to null prior passing it to the GetStyle method.
Finally, I would recommend you to create the StyleService object only once, outside the loop, and reuse it for every iteration.
Pavel