局限 和使用 Interop
.NET API 没有开放AutoCAD Civil 3D的所有功能,甚至比COM API都要少。在.NET中下列领域仍未被开放:
- 场地(Sites) 和 Parcels
- Data Bands
- 某些标签
另外,已经开放功能中,有部分领域尚未完成:
- Pipes: 冲突检查 ( 冲突检查样式除外)
如果你需要在你的.NET项目中使用这些功能,你可以使用相应的COM对象:
从.NET中使用 AutoCAD Civil 3D COM API
- 创建一个.NET 解决方案和项目
- 在项目菜单或者解决方案浏览器中选择 添加引用(Add Reference)
- 在浏览选项卡中定位到Civil 3D 安装文件夹,选择下列COM interop DLL文件,其中<domain>是你要用到的Civil domain(Land, Roadway, Pipe, or Survey):
- Autodesk.AEC.Interop.Base
- Autodesk.AEC.Interop.UiBase
- Autodesk.AutoCAD.Interop
- Autodesk.AutoCAD.Interop.Common
- Autodesk.AECC.Interop.<domain>
- Autodesk.AECC.Interop.Ui<domain>
- 选择上述引用,设置"(复制到本地)Copy Local" 属性为true,因为需要把所有引用类型嵌入到你的目标DLL文件中,这样一来,运行时就不再需要引用的 interop DLL文件了。
- 把Autodesk.AutoCAD.Interop and Autodesk.AECC.Interop.Ui<domain> 命名空间添加到using或Imports语句中。
注意:
你可能会在不同的Autodesk.AutoCAD.Interop命名空间中发现一些(warning type 1684)的警告,要屏蔽此类警告,在项目属性的Build选项中的Supress Warnings下面输入1684。
下面的C#;例子演示了使用COM interop从一个文档中获取一些point groups 和曲面:
string m_sAcadProdID = "AutoCAD.Application";
string m_sAeccAppProgId = "AeccXUiLand.AeccApplication.10.3";
...
private void useCom()
{
//Construct AeccApplication object, Document and Database objects
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;
// get the Database object via a late bind
m_oAeccDb = (Autodesk.AECC.Interop.Land.IAeccDatabase)m_oAeccDoc.GetType().GetProperty("Database").GetValue(m_oAeccDoc, null);
long lCount = m_oAeccDb.PointGroups.Count;
m_sMessage += "Number of PointGroups = " + lCount.ToString() + "\n";
lCount = m_oAeccDb.Surfaces.Count;
m_sMessage += "Number of Surfaces = " + lCount.ToString() + "\n\n";
MessageBox.Show(m_sMessage);
m_sMessage = "";
}
}
请参照位于<Install directory>\Sample\AutoCAD Civil 3D\COM下面的CSharpClient 和 VbDotNetClient 样例项目来获取更多有关interoprability的例子
父主题: