Author Topic: How to use the color of another layer for filling a shape  (Read 6105 times)

0 Members and 1 Guest are viewing this topic.

VisioDrivesMeCrazy

  • Newbie
  • *
  • Posts: 5
How to use the color of another layer for filling a shape
« on: July 13, 2021, 11:30:41 AM »
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?
« Last Edit: July 13, 2021, 11:39:39 AM by VisioDrivesMeCrazy »

Surrogate

  • Hero Member
  • *****
  • Posts: 1328
    • ShapeSheet™ Knowledge Base
Re: How to use the color of another layer for filling a shape
« Reply #1 on: July 13, 2021, 11:48:20 AM »
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

  • Newbie
  • *
  • Posts: 5
Re: How to use the color of another layer for filling a shape
« Reply #2 on: July 13, 2021, 11:55:37 AM »
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

  • Hero Member
  • *****
  • Posts: 1328
    • ShapeSheet™ Knowledge Base
Re: How to use the color of another layer for filling a shape
« Reply #3 on: July 13, 2021, 12:12:22 PM »
Please check this solution i make it in 5 minutes !

« Last Edit: July 13, 2021, 12:19:11 PM by Surrogate »

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4046
  • Ideas Visio-lized into solutions
Re: How to use the color of another layer for filling a shape
« Reply #4 on: July 13, 2021, 12: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.
Visio 2019 Pro

vojo

  • Hero Member
  • *****
  • Posts: 1577
Re: How to use the color of another layer for filling a shape
« Reply #5 on: July 13, 2021, 02: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.

VisioDrivesMeCrazy

  • Newbie
  • *
  • Posts: 5
Re: How to use the color of another layer for filling a shape
« Reply #6 on: July 14, 2021, 07:47:42 AM »
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

  • Hero Member
  • *****
  • Posts: 1577
Re: How to use the color of another layer for filling a shape
« Reply #7 on: July 14, 2021, 10:15:09 AM »
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

  • Newbie
  • *
  • Posts: 5
Re: How to use the color of another layer for filling a shape
« Reply #8 on: July 20, 2021, 05: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:

  • 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

  • Hero Member
  • *****
  • Posts: 1328
    • ShapeSheet™ Knowledge Base
Re: How to use the color of another layer for filling a shape
« Reply #9 on: July 20, 2021, 05:54:55 AM »
=RGB(30,30,0)
Do you use English language as default at your PC ? Non-English systems can have different delimeters…

vojo

  • Hero Member
  • *****
  • Posts: 1577
Re: How to use the color of another layer for filling a shape
« Reply #10 on: July 20, 2021, 07:52:44 AM »
format protection:
Option 1:  Use guard for fillforegnd and linecolor and line thickness
Option 2:  Under behavior, you check the "protect format" button.

VisioDrivesMeCrazy

  • Newbie
  • *
  • Posts: 5
Re: How to use the color of another layer for filling a shape
« Reply #11 on: July 20, 2021, 08:11:23 AM »
Quote
Do 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

  • Hero Member
  • *****
  • Posts: 1577
Re: How to use the color of another layer for filling a shape
« Reply #12 on: July 20, 2021, 12: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

bmwk100dk

  • Jr. Member
  • **
  • Posts: 16
Re: How to use the color of another layer for filling a shape
« Reply #13 on: July 22, 2021, 07:37:41 AM »
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