Visio Guy

Visio Discussions => General Visio => Topic started by: Blackhawk on July 05, 2019, 02:59:27 PM

Title: Protect custom stencil shapes from themes
Post by: Blackhawk on July 05, 2019, 02:59:27 PM
All

I am finally getting around to refreshing my custom stencils that I have been using for years.  It has been an annoyance when themes were introduced to have to shut off themes just to keep the colors and formatting of the stencils I have been using.

Now that I am getting around to cleaning them up, I would like to properly address this issue.    I would like themes to be active for a document, but whenever I drag in a shape from my stencil, I do not want it to be affected by the theme.   No matter what settings I enable on the master shape, it seems to ignore them, and I am not sure how to fix this.

I have followed a number of articles (including https://blog.bvisual.net/2016/06/10/protecting-shapes-from-themes-in-visio-2013/) but every time I drag the shape in, it re-colors it according to the theme.

Anyone have any ideas what might be going on here or how I can trace down why this is happening?

Title: Re: Protect custom stencil shapes from themes
Post by: Paul Herber on July 05, 2019, 03:08:51 PM
The top-level shape of the group is protected, but not the sub-shapes. You need to protect each sub-shape as well.
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 06, 2019, 06:08:08 AM
Paul,

I opened the group and applied protection to them as well and the same issue results.  I kept checking for more groups just to be sure, and I was at the lowest level.  Still no difference.


The only thing I can think of is that perhaps because it came from a VSS file and not VSSX, that it is retaining something or not upgrading when saved as a VSSX.

I say this because when I create a new document and open the stencil, then enable themes, I get a dialog stating that some shapes were created in an older version without theme support.

Could this be the issue?
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 06, 2019, 01:28:15 PM
Hmmm....additional playing around, and found that it was not the case where I get the dialog upon creating a new document and dragging in a stencil shape.   It must have been from the document I was using.

I tried also to protect Format (in addition to themes) and that also fails.

I am out of ideas.
Title: Re: Protect custom stencil shapes from themes
Post by: vojo on July 06, 2019, 10:00:15 PM
you should check again.   usually, you have to protect the child shapes explicitly
BTW, the other way to protect is to use guard    Fillforgnd = guard(rgb(200,200,200)...no matter what is done in UI, value stays same.
Title: Re: Protect custom stencil shapes from themes
Post by: wapperdude on July 07, 2019, 01:49:27 AM
Did some test cases as I recall there are some strange things with themes.  Duh.

Made a simple shape like the one you showed.  Upper child shape is filled with some color, lower child has white fill. Then made total of 4 variants:
1) no protection/guarding
2) theme protection at only group level
3) theme protection at group and child shapes
4) guarding at group and child shapes.

The results were: 
1) obvious...tracked with theme changes.
2) protected both group and child shapes...bit surprising, but worked.
3) ditto
4) mildly better than (1) above, but not very effective...quite surprising.

Went back and checked all the settings, and they are as initially set.  Note, as the themes were changing, I could see the shapes in the stencil change as well.

For reference:  I'm using V2019  Pro.
Title: Re: Protect custom stencil shapes from themes
Post by: vojo on July 07, 2019, 04:32:17 AM
thx wapperdude

Seems like a bug in #4 since guard is suppose to protect a cell from any UI changes
(guard shape...change a theme...shape changes....not the same behavior for pure colors ;-)  )
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 08, 2019, 05:41:52 PM
I saw what you put together in the document.   Maybe the problem isn't the shapes, but the starting stencil.   

What my shapes are based off of is "Divided Process 2" from "Miscellaneous Flowchart Shapes" stencil.    This is where I get the problem.   It does not behave like two shapes put together into one.
Title: Re: Protect custom stencil shapes from themes
Post by: wapperdude on July 08, 2019, 08:00:25 PM
I don't see the problem.  Here's updated file with the Divided shape from the Misc menu.  Everything still behaves as expected.
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 08, 2019, 10:26:12 PM
Ok, maybe it is the actual stencil file or my version of Visio 

