Message 1 of 1
remove fdo group doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having a bug when i try to remove FDO group using .net API in Autocad MAP 2024.
Sample code i used:
public static void addGroupTest()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
using (DocumentLock docLock = doc.LockDocument())
{
AcMapMap currentMap = AcMapMap.GetCurrentMap();
MgLayerGroupCollection groups = currentMap.GetLayerGroups();
// create the layer group
var lGroup = new AcMapLayerGroup("test");
lGroup.SetDisplayInLegend(true);
lGroup.SetVisible(true);
lGroup.SetExpandInLegend(true);
groups.Add(lGroup);
}
}
public static void removeGroupTest()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
using (DocumentLock docLock = doc.LockDocument())
{
AcMapMap currentMap = AcMapMap.GetCurrentMap();
var group = currentMap.GetLayerGroups().Where(g => g.Name == "test").First();
Debug.Print($"before removal {currentMap.GetLayerGroups().Count}");
currentMap.GetLayerGroups().Remove(group);
group.Dispose();
Debug.Print($"after removal {currentMap.GetLayerGroups().Count}");
}
}
steps to reproduce:
- use addGroupTest: the group "test" is added to the map
- use removeGroupTest: the group "test" is removed from the map
Behavior encountered:
When i use removeGroupTest function, the group is removed from currentMap.GetLayersGroups() but still appear on the layer explorer.
If i try "addGroupTest" again, the code show me currentMap.GetLayersGroups() just one group, but i see two groups in layer explorer: "test" and "" (i presume Acad didn't want to add two groups with same name)
Here are several screenshots to illustrate:
Red, what i logged during removal (and surrended in red what i see in layer manager after 'removed")
Green, what i logged during add (after remove)
Layer manager after the second "add":