请问如何获取当前图的所有图层?
Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForWrite));
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
//Create the block reference...use the return from CreateEmployeeDefinition directly!
BlockReference br = new BlockReference(pStart, CreatePolePedDefinition(pCellName));
br.LayerId = CreateLayer(pLayerName);
ObjectId newBtrId = btr.AppendEntity(br); //Add the reference to ModelSpace
trans.AddNewlyCreatedDBObject(br, true); //Let the transaction know about it
DBObject obj = trans.GetObject(newBtrId, OpenMode.ForWrite);
XDataDispose.AddRegAppTableRecord("xlentComms");
ResultBuffer rb = new ResultBuffer(
new TypedValue(1001, "xlentComms"),
new TypedValue(1000, pMslink + "," + pEntityNo)
);
obj.XData = rb;
rb.Dispose();
trans.Commit(); // Commit is always required to indicate success.
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
//db.SaveAs(ed.Document.Name, null);
db.SaveAs(ed.Document.Name, true, DwgVersion.Current, db.SecurityParameters);
}
现在要获取当前图中所有pLayerName Function GetLayers() As String()
Using Trans As Transaction = DB.TransactionManager.StartTransaction
Dim LayT As LayerTable = Trans.GetObject(DB.LayerTableId, OpenMode.ForRead)
Dim ID As ObjectId, LayTR As LayerTableRecord, Lays As New List(Of String)
For Each ID In LayT
LayTR = Trans.GetObject(ID, OpenMode.ForRead)
Lays.Add(LayTR.Name)
Next
Trans.Commit()
GetLayers = Lays.ToArray
End Using
End Function Database db = HostApplicationServices.WorkingDatabase;
List<LayerTableRecord> list = new List<LayerTableRecord>();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
LayerTable layertable = (LayerTable)trans.GetObject(db.LayerTableId,
OpenMode.ForWrite);//得到所有的层表
if (layertable != null)
{
foreach (ObjectId id in layertable) //遍历层表
{
LayerTableRecord tr=trans.GetObject(id,OpenMode.ForRead)
as LayerTableRecord; //获得层表记录
list.Add(tr); //将所有的图层放入一个集合中
}
}
}
希望能帮到你!!! 谢谢!
页:
[1]