Civil 3D provides. net-based APIs and COM-based APIs. We recommend that you use. net APIs, but sometimes you also need to use COM APIs. This example shows how to use the com api to import DEM data to generate a Civil 3D surface. In Civil 3D development, the reference to be added using the com api is too long. We recommend that you use the Wizard to create a project to simplify the operation. The Wizard can help you add most references, it is much easier to add one by yourself. Note that to use COM APIs, you must check the interOp reference of AutoCAD and Civil 3D.
The following code imports DEM data using the com api:
// (C) Copyright 2013 by Autodesk
//
Using System;
Using Autodesk. AutoCAD. Runtime;
Using Autodesk. AutoCAD. ApplicationServices;
Using Autodesk. AutoCAD. DatabaseServices;
Using Autodesk. AutoCAD. Geometry;
Using Autodesk. AutoCAD. EditorInput;
Using System. Windows. Forms;
Using Autodesk. AECC. Interop. UiLand;
Using Autodesk. AutoCAD. Interop;
Using Autodesk. Civil. ApplicationServices;
// This line is not mandatory, but improves loading CES
[Assembly: CommandClass (typeof (LoadDEM_demo.MyCommands)]
Namespace LoadDEM_demo
{
Public class MyCommands
{
// COM objects:
Private Autodesk. AutoCAD. Interop. IAcadApplication m_oAcadApp = null;
Private Autodesk. AECC. Interop. UiLand. IAeccApplication m_oAeccApp = null;
Private Autodesk. AECC. Interop. UiLand. IAeccDocument m_oAeccDoc = null;
Private Autodesk. AECC. Interop. Land. IAeccDatabase m_oAeccDb = null;
String m_sAcadProdID = "AutoCAD. Application ";
String m_sAeccAppProgId = "AeccXUiLand. AeccApplication.10.0"; // Civil 3D 2013
// String m_sAeccAppProgId = "AeccXUiLand. AeccApplication.9.0"; // Civil 3D 2012
Private string m_sMessage = "";
[CommandMethod ("LoadDemSurfaceop")]
Public void LoadDemSurface ()
{
Try
{
OpenFileDialog ofd = new OpenFileDialog ();
Ofd. filter = "usgs dem (*. DEM) | *. dem | GEOTIFF (*. tif) | *. tif | esri ascii grid (*. asc) | *. asc | esri ascii grid (*. txt) | *. txt | ESRI binary raster (*. adf) | *. adf ";
Ofd. FilterIndex = 0;
If (ofd. ShowDialog () = DialogResult. OK)
{
// Use COM
M_oAcadApp = (IAcadApplication) System. Runtime. InteropServices. Marshal. GetActiveObject (m_sAcadProdID );
If (m_oAcadApp! = Null)
{
M_oAeccApp = (IAeccApplication) m_oAcadApp.GetInterfaceObject (m_sAeccAppProgId );
M_oAeccDoc = (IAeccDocument) m_oAeccApp.ActiveDocument;
M_oAeccDoc.Surfaces.ImportDEM (ofd. FileName );
}
M_oAeccDoc.Regen (Autodesk. AutoCAD. Interop. Common. AcRegenType. acActiveViewport );
}
Else
{
}
}
Catch (System. Exception e)
{
MessageBox. Show (e. Message );
}
Finally
{
}
}
}
}