Layer.Add Method not functioning as expected

Started by phillip_141, May 11, 2017, 02:35:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

phillip_141

Hello all,
I'm trying to do some playing around with layers in my diagram so that I can hide/show certain shapes based on various conditions. I've been using the Layer.add method to add shapes in the diagram to the desired layer, which works fine, but the shapes are not removed from other layers.

ActivePage.Layers("Invisible Layer").Add shp, 0

According to the description at https://msdn.microsoft.com/en-us/library/office/ff766857.aspx, the second variable for layer.add should be zero to remove subshapes from any previous layer assignments; non-zero to preserve layer assignments. I'm using zero but the shapes are still sticking to the other layers.

Please help if able.
Thank you,
Phillip

wapperdude

See Remarks under the link you provided.  That parameter only applies to subshapes of a group, and only if the selected shape is a group.  Otherwise, no layer removal, just layer add.  To remove, you need the .remove method:  https://msdn.microsoft.com/en-us/library/office/ff768462.aspx

Wapperdude
Visio 2019 Pro

phillip_141

Well don't I feel stupid. I noticed that the effect worked on groups, but I assumed there was screwy behavior going on since I didn't see that it only works in groups. Thank you sir.

wapperdude

In your code, you could add a loop to remove shape from each layer, then add to desired layer.

Wapperdude
Visio 2019 Pro