Draw: set layer property "IsVisible"

The base is a drawing with several layers. Some are visible, some are printable and some have elements.
The task is, to copy and paste (at different place) the elements of specific layers and leaf the elements of other layers as the are.
As far as I know it is not possible to select the elements of an layer directly. So I will try to set all other layers invisible and select all visible elements.
But how can I set layers invisible? Following code dose nothing at all.

Sub SetLayerNotVisible()

Dim oController As Object : oController = ThisComponent.getCurrentController()
Dim oLayerManager As Object : oLayerManager = ThisComponent.getLayerManager()
Dim myLayer As Object : myLayer = oLayerManager.getByName("myLayerName")
Dim oActiveLayer As Object

oController.setPropertyValue("ActiveLayer", myLayer)
oActiveLayer = oController.ActiveLayer
oActiveLayer.setPropertyValue("IsVisible", False)

End sub

No Action also with this code!

...
code as above
...
oActiveLayer.IsVisible = False
...

The property is not marked as “read only” in MRI. So why doesn’t happen anything?

The interesting thing is, that this lines dose change the properties.

...
code as above
...
oActiveLayer.Title = "MyNewTitle"
oActiveLayer.Name= "MyNewName"
...

or

...
code as above
...
oActiveLayer.setPropertyValue("Title ", "MyNewTitle")
oActiveLayer.setPropertyValue("Name", "MyNewName")
...

Here is my sample file with a custom menu MyDrawMenu (near the Help menu), and three assigned Basic subroutine.

Update: Fixed macro.
DrawLayers.odg (19.5 KB)

That approach will not work. A layer has no information about the shapes. Only the other way round, the object knows on which layer it is.

Travers all objects of the draw page and inspect for each its property LayerID or its LayerName.

Do you want to copy and paste the objects to a different draw page or different document, or do you only want to move them to a different layer?

I want to copy the objects, change one or two of them (a number or a name), and paste them into the same document on the same layer next to the original objects. The objects include a rectangle as a frame object that specifies the width for moving before pasting.
All of this already works in a document with only one layer. The new task is to make this work in a document with multiple layers and objects on layers that must not be copied.

I did that. But in the first try the LayerID and LayerName where for all objects the same (all of the last layer) and totally wrong. But now I got it run with this code:


Sub GetLayerIdAndName()

Dim oController As Object : oController = ThisComponent.getCurrentController()
Dim oPage As Object : oPage = oController.getCurrentPage()
Dim numberOfShapes As integer : numberOfShapes = oPage.getCount()
Dim layerInfo As String
Dim shape As Object

Dim iShape As integer
For iShape = 0 To numberOfShapes - 1
	shape = oPage.getByIndex(iShape)
	layerInfo = layerInfo & iShape & " - "  & shape.LayerID & " - " & shape.LayerName & Chr(10)
Next iShape

MsgBox(layerInfo)

End sub

And I think it will bring me a big step forward. Thank you for your tip.