.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Purge Layer empty

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
242 Views, 2 Replies

Purge Layer empty

I need to Purge the layer not used that dont contain nothing.
There is a flag that contain this information.
Or i must ,before erase the layer, make a selection with filter for each
layer?

to Purge block i have found :
ObjectIDs = Blocco.GetBlockReferenceIds(True, True)

this function return a collection of objectid that is the number of
blockreference still insert.

Many thank's in advance.

GPaolo
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

[code]
[CommandMethod("PurgeAllNonRefLayers")]
static public void PurgeAllNonRefLayers()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
LayerTable lt = (LayerTable)(trans.GetObject(db.LayerTableId, OpenMode.ForRead));
ObjectIdCollection ids = new ObjectIdCollection();
foreach (ObjectId id in lt)
{
LayerTableRecord ltr = (LayerTableRecord)(trans.GetObject(id, OpenMode.ForRead));
ids.Add(ltr.ObjectId);
}
db.Purge(ids);
if (ids.Count > 0) {
foreach (ObjectId id in ids) {
LayerTableRecord ltr = (LayerTableRecord)(trans.GetObject(id, OpenMode.ForWrite));
ltr.Erase();
}
}
trans.Commit();
}
finally
{
trans.Dispose();
}
}
[/code]
Message 3 of 3
Anonymous
in reply to: Anonymous

Perfect.
Many Thanks
GPaolo
ha scritto nel messaggio
news:5157787@discussion.autodesk.com...
[code]
[CommandMethod("PurgeAllNonRefLayers")]
static public void PurgeAllNonRefLayers()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
LayerTable lt = (LayerTable)(trans.GetObject(db.LayerTableId,
OpenMode.ForRead));
ObjectIdCollection ids = new ObjectIdCollection();
foreach (ObjectId id in lt)
{
LayerTableRecord ltr = (LayerTableRecord)(trans.GetObject(id,
OpenMode.ForRead));
ids.Add(ltr.ObjectId);
}
db.Purge(ids);
if (ids.Count > 0) {
foreach (ObjectId id in ids) {
LayerTableRecord ltr = (LayerTableRecord)(trans.GetObject(id,
OpenMode.ForWrite));
ltr.Erase();
}
}
trans.Commit();
}
finally
{
trans.Dispose();
}
}
[/code]

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost