Putting a 'button' on a shape to show/hide a container

Started by Visisthebest, June 10, 2020, 08:18:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

Adding VBA macros on the context menu of a shape is a very useful feature of Visio, but in this scenario I would like to add a 'button' on a shape the user can press to run a Sub (I will run the Sub in the stencil with CALLTHIS to get the ID of the shape it is run from).

I want to add a 'toggling button' with a + or - symbol on it (depending on the toggle state) on the shape that calls a Sub that shows or hides a container related to the shape.

(I add the container and the shapes/connectors contained by the container to their own layer, then I show/hide this layer in the Sub depending on the + or - state of the button. I use a custom connector that does not put connectors dropped from this master connector on the 'connector layer' so I can hide them as well without hiding all connectors).

What is the recommended way to add such a 'button' to a shape?

Thank you for your help and advice much appreciated!
Visio 2021 Professional

vojo

VBA:  If you want the cute button and rich flexibility of vBA
         Just got to get the foundation in place (calls in shape, security settings for other users to use it).

Actions:  Can use actions...not as pretty, but relatively simple
             in shapesheet of shape, insert actions section
             actions.show_hide = setf(getref(actions.show_hide), if (actions.show_hide.checked,0,1)
             actions.show_hide.label = "hide shape"
             Geometry<x>.noshow = if(actions.show_hide.checked,0,1)

             to use, right click shape...click on the "hide shape"
             now if you want to make it more usable, add another shape as the buttom and group them
             you can use that button shape to control hiding the real shape.
             actions in the button shape          E.g. in sheet.2!actions.show_hide
             geometry<x>.noshow in shape    e.g. in sheet.1....if(sheet.2!actions.show_hide.checked,0,1)

VBA more flexible but got to deal with security settings
Actions less VBA overhead but harder to extend for other things...if that is the goal

             

       

wapperdude

Some additional thoughts...
1)  the button, typically activated by dbl click, runs macro.  This fact forces a complex shape structure, e.g., grouped / container, and compounds coding issue to identify exactly what shape is being modified.  Dbl clicking steals Visio's "focus".  This has been done, but there are some idiosyncrasies that occur now and then.
2)  Just use dbl click the shape to run the macro, no additional button shape needed.
3)  Add button to the page.  However, this has issues too...how to identify desired shapes, different macros for different "classes" of shapes, etc.
4)  Dbl click page button brings up non-modal form, then...  see as example:  http://visguy.com/vgforum/index.php?topic=6373.msg26266#msg26266
          a) select desired shape(s) for updating
          b) select option on the form...could be a list of macros,
          c) run
4)  the cleanest method has been the right click, context menu.  But, that does require pre-planning, thus being somewhat inflexible. 


Visio 2019 Pro

Visisthebest

Thank you good to understand this is not as simple as hoped especially as each solution has some trade-offs.

What about gluing a button shape to the main shape, and capturing the double-click event on that shape? Would single-click starting a VBA Sub be feasible then too? Yes I understand this option has trade-offs too unfortunately.
Visio 2021 Professional

wapperdude

QuoteWhat about gluing a button shape to the main shape
...that actually might work.
Visio 2019 Pro

Visisthebest

Ok super will let you know how I get on with this!
Visio 2021 Professional

wapperdude

Conceptually...
1)  dbl click / rt  click the button to fire macro
2) macro searches button to see to whom it is glued
3) macro uses the shape identity to perform desired task.

It would also seem that...
a) many buttons could be glued to various shapes
b) many buttons, with unique macros, could be attached to a single shape
c) a single button might be moved from shape to shape

While these scenarios seem plausible, they all have one thing in common...added complexity.  Complexity, that, strictly speaking, isn't necessary, as Visio has adequate built-in features to do all of this without the need for buttons.
Visio 2019 Pro

Visisthebest

#7
I use NameU for types of shapes the macro can safely check wether it is glued to the correct shape type (identified by NameU) then execute itself on the specific shape it is is glued to (I will use CALLTHIS to call VBA in the stencil).

If someone changes the NameU of the shapes the button will stop working.

I will try it and see if I run into other undesirable side-effects, this could work it is a bit of a User Experience thing the context menu is a good option as well, but users can be demanding for UX features.

Is it possible to set shortcut keys with vba code so I can set up shortcut keys for running macros for the user, also a good option I think.

Thank your for your kind help!
Visio 2021 Professional

sax symbol

Hello, could the method described above be used to do the same thing in Sharepoint? I would like to do something similar by connecting an onclick event in Sharepoint to toggle shapes in a Visio Web part as described in this VisioGuy article:

https://www.visguy.com/2006/09/05/the-hidden-world-of-visio-shapes/

If I need to move this question let me know; I don't intent to hijack someone else's thread.

vojo

sharepoint is just a big bucket of capacity....it wouldn't know visio from a golf ball.
So you can place your visio drawing file there, but need visio somewhere else actually explore / modify the file.

Even in teams, the instance runs on your laptop subject to authorization from MS
It does not go up to MS for "move right 1 mm" action or "change red to blue" action

Visisthebest

sax this only works in the Visio desktop app, but there should hopefully be a way you can do this in Sharepoint with the online version of Visio. I guess with some javascript but haven't done much with the online version myself yet.
Visio 2021 Professional

vojo

check for yourself.    SharePoint is FTP with some usability "sizzle"....nothing more