As background information: A new Draw page will have 5 Layers with the index from 0 to 4...
Code: Select all
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
' 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
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
Code: Select all
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?
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.