How to use the color of another layer for filling a shape

Started by VisioDrivesMeCrazy, July 13, 2021, 04:30:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

VisioDrivesMeCrazy

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?

Surrogate

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 !

VisioDrivesMeCrazy

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.

Surrogate

Please check this solution i make it in 5 minutes !


wapperdude

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

vojo

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.

VisioDrivesMeCrazy

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  :-\

vojo

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

VisioDrivesMeCrazy

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:


  • I have to enter ThePage!User.car instead of page!user.car in the "FillColor" (the latter doesn't work for me)
  • Putting an RGB value (e.g. "=RGB(30,30,0") ) into the Value field of user defined cell "User.car" results always in shape color black! However, when entering a numeric value (e.g. "38" or  "65") the color is changing as expected. But, when entering a numeric value of "38" directly as the "FillColor" value, then it gets converted to "RGB(192,80,70)" directly in the "FillColor" - Value field  :o  --> any idea what is happening there?

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)

Surrogate

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

vojo

format protection:
Option 1:  Use guard for fillforegnd and linecolor and line thickness
Option 2:  Under behavior, you check the "protect format" button.

VisioDrivesMeCrazy

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.

  • when entering "38" in Fill Format -> FillForegnd, Visio converts to "=RGB(192,80,70)"
  • using "." or ";" as delimiter results in an error message
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"...  :-\

vojo

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

bmwk100dk

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/ and found this in the comments section:
Hope you find a solution.

bmw100dk