public static void CreateLayerIFNonExisting(string layername) { Transaction trans = Active.StartTransaction(); var layerTable = (LayerTable)trans.GetObject(Database.LayerTableId, OpenMode.ForRead); if (!layerTable.Has(layername)) { var newLayer = new LayerTableRecord() { Name = layername }; layerTable.UpgradeOpen(); layerTable.Add(newLayer); trans.AddNewlyCreatedDBObject(newLayer, true); } trans.Commit(); }
public static void DeleteAllEntitiesOnLayer(string layername) { using (Transaction trans = Active.StartTransaction()) { TypedValue[] selectionCriteria = new TypedValue[] { new TypedValue((int)DxfCode.LayerName, layername) }; SelectionFilter filter = new SelectionFilter(selectionCriteria); PromptSelectionResult result = Active.Editor.SelectAll(filter); if (result.Status == PromptStatus.OK) { SelectionSet set = result.Value; ObjectId[] ids = set.GetObjectIds(); foreach (ObjectId id in ids) { id.GetObject(OpenMode.ForWrite).Erase(); } } trans.Commit(); } }