eventdblclick to change color

Started by johanneshoogenboom, October 08, 2014, 08:07:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

johanneshoogenboom

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

Paul Herber

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.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

johanneshoogenboom

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

aledlund

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

Yacine

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)))
Yacine

wapperdude

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
Visio 2019 Pro

AndyW

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.
Live life with an open mind

johanneshoogenboom

#7
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

wapperdude

#8
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)
Visio 2019 Pro

johanneshoogenboom

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

wapperdude

Don't think that's possible.  No such shapesheet function and no such DOCMD shapesheet function.

Wapperdude
Visio 2019 Pro

vojo

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
   

johanneshoogenboom

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