Author Topic: Putting a 'button' on a shape to show/hide a container  (Read 478 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Full Member
  • ***
  • Posts: 128
Putting a 'button' on a shape to show/hide a container
« on: June 10, 2020, 03:18:58 AM »
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!
« Last Edit: June 10, 2020, 03:20:50 AM by Visisthebest »

vojo

  • Hero Member
  • *****
  • Posts: 1476
Re: Putting a 'button' on a shape to show/hide a container
« Reply #1 on: June 10, 2020, 07:19:02 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3800
  • Ideas Visio-lized into solutions
Re: Putting a 'button' on a shape to show/hide a container
« Reply #2 on: June 10, 2020, 08:42:32 AM »
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

  • Full Member
  • ***
  • Posts: 128
Re: Putting a 'button' on a shape to show/hide a container
« Reply #3 on: June 12, 2020, 02:11:45 AM »
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.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3800
  • Ideas Visio-lized into solutions
Re: Putting a 'button' on a shape to show/hide a container
« Reply #4 on: June 12, 2020, 08:45:36 AM »
Quote
What about gluing a button shape to the main shape
...that actually might work.
Visio 2019 Pro

Visisthebest

  • Full Member
  • ***
  • Posts: 128
Re: Putting a 'button' on a shape to show/hide a container
« Reply #5 on: June 12, 2020, 10:28:08 AM »
Ok super will let you know how I get on with this!

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3800
  • Ideas Visio-lized into solutions
Re: Putting a 'button' on a shape to show/hide a container
« Reply #6 on: June 12, 2020, 11:06:31 AM »
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

  • Full Member
  • ***
  • Posts: 128
Re: Putting a 'button' on a shape to show/hide a container
« Reply #7 on: June 12, 2020, 11:28:56 AM »
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!
« Last Edit: June 12, 2020, 11:30:59 AM by Visisthebest »

sax symbol

  • Newbie
  • *
  • Posts: 2
Re: Putting a 'button' on a shape to show/hide a container
« Reply #8 on: July 14, 2020, 11:37:48 AM »
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

  • Hero Member
  • *****
  • Posts: 1476
Re: Putting a 'button' on a shape to show/hide a container
« Reply #9 on: July 14, 2020, 10:33:37 PM »
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

  • Full Member
  • ***
  • Posts: 128
Re: Putting a 'button' on a shape to show/hide a container
« Reply #10 on: July 15, 2020, 03:49:35 AM »
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.

vojo

  • Hero Member
  • *****
  • Posts: 1476
Re: Putting a 'button' on a shape to show/hide a container
« Reply #11 on: July 15, 2020, 06:48:34 AM »
check for yourself.    SharePoint is FTP with some usability "sizzle"....nothing more