Code Red > .NET

Why cann't it delete a layer?

(1/1)

itcad:
 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();
         }

Glenn R:
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.

Navigation

[0] Message Index

Go to full version