I am using Visio Online Plan 2 - Desktop Program - Version 1808 (Build 10730.20348 Click to Run).

I have attached the VSSX file.

Drag each of these objects into a document and then set the theme.   In my version of Visio, all three change.
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 09, 2019, 07:15:57 AM
I checked Theme Issue.vssx on my PC. Visio 2013.
The "Theme Protected" master, dropped onto the page, changes color when applying a theme.
Then I did the following:
- Opened for editing the master in the Document Stencil
- Opened the Protection window
- Switched to "Not checked", then returned to "Checked" 6 CheckBoxes
- Clicked OK
Now the "Theme Protected" master works fine. Applying a theme does not affect the shape color.
It seems that despite the CheckBoxes are checked, the protection was imposed with an error.
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 09, 2019, 12:19:19 PM
If you checked 6 boxes, then you must have also checked "Group Formatting" in addition to themes.

Strange...so I followed exactly what you wrote in your steps and it did not work   >:(     I am wondering if this is a bug in my version and it is not setting the protection flags properly??

Can someone else try this on Visio 2019 or Visio 2016?   
Title: Re: Protect custom stencil shapes from themes
Post by: vojo on July 09, 2019, 12:21:13 PM
I guess this is adhering to MS test strategy:  "no smoke, touchdown baby, ship it"
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 09, 2019, 03:01:42 PM
AVI with recorded actions in Windows 10, Visio 2019 Professional
https://www.dropbox.com/s/vxnls9jt8zcch37/Project002.avi?dl=0
Title: Re: Protect custom stencil shapes from themes
Post by: wapperdude on July 09, 2019, 03:30:21 PM
I was able to confirm Croc's finding with V2019 Pro.  Dragged your theme protected shape onto a drawing.  Changing themes pushed fill color changes into the shape.  Went to Developer tab > protection.  Merely clicked off and back on the theme related entries...it was not necessary to change the "format", but probably a good idea.  The shape becomes protected. 

For V2019, easily fixable.
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 09, 2019, 05:38:41 PM
I continued research and received some more data.
1. The protection process I described works in the Document Stencil, but does not works in VSSX !
2. XML text comparison showed that good and bad master-shapes differ by 5 SchemeIndex values.
3. In VSSX, these values ​​are 0
When we drop the master from VSS to the Drawing Page, a copy of the master appears in the Document Stencil. SchemeIndex of that copy gets a non-zero value (in example 65534).
After the protection operation of this master-shape in the Document Stencil, 5 SchemeIndex cells take the value 0.
Conclusion (intermediate): Shapes in VSSX are protected. They spoil at the time of dropping on the page. If we then nullify the SchemeIndex in the Document Stencil, then the protection is returned against.
Need to continue research :)
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 09, 2019, 06:01:18 PM
The value 65534 is inherited from Styles / Theme.
If in the "Theme Properties" section of "Styles / Theme" ShapeSheet you set SchemeIndex = 0, then the shapes from "Theme Issue.vssx" will get into the document in a theme-protected state.
That is, to work with such a stencil, you must first prepare a document. Override one style. You can save such a document as a template.
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 09, 2019, 06:13:40 PM
I apologize for any errors. Just writing as intermediate results appear. Maybe after that someone will have more correct thoughts :)
Title: Re: Protect custom stencil shapes from themes
Post by: wapperdude on July 09, 2019, 11:44:53 PM
Generally, I wouldn't try to overwrite a Visio stencil.  Any alterations I would save to a new user defined stencil.
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 10, 2019, 11:15:24 AM
Blackhawk, I think I found a normal solution.
Your master shapes rely on styles. DFD Normal style inherits from Normal. In the document with themes, inheritance will turn into a chain of DFD Normal => Normal => Theme. This will change the indexes in the Theme Properties section.
To prevent this from happening, you must break the chain of inheritance. To do this, open the stencil for editing and add local formatting in the master-style DFD Normal. That is, manually write the zeros in the Theme Properties section through ShapeSheet. Values ​​should turn blue.
I changed the Theme Protected master in the Theme Issue - Copy.vssx stencil in this way. Check how it works.
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 10, 2019, 03:29:56 PM
I see others had the same behavior...good to know that I wasn't going crazy!  (well...I suppose that is still somewhat debatable)   

