.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How to get all names of layers in a drawing by traversal layers using c#?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
434 Views, 3 Replies
03-14-2012 09:32 PM
I want to get all names of layers in a drawing ,and then put them in a array. how to carry out it.
Re: How to get all names of layers in a drawing by traversal layers using c#?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-14-2012 10:35 PM in reply to:
dreamwtx
I think easier to gather layer names to List of string
then you can easy to convert to array using
List.ToArray() method
Here is a quick sample:
// This method can have any name
[CommandMethod("DisplayLayers","displa", CommandFlags.Modal)]
public void TestDisplayLayers()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
List<string> info = LayersToList(db);
foreach (string lname in info)
ed.WriteMessage("\nLayer Name: \t{0}", lname);
}
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;
}
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
C6309D9E0751D165D0934D0621DFF27919
Re: How to get all names of layers in a drawing by traversal layers using c#?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-15-2012 10:02 AM in reply to:
Hallex
Just curious Hallex, what's different about "StartOpenCloseTransaction" as opposed to "StartTransaction"?
Re: How to get all names of layers in a drawing by traversal layers using c#?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-15-2012 10:11 AM in reply to:
Paulio
To be honestly I did not read Arx docs about this
I use it when I just do nothing in the drawing,
as in this case to read something from document only
![]()
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
C6309D9E0751D165D0934D0621DFF27919
