GeoMedia Discussions

Search for an answer, post a question, or answer other users' questions in our GeoMedia support discussions. This discussion board is a great way to collaborate with industry peers around the world. It is intended for discussion and support of the GeoMedia Desktop and Add-on applications.
Showing results for 
Search instead for 
Do you mean 
Reply
Occasional Contributor
Posts: 5
Registered: ‎12-20-2017

Add a CAD File Server to GeoMedia

[ Edited ]

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

Technical Evangelist
Posts: 567
Registered: ‎09-11-2015

Re: Add a CAD File Server to GeoMedia

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