Hi,
I'm using Autocad 2012 and C#[2010].
How to get all the entities list and entity properties from a all the layer?
In the below code routines list all the layer name and count of entities.
my code Result:
0: 17
Model: 28
Center: 6
Dim: 14
Hidden: 22
Defpoints: 0
I want the result,
Layer Name: Model
Entity Name : Line
Properties: .......
......
......
I don't know how to make code for list entity name and their properties.
Please guide me the right direction.
public List<string> LayersToList(Database db)
{
List<string> lstlay = new List<string>();
LayerTableRecord layer;
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
foreach (ObjectId layerId in lt)
{
layer = tr.GetObject(layerId, OpenMode.ForWrite) as LayerTableRecord;
lstlay.Add(layer.Name);
}
}
return lstlay;
}
[CommandMethod("LLE")]
public void EntitiesOnLayer()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
List<string> info = LayersToList(db);
foreach (string lname in info)
{
ObjectIdCollection ents = GetEntitiesOnLayer(lname);
ed.WriteMessage("\n" + lname + ": " + ents.Count);
}
}
private static ObjectIdCollection
GetEntitiesOnLayer(string layerName)
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
// Build a filter list so that only entities
// on the specified layer are selected
TypedValue[] tvs =
new TypedValue[1] {
new TypedValue(
(int)DxfCode.LayerName,
layerName
)
};
SelectionFilter sf =
new SelectionFilter(tvs);
PromptSelectionResult psr =
ed.SelectAll(sf);
// I guess need to change here.
if (psr.Status == PromptStatus.OK)
return
new ObjectIdCollection(
psr.Value.GetObjectIds()
);
else
return new ObjectIdCollection();
}
Thanks in advance,
thenndral