Protect custom stencil shapes from themes

Started by Blackhawk, July 05, 2019, 02:59:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Croc

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

Croc

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

Croc

I apologize for any errors. Just writing as intermediate results appear. Maybe after that someone will have more correct thoughts :)

wapperdude

Generally, I wouldn't try to overwrite a Visio stencil.  Any alterations I would save to a new user defined stencil.
Visio 2019 Pro

Croc

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.

Blackhawk

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!

Croc

And I became smarter in the process of research :)

Blackhawk

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!

vojo

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.

Blackhawk

@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

Croc

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.

Croc

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

Croc

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

Blackhawk

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.


Croc

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