Croc:

Absolute genius!!!   Thank you so much!   Resetting the values on the format properties manually (even though they were already 0) finally fixed this nagging issue!

Here are a few virtual beers for you   🍺🍺🍺🍺

Cheers!
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 10, 2019, 04:16:23 PM
And I became smarter in the process of research :)
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 10, 2019, 09:09:22 PM
Oh, crap!   After going in and modifying a bunch of shapes in my stencil....it seems to only work in the current session of Visio.    When I quit and then came back again into a new document, it started on the same behavior again!!

Ugh!   This is very annoying!
Title: Re: Protect custom stencil shapes from themes
Post by: vojo on July 11, 2019, 02:51:15 AM
if you modify a shape within the stencil (edit shape in stencil vs pull to drawing, edit it,  and put it back in stencil).
Got to save the stencil before exiting Visio.

note Visio 2013 at least, Save/Saveas is unreliable...so either save multiple times or save stencil to new name and make sure name/timestamp is correct from outside visio before you exit visio.
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 11, 2019, 04:44:48 AM
@vojo,

Seriously?   Wow.   I thought QA was a bit better for MS Office products than that.   

Ok, let me try that again and let you know
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 11, 2019, 04:51:20 AM
QuoteWhen I quit and then came back again into a new document
The last proposed method corrects the style and assumes that the style to be copied from the stencil into the document. This works well in a new clean document.
But if the document is not empty, then problems may arise when copying the style. For example, if the document already has a style with the same name. If this is the reason, then you can first try to remove the old style (with the same name) from the document.
Too bad that Microsoft, when adding themes, made it impossible to work with styles through the GUI.
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 11, 2019, 07:14:00 AM
You can also break the chain of inheritance not in the stencil, but already in the document.
For example, you need to make the indexes of the "DFD Normal" style become independent of the Theme style. Execute the following macro in the document.
Sub ttt()
    For i = 0 To 7
        ActiveDocument.Styles.ItemU("DFD Normal").CellsSRC(visSectionObject, visRowThemeProperties, i).FormulaU = "0"
    Next
End Sub
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 11, 2019, 07:30:14 AM
Another useful macro will help you understand which styles are used in the stencil. It is now tuned to the stencil "Theme Issue.vssx".
Sub MasterStyleRelation()
    Set doc = Documents("Theme Issue.vssx")
    For Each m In doc.Masters
        Debug.Print "==== MasterName = " & m.Name
        With m.Shapes(1)
            Debug.Print .NameID, .Style
            For Each shp In .Shapes
                Debug.Print "  " & shp.NameID, shp.Style
                For Each shp2 In shp.Shapes
                    Debug.Print "    " & shp2.NameID, shp2.Style
                Next
            Next
        End With
    Next
End Sub
The output for this macro.
==== MasterName = Original
Sheet.5       DFD Normal
  Sheet.6     DFD Normal
  Sheet.7     DFD Normal
  Sheet.8     No Style
    Sheet.9   No Style
    Sheet.10  No Style
    Sheet.11  No Style
==== MasterName = Group Protected
Sheet.5       DFD Normal
  Sheet.6     DFD Normal
  Sheet.7     DFD Normal
  Sheet.8     No Style
    Sheet.9   No Style
    Sheet.10  No Style
    Sheet.11  No Style
==== MasterName = Theme Protected
Sheet.5       DFD Normal
  Sheet.6     DFD Normal
  Sheet.7     DFD Normal
  Sheet.8     No Style
    Sheet.9   No Style
    Sheet.10  No Style
    Sheet.11  No Style
==== MasterName = Depends
Sheet.5       No Style
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 11, 2019, 04:13:33 PM
Thanks for the code!   As a developer...this is more comforting than dealing with the sheets.   The only thing, is I don't know the object model, so there are a lot of properties to deal with.

