Visio Guy

Visio Discussions => Visio Bugs (er...Issues) => Topic started by: phillip_141 on May 11, 2017, 02:35:18 PM

Title: Layer.Add Method not functioning as expected
Post by: phillip_141 on May 11, 2017, 02:35:18 PM
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 (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
Title: Re: Layer.Add Method not functioning as expected
Post by: wapperdude on May 11, 2017, 03:46:19 PM
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 (https://msdn.microsoft.com/en-us/library/office/ff768462.aspx)

Wapperdude
Title: Re: Layer.Add Method not functioning as expected
Post by: phillip_141 on May 11, 2017, 04:07:50 PM
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.
Title: Re: Layer.Add Method not functioning as expected
Post by: wapperdude on May 11, 2017, 04:18:00 PM
In your code, you could add a loop to remove shape from each layer, then add to desired layer.

Wapperdude