News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

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

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 197 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1052KB.
Tokens: post-login.
Cache hits: 13: 0.00116s for 26,767 bytes (show)
Cache misses: 2: (show)
Queries used: 16.

[Show Queries]