Author Topic: Why cann't it delete a layer?  (Read 1401 times)

0 Members and 1 Guest are viewing this topic.

itcad

  • Guest
Why cann't it delete a layer?
« 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();
         }

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Why cann't it delete a layer?
« Reply #1 on: November 12, 2008, 05:06:35 AM »
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.
Me