Use com api in Civil 3D to import DEM data to create a surface

Source: Internet
Author: User

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
{

}
}




}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.