Could I just set all the shapes styles to "No Style", and then delete all the styles in the stencil?     I tried deleting the DFD Style but that set everything to Normal and the problem persists.   If I could pro grammatically set everything that would be ideal.

Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 11, 2019, 05:08:26 PM
Replacing styles will require almost the same macro.
But before that, you will need delete protection from themes and formatting.
And after the macro again, format everything as it should and put a protection from themes against those.
Sub MasterStyleRelation()
    Set doc = Documents("Theme Issue - Copy (2).vssx")
    For Each m In doc.Masters
        Debug.Print "==== MasterName = " & m.Name
        With m.Shapes(1)
            .Style = "No Style"
            Debug.Print .NameID, .Style
            For Each shp In .Shapes
                shp.Style = "No Style"
                Debug.Print "  " & shp.NameID, shp.Style
                For Each shp2 In shp.Shapes
                    shp2.Style = "No Style"
                    Debug.Print "    " & shp2.NameID, shp2.Style
                Next
            Next
        End With
    Next
End Sub
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 11, 2019, 05:59:15 PM
Thanks.   This I have done, but I also want to set the Theme Properties to 0 and was not able to find where in the object model this is located.

Do you know how to find this?
Title: Re: Protect custom stencil shapes from themes
Post by: Croc on July 11, 2019, 06:22:58 PM
    For i = 0 To 7
        ActivePage.Shapes(1).CellsSRC(visSectionObject, visRowThemeProperties, i).FormulaU = "0"
    Next

Instead of ActivePage.Shapes (1) you need to substitute the desired shape
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 12, 2019, 01:12:31 PM
Ah!  Thanks.

I didn't see CellsSRC in the object model when looking at the watch window.    I will try that.

Thanks
Title: Re: Protect custom stencil shapes from themes
Post by: Surrogate on July 12, 2019, 02:22:17 PM
Please looking for "Sections, Rows, Cells" at right side
(https://i-msdn.sec.s-msft.com/dynimg/IC65739.gif)
PS You can't find these items in Watch Window
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 17, 2019, 04:18:05 PM
Just want to say thanks to everyone for your assistance.   

I ended up having to abandon the effort once again.  No matter what I do I still keep running into issues where Visio tries to change things despite protection settings, shapesheet guard formulas, etc., and it is taking WAY WAY too much time to debug and write code to make it work properly.   Such a shame...

The solution at the moment is to disable themes in the document and then everything works.   That is too bad because I would like other shapes to be themed in the same document but just leaving my stencil shapes alone.   

Once again, thanks for helping.   I learned some interesting things about Visio (quite frankly, however,...shouldn't need to know for this type of problem) that perhaps I can apply at some point down the road for other things.

Keep up the great work with the forum!
Title: Re: Protect custom stencil shapes from themes
Post by: vojo on July 17, 2019, 06:24:14 PM
one last suggestion:  Have tried guarding the theme cells themselves?
Title: Re: Protect custom stencil shapes from themes
Post by: Blackhawk on July 17, 2019, 06:34:14 PM
To some extent yes, but the problem is, I have a lot of different types of shapes and it takes a bit of time to discern what is all required.

For example, some shapes are just simple lines.   So the only way to protect those, seemed to be protecting the Format option, but then that affects the ability to change the arrows when in the document (which I need that ability).

Other times, the shapes are composites which some shapes need protecting in one way, and other shapes need it differently.   It became quite a daunting task to test all the possibilities of what to protect and what not to.   It wasn't like I had hoped which was just loop through all the shapes and subshapes setting all the theme properties to 0.   Sometimes they had formulas in them. 

I have learned that Visio is pretty damned powerful, but also frickin complicated if it doesn't behave like you want it to.   It would be nice if the "Theme Protection" settings just worked, but there seems to be so many other factors that get in the way.

Maybe when I am bored and have nothing better to do with my life, I will go back in and figure this out.  Right now, I gotta get stuff done.   :o
Title: Re: Protect custom stencil shapes from themes
Post by: vojo on July 22, 2019, 01:00:17 PM
could try themeguard instead of guard