Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: VisioDrivesMeCrazy on July 13, 2021, 04:30:41 PM

Title: How to use the color of another layer for filling a shape
Post by: VisioDrivesMeCrazy on July 13, 2021, 04:30:41 PM
Hi Folks,

I'm trying to use the Layer-Color of one Layer (say, "Layer_A") to fill a shape which is not on this layer.

Reason: I want to have shapes which can be assigned to different layers (for making them visible / hiding them in logical groups), but want to control the color of this shapes (or parts of them) via one separate Layer which only acts as a "color selector" (no shapes assigned to that layer, just a layer color defined.

I tried to achieve this by using the ShapeSheet (of the shape residing on "Layer_B", which should be filled with the color of "Layer_A") and putting the following code into the "Fill Format > FillForegnd" field: Application.ActivePage.Layers.Item("Layer_A").CellsC(visLayerColor)

Unfortunately, I always get an error message telling that there is an error in the formula.
However, when I use the VBA direct window, then a print(Application.ActivePage.Layers.Item("Layer_A").CellsC(visLayerColor)) returns a 38 as result and putting 38 into the ShapeSheet field results in filling the shape with the correct color (however, the 38 is changed to RGB(192,80,70) when leaving the field).

Does anybody have an idea what I'm doing wrong or how to (better) achieve what I'm trying to do?
Title: Re: How to use the color of another layer for filling a shape
Post by: Surrogate on July 13, 2021, 04:48:20 PM
I am not big fan of layers in MS Visio, but as I know if shape assigned to 2 or more layers it still black !
Title: Re: How to use the color of another layer for filling a shape
Post by: VisioDrivesMeCrazy on July 13, 2021, 04:55:37 PM
You're right (however, I'm a layer fan since I frequently have to hide / unhide parts of the drawing).
However, I do not want to assign one shape to multiple layers. I just want to assigne one shape to one layer (a layer without a layer color) and use another (empty) layer to define a layer color there and just reference to that layer color in my shape. That's why I try it to do with that VBA style object referencing code in the ShapeSheet.
Title: Re: How to use the color of another layer for filling a shape
Post by: Surrogate on July 13, 2021, 05:12:22 PM
Please check this solution i make it in 5 minutes !
(https://c.radikal.ru/c12/2107/d9/daaf934822ce.gif)
Title: Re: How to use the color of another layer for filling a shape
Post by: wapperdude on July 13, 2021, 05:30:58 PM
Another possible approach...
1) keep the layers for group membership, but
2) don't use layer for coloring.

Instead, setup a true/false page data property or action property that the shapes refer to.  Just a thought.  That ought to avoid multiple layer memberships.
Title: Re: How to use the color of another layer for filling a shape
Post by: vojo on July 13, 2021, 07:07:12 PM
I think you may be wrapping yourself around the axle here.   I dont think you want to use layers for color control.
it seems to me you are going long way around on this:
-if you want to color shape and bind it to layer (vba, shapsheet, UI)...that is easier than your approach
-if you want to do some sort of handle (car = red, truck = blue) ...set shape data to control fill color in shapesheet
-if this is about assigning shapes...create a stencil and let user drag n drop.
Title: Re: How to use the color of another layer for filling a shape
Post by: VisioDrivesMeCrazy on July 14, 2021, 12:47:42 PM
Thanks for the replies so far. However, I think I was misunderstood. Maybe my explanation was not clear enough.

I don *not* want to assign one shape to more than one layer.

I want to create a (grouped) shape which consists of at least two basic shapes. One is a border, which is always black (black rectangle). The second is a symbol (e.g. a circle or an arrow) inside that black rectangle. Both get grouped. While the rectangle always stays black, I want to be able to change the color of the symbol. So far, not a problem.

