Changing fill color from RGB values

Started by Jennifer, June 07, 2018, 01:05:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jennifer

Is there a way that I can assign RGB values to a shape and have that control the fill color and also display those 3 values somewhere on or near the shape?

I've attached an example of what I have in mind. I don't see it on the Preview. I hope it shows up when this is posted.
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

Sure.

You could use shape data properties, one for each color, e.g., prop.red.  Then, in the Foreground fill cell, =RGB(prop.red, prop.grn,prop.blue).  I think that should work for the coloring.

For text display, I'd use insert field, custom.  It would be something like = "(" & prop.red & " " & prop.grn & " " & prop.blu & ")"
I'm not at my computer, so you may have to fiddle the formula.  Not sure if the & is ok.  You may have to use chr(10) or is it char(10) ???.  And the value 10 may be incorrect too.

Of course, that puts the text right in middle of the shape, so you need to use the textbox control to resize and reposition the textbox as desired.

At least, those are the steps needed.

Wapperdude
Visio 2019 Pro

Hey Ken

Jennifer:

   Yes there's a way, but it's not very pretty.  Downright messy, in fact.  You can use the Text Fields shapesheet section to accomplish your goal. 

   The idea is to parse the FillForegnd cell from within the Text Fields section's Value cell.  Here's an example that isolates the first RGB value (assuming it's three digits):


Format: =FIELDPICTURE(0)
Value: =MID(FillForegnd,FIND("(",FillForegnd)+1,3)


   I only took the solution far enough to prove to myself it's possible, so my apologies for leaving the messiest part to you.  You'll need to replace the "3" with another Find command to locate the first comma, then append two more Mid functions to extract the next two RGB parameters along with their embedded Find functions.  Messy, as I said, but eminently doable.

   Good luck!

   - Ken


Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

wapperdude

#3
Back at computer...
The insert field formula works with the &.  If you don't want the ( and ), just eliminate them from the formula.

The fillforegnd formula works as indicated.

Attached is a sample.  Note, I also tweaked some of the Text Transfrom entries to control the textbox sizing and position based upon width of the text and size of the font.
Plus, added DOCMD(1312) to double click event to quickly access shape data entries.

Enjoy.
Wapperdude
Visio 2019 Pro

vojo

if the 4 shapes are in a group (like color cards ...dark blue to light blue

In the master / primary shape
- 3 user cells
- user cell 1 = setf(getref(sheet.2!fillforegnd), fillforegnd + 1)             
- user cell 2 = setf(getref(sheet.2!fillforegnd), fillforegnd + 2)
- user cell 3 = setf(getref(sheet.2!fillforegnd), guard(fillforegnd + 3))

3rd user cell makes sure nobody can mess with the 4th shape in the group

So what color you set for the first group...rest follow

As you mentioned, you may have parse fillforegrnd into red, blue, green...then build back up

Jennifer

Quote from: Hey Ken on June 07, 2018, 01:43:32 PM
Yes there's a way, but it's not very pretty.  Downright messy, in fact.
Thanks for that. It's probably too complicated (or messy) for my needs in this project, but I'll file it away for future reference.

PS: Isn't "pastiche parody" a contradiction in terms, like sweet sorrow, awfully good, business ethics, compassionate conservative, or logical liberal?

PPS: Good luck in the election this fall. My son's a libertarian despite my best efforts to bring him up right.  ;)
Using Visio 2019, part of Office 365 on Windows 10

Jennifer

Quote from: wapperdude on June 07, 2018, 02:25:13 PM
Back at computer...
The insert field formula works with the &.  If you don't want the ( and ), just eliminate them from the formula.

The fillforegnd formula works as indicated.

Attached is a sample.  Note, I also tweaked some of the Text Transfrom entries to control the textbox sizing and position based upon width of the text and size of the font.
Plus, added DOCMD(1312) to double click event to quickly access shape data entries.

Enjoy.
Wapperdude
Thanks for that. I'm still fiddling with it.
Using Visio 2019, part of Office 365 on Windows 10

Jennifer

Quote from: vojo on June 07, 2018, 03:21:15 PM
if the 4 shapes are in a group (like color cards ...dark blue to light blue

In the master / primary shape
- 3 user cells
- user cell 1 = setf(getref(sheet.2!fillforegnd), fillforegnd + 1)             
- user cell 2 = setf(getref(sheet.2!fillforegnd), fillforegnd + 2)
- user cell 3 = setf(getref(sheet.2!fillforegnd), guard(fillforegnd + 3))

3rd user cell makes sure nobody can mess with the 4th shape in the group

So what color you set for the first group...rest follow

As you mentioned, you may have parse fillforegrnd into red, blue, green...then build back up

That's an interesting approach. I don't need it for this project. My 4 examples were just that. But I can definitely see used for this in the future. Thanks.
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

Visio 2019 Pro

Hey Ken


Jennifer:

   Thank you muchly for your kind wishes!

Quote from: Jennifer on June 26, 2018, 05:32:51 PM

PS: Isn't "pastiche parody" a contradiction in terms, like sweet sorrow, awfully good, business ethics, compassionate conservative, or logical liberal?


   Yep, "pastiche parody" is meant to be an oxymoron because my novel is a respectfully serious parody of Ayn Rand's Atlas Shrugged, and something of a tribute to its author.  Pastiche is doubly apropos because it also means something made out of pieces, and I liberally use quotes from her novel (typically in an incorrect context), plus quotes from a variety of literary sources (Isaac Asimov's Foundation, Robert Heinlein's Stranger in a Strange Land, even Bill and Ted's Excellent Adventure, among dozens of others).  But you'd never notice if you didn't already know them.  And as you do know, I used Visio to assemble the pieces of the book's cover, so the word is triply apropos.

Quote from: Jennifer on June 26, 2018, 05:32:51 PM

My son's a libertarian despite my best efforts to bring him up right.  ;)


   As compared to bringing him up left?  ;- )  How about neither?  We'd better knock it off or Paul might ban us both for going off-topic!

   Thanks again,

   - Ken



Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com