AutoCAD.NET开发

访问AutoCAD对象

2019-03-12  本文已影响0人  using__
Autodesk.AutoCAD.DatabaseServices.Database acCurDb;
acCurDb = Application.DocumentManager.MdiActiveDocument.Database;
string strFName, strBlkName;
Autodesk.AutoCAD.DatabaseServices.ObjectId objId;

strFName = "c:/test.dwg";
strBlkName = System.IO.Path.GetFileNameWithoutExtension(strName);
objId = Application.DocumentManager.MdiActiveDocument.Database.AttachXref(strFName,strBlkName);
string strFName, strBlkName;
Autodesk.AutoCAD.DatabaseServices.ObjectId objId;
Autodesk.AutoCAD.DatabaseServices.Database acCurDb;
acCurDb = Application.DocumentManager.MdiActiveDocument.Database;

strFName = "c:/test.dwg";
strBlkName = System.IO.Path.GetFileNameWithoutExtension(strName);
objId = acCurDb.AttachXref(strFName,strBlkName);
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[CommandMethod("ListEntities")]
public static void ListEntities()
{
  //获取当前数据库,启动事务
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
  Database acCurDb = acDoc.Database;
  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  {
    //以读模式打开块表
    BlockTable acBlkTbl;
    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,OpenMode.ForRead) as BlockTable;
    //以读模式打开块表记录模型空间
    BlockTableRecord acBlkTblRec;
    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForRead) as BlockTableRecord;
    int nCnt = 0;
    acDoc.Editor.WriteMessage("\nModel space objects: ");

    //遍历模型控件里的每个对象,并显示找到的对象类型
    foreach(ObjectId acObjId in acBlkTblRec)
    {
      acDoc.Editor.WriteMessage("\n" + acObjId.ObjectClass.DxfName);
      nCnt = nCnt + 1;
    }
    //如果没发现对象则显示提示信息
    if(nCnt == 0)
    {
       acDoc.Editor.WriteMessage("\n No objects found");
    }
   //关闭事务
  }
}
上一篇下一篇

猜你喜欢

热点阅读