Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: johanneshoogenboom on October 08, 2014, 08:07:59 PM

Title: eventdblclick to change color
Post by: johanneshoogenboom on October 08, 2014, 08:07:59 PM
Hello

This is my first time using Visio. I have a flow diagram created but I want users to be able to double click valves and have the colors change between green and red.

How do I go about this. Many thanks in advance!
-Johannes
Title: Re: eventdblclick to change color
Post by: Paul Herber on October 08, 2014, 08:30:35 PM
If you can write a macro to do the color change, the shape double-click operation can then be changed via the shape behavior dialog.

Title: Re: eventdblclick to change color
Post by: johanneshoogenboom on October 08, 2014, 08:43:47 PM
Thanks for the reply Paul.

I have used vba with excel but never with visio. I am sure I could record a macro, but I am not sure how to do the second part. Any suggestions?

Thanks
-Johannes
Title: Re: eventdblclick to change color
Post by: aledlund on October 09, 2014, 02:33:06 AM
Visio allows you to record a macro while you are making changes to a drawing. You can then use the recording as a template to understand what is happening 'under the covers' and then call an updated version of the macro to test it. Once your development of the updated macro is completed you can change the shapesheet of a shape and configure it to call the macro on a double-click event.
There are many example available on Chris Roth's site www.visguy.com

al
Title: Re: eventdblclick to change color
Post by: Yacine on October 09, 2014, 03:58:21 AM
You may also use only shapesheet functions.
The Double Click would switch a boolean value. (SETF(GetRef(Prop.Actuated),NOT(Prop.Actuated)))
And the filling would have 2 different values depending on the boolean one (IF(Prop.Actuated,RGB(0,255,0),RGB(255,0,0)))
Title: Re: eventdblclick to change color
Post by: wapperdude on October 09, 2014, 04:35:13 AM
If you only care about changing the color, and don't need to use a shape property for other purposes, you could set the colors directly with a slightly more complicated dblclick formula:
=IF(FillForegnd=RGB(255,0,0),SETF(GetRef(FillForegnd),RGB(0,255,0)),SETF(GetRef(FillForegnd),RGB(255,0,0))). 

This checks the status of the fill color, and then toggles the color between red and green.  But that's all it does.  It does not set any other properties.  Also, if the user happens to set the color using the user interface from the Menu bar or the ribbon, the formula in the Fillforegnd gets clobbered.  Since the above formula only writes a "color" to the Fillforegnd, it should (will) always work.

Wapperdude
Title: Re: eventdblclick to change color
Post by: AndyW on October 09, 2014, 07:39:55 AM
Maybe you should set actions for the shape (right mouse click - context menu). Then you could have actions of Open Valve, Close Valve and set the appropriate colour.
Title: Re: eventdblclick to change color
Post by: johanneshoogenboom on October 09, 2014, 07:36:41 PM
Thanks everyone for your replies.

Wapperdude: I used your solution and it works great except for one small issue. All of my valves are "Powered Valves" which means they are a grouped shape and this doesn't work on grouped shapes. I have about 50 valves so I am happy to go thru and ungroup the shapes and have the the little box at the top remain unfilled, but it would be nice to have the whole grouped shape change color. Any ideas?

Thanks again!!
-Johannes
Title: Re: eventdblclick to change color
Post by: wapperdude on October 09, 2014, 08:08:32 PM
If you're happy with double clicking the group, then what you need to do is to note the shape ID of the group, e.g., sheet.87, then, push into the each sub-shape, edit the shapesheet, and modify the fillforegnd value to contain the formula:  sheet.87!fillforegnd.  Do that for every sub-shape that you want to respond to the double click action.

You only need to do this once for the grouped shape.  Subsequent copies will update group ID automatically.

Wapperdude

Edit update:  put guard function around the formula:  guard(sheet.87!fillforegnd)
Title: Re: eventdblclick to change color
Post by: johanneshoogenboom on October 09, 2014, 08:32:31 PM
wapperdude thanks again. It all works now! I hate to be greedy but if I want visio to automatically deselect the shape after double click it. How do I seperate a new command in the events cell?

Thanks
-Johannes
Title: Re: eventdblclick to change color
Post by: wapperdude on October 09, 2014, 08:50:28 PM
Don't think that's possible.  No such shapesheet function and no such DOCMD shapesheet function.

Wapperdude
Title: Re: eventdblclick to change color
Post by: vojo on October 10, 2014, 05:12:33 PM
I do this all the time

eventdblclk = setref(getref(thepage!user.switch), if (thepage!user.switch = 1, 0 , 1)

In each shape, can take action

    show/hide:        sheet<xxx>!geometry1.noshow = if(thepage!switch = 1, 0, 1)
    change color:    sheet<yyy>!fillforegrnd = if(thepage!switch = 1, RGB(200,200,200), RGB(100,100,100)
    etc

Morever, on Eventdblclk, you can get real slick

    some dashboard or console shape
           eventdblclk = docmd(1312)
           set value to whatever you want (1 means this, 2 means that, 3 means some other)
           user.consoleswitch = setf(getref(thepage!user.switch) + dependson(props.consoleswitch)

    This does the following
           - triggers the GUI for properties
           - User sets the value of interest
           - when saved, triggers the user cell to write the value into the page user cell used by all other shapes
           - All other shapes triggered cause this page cell changed....they take action
   
Title: Re: eventdblclick to change color
Post by: johanneshoogenboom on October 10, 2014, 05:20:47 PM
wapperdude - thats no big deal. I really appreciate your help. This is going to make me look like a greek god at work! THANKS

VOJO - thats WAY beyond me, but thanks for sharing

-Johannes