objectarx .net 获取图层名称

主要是通过遍历  layerTable 表的方式获取,方法很基础,只是本人菜鸟,才发现,代码如下:

[CommandMethod("getLayername")]
        public void GetLayerName()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

                foreach (ObjectId layerId in lt)
                {
                    LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(layerId, OpenMode.ForRead);
                    ed.WriteMessage(ltr.Name);
                }
                trans.Commit();
            }
        }


你可能感兴趣的:(AutoCAD二次开发,.net,database)