Author Topic: Layer.Add Method not functioning as expected  (Read 2662 times)

0 Members and 1 Guest are viewing this topic.

phillip_141

  • Jr. Member
  • **
  • Posts: 22
Layer.Add Method not functioning as expected
« on: May 11, 2017, 09:35:18 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4043
  • Ideas Visio-lized into solutions
Re: Layer.Add Method not functioning as expected
« Reply #1 on: May 11, 2017, 10:46:19 AM »
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

  • Jr. Member
  • **
  • Posts: 22
Re: Layer.Add Method not functioning as expected
« Reply #2 on: May 11, 2017, 11:07:50 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4043
  • Ideas Visio-lized into solutions
Re: Layer.Add Method not functioning as expected
« Reply #3 on: May 11, 2017, 11:18:00 AM »
In your code, you could add a loop to remove shape from each layer, then add to desired layer.

Wapperdude
Visio 2019 Pro