How Do You Read a Shape's Color?

Started by qianjin_w, July 04, 2009, 09:37:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

qianjin_w

how to read  shape's color? use what method ?

Lars-Erik

#1
Shape.FillForegnd
The integer in that field will determine the color of the shapes "fill"
e.g 0 = black, 1=white

- Lars

qianjin_w

#2
But no that field FillForegnd.  My project control Visio 2003,how can i do?

Visio Guy

Try:

Dim shp as Visio.Shape
Set shp = Visio.Application.Selection.Item(1)

Debug.Print shp.Cells("FillForegnd").Formula
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

vojo

#4
you will also need to realize the data can be one of 3 flavors
- single number for popular colors (0=black I think)
- RGB(red tone, green tone, blue tone).....RGB(128,128,128)
- HSL(hue, saturation, lumination)

personally, I play with RGB...more precision and control.   There are functions to convert where possible.

values in RGB are from 0 to 255 for each color....you can make complex formulas (VBA or shapesheet) to ensure roll over or to ensure one field is an offset of another (shading on a cube).  You can also use this approach to set text color in that field to be compatible (black with white text...white with black text) using the mod function at say 128 
( RGB(200,200,200)  - aka light grey - drives text to RGB(72,72,72) - aka dark grey).

Nikolay

Please take a look at this topic - if you don't want to get buried with formulas, and just want the "raw" RGB ;)


  myRGB = shp.Cells("FillForegnd").ResultStr(visNoCast) ' this shall result in something like "RGB(205, 115, 107)"


The above works just fine (thanks Chris!), but there is one caveat - you might need to take special care of the separators (comas), because they are locale-dependent.
Means, you can get semicolons or other funny stuff there instead of comas dpending on your system locale (this is the "list separator" symbol)

Kind regards, Nikolay.

Visio Guy

If you use ResultStrU instead of ResultStr, then you should always get the commas, and not have to worry about culture-specific list separators.

The "U" stands for universal, by the way, and you'll find lots of shape/ShapeSheet access methods have both U and non-U versions.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Nikolay