Hi James,
But, that is the same behavior with AutoCAD's LAYISO command too.
It prevents any changes to the entities in those locked layers but are still selectable.
If you do not want them to be selectable, please try this
[CommandMethod("LayIsoThruCode")]
public void layisothrucode()
{
List<string> layers = new List<string> { "LAYER1" };
IsolateLayers(layers);
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.Editor.SelectionAdded += Editor_SelectionAdded;
}
void Editor_SelectionAdded(object sender, SelectionAddedEventArgs e)
{
ObjectId[] addedIds = e.AddedObjects.GetObjectIds();
Document doc = Application.DocumentManager.MdiActiveDocument;
using (Transaction tr = doc.Database.TransactionManager.StartOpenCloseTransaction())
{
for (int i = 0; i < addedIds.Length; i++)
{
ObjectId oid = addedIds[i];
Entity ent = tr.GetObject(oid, OpenMode.ForRead, false) as Entity;
if (! ent.Layer.ToUpper().Equals("LAYER1"))
{
e.Remove(i);
}
}
tr.Commit();
}
}
[CommandMethod("LayUnIsoThruCode")]
public void unisothrucode()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.Editor.SelectionAdded -= Editor_SelectionAdded;
UnisolateLayers();
}
This removes the entity object id from the selected list based on whether its layer was isolated or not.
Regards,
Balaji
Balaji
Developer Technical Services
Autodesk Developer Network