Add LayerGroup

Add LayerGroup

dan_nilsson
Observer Observer
376 Views
1 Reply
Message 1 of 2

Add LayerGroup

dan_nilsson
Observer
Observer

Is it possible to add a layergroup in the Task Pane (Display Manager) with .Net code?
I have tried this code but I get an error when I use grp.add(...). Have also tried with grp.Insert(...) but also an error show up. What do I need to do more to get it to work properly?


If I save the dwg file, and then open it again, the layergroup is there and it works.

Public Sub MapCreateGroup(ByVal sGrp As String)
Dim currentMap As AcMapMap = AcMapMap.GetCurrentMap()
Dim sName As String = currentMap.Name
Dim grpcol As MgLayerGroupCollection = currentMap.GetLayerGroups()
If (Not grpcol.Contains(sGrp)) Then
Dim MgLayGroup As New MgLayerGroup(sGrp)
MgLayGroup.SetDisplayInLegend(True)
MgLayGroup.SetExpandInLegend(False)
MgLayGroup.SetLegendLabel(sGrp)
grpcol.Add(MgLayGroup)
End If
End Sub

Error: An unclassified exception occurred.

0 Likes
377 Views
1 Reply
Reply (1)
Message 2 of 2

david_hequetTMA4M
Observer
Observer

I think you need to lock the document

 

Dim docLock As DocumentLock = _AcDocument.LockDocument
Using docLock
... your code
End Using 

 

0 Likes