However, I want to use this created Shape(s) in a drawing several times. Let's say: use the shapes 8 times and assign two of each to Layer "North", "South", "East" and "West" (these layers don *not* have set a layer color - they are only there for making parts of the drawing visible / invisble!).
I also want to change the color of the "symbol" in each of the shapes at  a later time to another color without touching each of the shapes again to change the symbol colour for every single shape.
This is why i want to set the fill color (and also the line color) to reference to an (color) object that I can use later to change the color of all "symbol" shapes at one time by just changing the color of this one, referenced object.
Theoretically this could be also a separate shape on a separate (invisible) layer for which I change the color. However, I thought it would be better to just use directly the color setting of a layer (which does not hold any shapes, just acts as a color picker).
Means: All (grouped) shapes (including the "symbol" sub-shapes) are residing on one of the layers "North", "South", "East" or "West", but the color for the "symbol" shapes is derieved from the layer color of layer "ColorPickerLayer".

I think I'm very close to a solution with what I tried to do, but only have a little mistake either in the syntax or e.g. a type mismatch - but I don't find the error. Unfortunately, the error message I get does not give any hint what'S wrong  :-\
Title: Re: How to use the color of another layer for filling a shape
Post by: vojo on July 14, 2021, 03:15:09 PM
as far as I can tell....this sounds like taking the long way around to the destination.

The thing that stood out to me was change the color of all shapes in a class.
To do that, you can go to the document stencil and change the color there.....that will change all shapes in the drawing.

Maybe I dont see the problem you want to solve, but I am pretty sure that using layers for color control is not realistic.

another way to do color control could be
- user cells at the page level   e.g.   user.car = RGB(0,0,200).....user.truck = RGB(200,0,0)
- Car shape use page!user.car for fill color
- same for truck
- want to change color of cars, then got to page!user.car and change the RGB value
Title: Re: How to use the color of another layer for filling a shape
Post by: VisioDrivesMeCrazy on July 20, 2021, 10:33:19 AM
Hello @vojo,

thanks for your suggestions! - I think, I'll use the second option with the user cells on page level (or even on document level?)

However, I ran into new problems when I tried to implement:


Another, additional question: Is there a way to protect a shape from beeing formatted with the Layer Colour in case it is (accidentially) assigned to a layer which has a layer color defined?
I tried different possible options that came to my mind / I found with Google (e.g. protecting the shape and the sheet or using function "GUARD()" and "THEMEGUARD()" for defining the color value via ShapeSheet), but up to now I did not find any way to protect the shape from getting the Layer Color once one is defined for the layer the shape is residing on...

Btw.: I'm using the MS365 version of Visio (Visio 2008 / MS Visio Plan 2)
Title: Re: How to use the color of another layer for filling a shape
Post by: Surrogate on July 20, 2021, 10:54:55 AM
Quote from: VisioDrivesMeCrazy on July 20, 2021, 10:33:19 AM=RGB(30,30,0)
Do you use English language as default at your PC ? Non-English systems can have different delimeters...
Title: Re: How to use the color of another layer for filling a shape
Post by: vojo on July 20, 2021, 12:52:44 PM
format protection:
Option 1:  Use guard for fillforegnd and linecolor and line thickness
Option 2:  Under behavior, you check the "protect format" button.
Title: Re: How to use the color of another layer for filling a shape
Post by: VisioDrivesMeCrazy on July 20, 2021, 01:11:23 PM
QuoteDo you use English language as default at your PC ? Non-English systems can have different delimeters...
Yes and no...  ;D - English Win10, Locales: german, Visio: german MUI
However, I can rule out that delimiter is causing the issue.
However, your hint was valuable anyway: I tried the other way round, means, entering "=RGB(192,80,70)" as value of the "User.car" cell - this works now!
Thus, at the moment it seems for me that not every RGB color value can be used as value for "FillForegnd"...  :-\
Title: Re: How to use the color of another layer for filling a shape
Post by: vojo on July 20, 2021, 05:11:07 PM
each (R value, G value, B value) can be from 0 to 255.
BTW, you could play with colors using the HSU approach, that is recognized by Visio as well
Title: Re: How to use the color of another layer for filling a shape
Post by: bmwk100dk on July 22, 2021, 12:37:41 PM
Hi
I think vojo might be on to something. I had a similar problem, and my setup is the same as yours (except danish instead of german). I found this solution:
http://www.visguy.com/2010/04/21/list-separators-in-visios-shapesheet-are-crazy/ (http://www.visguy.com/2010/04/21/list-separators-in-visios-shapesheet-are-crazy/) and found this in the comments section:
Hope you find a solution.

bmw100dk