using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using System.Collections;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace Civil二次开发项目样板
{
public class Part1
{
[CommandMethod("GetDocNumber")]
public void ListDocs()
{
DocumentCollection docs = Application.DocumentManager;
Document doc = docs.MdiActiveDocument;
Editor ed = doc.Editor;
ed.WriteMessage("\n文档数量:\t{0}", docs.Count);
ed.WriteMessage("\n活动文档为:\t{0}", doc.Name);
IEnumerator enumerator = docs.GetEnumerator();
while (enumerator.MoveNext())
{
doc = enumerator.Current as Document;
ed.WriteMessage("\n 文档名称:\t{0}", doc.Name);
}
}
[CommandMethod("ListEnts")]
public void ListDocss()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
ObjectId blockTblId = db.BlockTableId;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable blockTable = blockTblId.GetObject(OpenMode.ForRead) as BlockTable;
foreach (ObjectId btrId in blockTable)
{
BlockTableRecord blockTableRecord = btrId.GetObject(OpenMode.ForRead) as BlockTableRecord;
ed.WriteMessage("\n块表记录:{0}", blockTableRecord.Name);
foreach (ObjectId enId in blockTableRecord)
{
Autodesk.AutoCAD.DatabaseServices.DBObject obj = enId.GetObject(OpenMode.ForRead);
ed.WriteMessage("\n实体模型为:{0}\t句柄:{1}", obj.GetType().Name, obj.Handle);
}
}
tr.Commit();
}
}
[CommandMethod("ListBlkRcd")]
public void ListBlkRcd()
{
string[] btrNames = new string[] {
"*Model_Space","*model_space","*Paper_Space",
"*Paper_Space0","*Paper_Space1","*Paper_Space2",
"Line","TestBlock","Something",
BlockTableRecord.ModelSpace,BlockTableRecord.PaperSpace
};
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
ObjectId blockTable = db.BlockTableId;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = blockTable.GetObject(OpenMode.ForRead) as BlockTable;
foreach (string btrName in btrNames)
{
if (bt.Has(btrName)