做BIM二开常常要和CAD打交道,那么怎么才能直接获取CAD的信息呢?加载Teigha库可以实现获取CAD信息。Teigha库有比较多的版本,其他的自行了解,下面简单说一下TD_Mgd_3.09.dll使用步骤:
TD_Mgd_3.09.dll使用步骤:
1.在VS项目引用加载TD_Mgd(建议引用文件放到revit加载dll的文件内)Teigha文件包内的其他文件,放到Revit加载Dll路径(默认C盘)内。属性-复制本地-选False。
2.然后利用Ribbon里生成项目DLL文件,放到Revit加载路径(默认C盘)里面。
3.Revit加载DLL文件,正常使用插件功能。
4.如需调试功能,需完成1~3点,打开revit先用一下该功能,然后再去调试。
如提示以下错误
1.是加载的TD文件和电脑系统不匹配,看是不是64位电脑加载了32位的TD_DLL,解决方法下载64位TD_DLL
2.找不到指定的模块,可能是缺少文件,解决方法:把Teigha的文件夹内所有文件放到VS生成的DLL文件路径内。
TD_3.09版64位下载链接
链接:https://pan.baidu.com/s/1eeFE0S0MNXE25V_OPpbzow
提取码:tisw
以下是TD-DLL的内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Teigha.Runtime;
using Teigha.DatabaseServices;
using System.IO;
using System.Collections;
using Teigha.Geometry;
using Teigha.GraphicsInterface;
using Teigha.GraphicsSystem;
namespace MagicTools
{
public class CADModelUtils
{
/// <summary>
/// 取得链接cad的路径
/// </summary>
/// <param name="cadLinkTypeID"></param>
/// <param name="revitDoc"></param>
/// <returns></returns>
public static string GetCADPath(ElementId cadLinkTypeID, Document revitDoc)
{
CADLinkType cadLinkType = revitDoc.GetElement(cadLinkTypeID) as CADLinkType;
return ModelPathUtils.ConvertModelPathToUserVisiblePath(cadLinkType.GetExternalFileReference().GetAbsolutePath());
}
/// <summary>
/// 取得CAD的文字信息
/// </summary>
/// <param name="dwgFile"></param>
/// <returns></returns>
public List<CADTextModel> GetCADTextInfo(string dwgFile)
{
List<CADTextModel> listCADModels = new List<CADTextModel>();
using (new Services())
{
using (Database database = new Database(false, false))
{
database.ReadDwgFile(dwgFile, FileShare.Read, true, "");
using (var trans = database.TransactionManager.StartTransaction())
{
using (BlockTable table = (BlockTable)database.BlockTableId.GetObject(OpenMode.ForRead))
{
using (SymbolTableEnumerator enumerator = table.GetEnumerator())
{