Visio Guy

Visio Discussions => Programming & Code => Topic started by: perry59 on January 20, 2020, 12:21:08 AM

Title: shapesheet, changing color of subshape
Post by: perry59 on January 20, 2020, 12:21:08 AM
I have a simple shape for a banana plug. It comes in several colors, each one with a slightly different part number. I have a fixed list for colors and I wanted the part number to change based on the users color selection. I found some code on John Goldsmith's blog here...https://visualsignals.typepad.co.uk/vislog/2018/02/using-a-2d-lookup-array-in-visio.html (https://visualsignals.typepad.co.uk/vislog/2018/02/using-a-2d-lookup-array-in-visio.html) that looked like it would do the trick. It worked just fine! when the user selects a particular color of plug the part number changes, woot!
I then decided I wanted the actual color of the shape to change as well. I thought the same technique would work, but the color of the subshape (the "grip" of the plug) does not change.
Can one of you shapesheet guru's take a look and tell me what I did wrong?
Thanks
Title: Re: shapesheet, changing color of subshape
Post by: vojo on January 20, 2020, 05:49:21 PM
Something like this

Group id = sheet.1
Handle = sheet.2
plug = sheet.3

Can use shape properties or actions...here we will do shape properties.  In essence, making a fixed list at the group level so no user can decide "peach" is the best color ;-)  .  The child shapes watch the group shape property to set their respective color.

- create shape data.....call it color
    - in format, fixed list.....red;green;blue    //check the separators...I think its ;
    - Handle.    sheet.2!fillforegrnd = if (strsame(sheet.1!props.color, "red"), RGB(255,0,0), if (strsame(sheet.1!props.green),RGB 0, 255, 0, RGB(0,0,255)))
    - plug...lets say is different hues    sheet.3!fillforegnd = if (strasm(sheet.1!props.color, "red", RGB(225,0,0),if (strsame(sheet.1!props.color, "green"), RGB (0,225,0),RGB(0,0, 225)))

So now in the group shape properties, you can pick a color...and the handle is bright color and plug is darker.

You can do this with actions as well, but its more complicated and user has 2 clicks to set color
(unset the current, set the new...probably throw in a few user cells to make debug easier)