TheSwamp
Code Red => .NET => Topic started by: itcad on November 12, 2008, 04:08:23 AM
-
Why cann't it delete a layer?
the code :
public void DeleteLayer(string layerName)
{
ObjectId layerId = ObjectId.Null;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite, true);
if (lt.Has(layerName))
{
layerId = lt[layerName];
if (lt[layerName].IsErased==false)
{
LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(layerId, OpenMode.ForWrite,true);
ltr.Erase();
}
}
trans.Commit();
trans.Dispose();
}
-
Without seeing any error you might be getting, I would suggest that it's either:
A: The layer you're trying to delete is the current layer, or,
B: The layer you're trying to delete has geometry or something else referencing it in the drawing.
Or, you've run into the dreaded 'default indexer' bug on the SymbolTables.