As background information: A new Draw page will have 5 Layers with the index from 0 to 4...
- Code: Select all Expand viewCollapse view
oDoc = ThisComponent
oLM = oDoc.getLayerManager()
msgbox "Layer Count: " + str(oLM.Count) '<--- Layer Count: 5
'msgbox oLM.DBG_Properties
'msgbox oLM.DBG_Methods
aElementNames = oLM.getElementNames()
s = ""
For i = LBound(aElementNames) to UBound(aElementNames)
s = s + str(i) + ": " + aElementNames(i) + chr(10)
Next i
msgbox s
' Msgbox displays...
' 0: layout
' 1: background
' 2: backgroundobjects
' 3: controls
' 4: measurelines
A Draw page displays three of these layers which are labelled as: Layout, Controls, and Dimension Lines.
The LayerManager allows inserting additional layers, as follows...
- Code: Select all Expand viewCollapse view
oDoc = ThisComponent
oLM = oDoc.getLayerManager()
msgbox "Layer Count: " + str(oLM.Count) '<--- Layer Count: 5
oNewLayer = oLM.insertNewByIndex(oLM.Count)
oNewLayer.Name = "Layer" + str(oLM.Count - 1)
msgbox "Layer Count: " + str(oLM.Count) '<--- Layer Count: 6
The Draw page now displays the added layer tab as Layer 5. I use the following code to attempt to delete this newly added layer...
- Code: Select all Expand viewCollapse view
oDoc = ThisComponent
oLM = oDoc.getLayerManager()
msgbox "Layer Count: " + str(oLM.Count) '<--- Layer Count: 6
oLatestLayer = oLM.getByIndex(oLM.Count - 1)
oLM.remove(oLatestLayer)
msgbox "Layer Count: " + str(oLM.Count) '<--- Layer Count: 6 <--- huh?
My understanding from the reference manual ( https://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/XLayerManager.html ) is that oLM.remove(oLatestLayer) should have deleted the Layer 5. The oLM.DBG_Methods describes SbxVOID remove (SbxOBJECT). The code executes without error, but the layer still remains.
What I'm wondering is if oLM.remove(oLatestLayer) is this the correct code? If not, can someone supply the code that will perform the removal a layer?
Note that using a mouse I can right-click on the newly created Layer 5 tab, and from the drop down menu Delete Layer... will function OK and remove the layer. However I wish to do this under program control.
Thanks and regards, Ian.
PS: On checking the remove_layer_demo.odg file it already had two layers that I had created. I have replaced the file so it is representative of a new Draw document with only the default layers present.