Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on October 04, 2021, 08:25:35 AM

Title: Is there a good way to get a Master in to the document stencil without drop
Post by: Visisthebest on October 04, 2021, 08:25:35 AM
Is there a good way to get a master reliably into the document stencil without dropping a shape on to the page?

This just eliminates the unnecessary dropping then removing. The important thing is that the Master stays in the document stencil and there is not the possibility that a round of 'cleaning up' of the Visio document removes the master.

Maybe there is a setting where I can lock masters in place in the document stencil, even if there is no instance of the master on the page yet.

Or is dropping often-used shapes in to a hidden layer (so there is a shape instance and the Master cannot be 'cleaned up') a better way to go? Certainly not the most elegant solution but it would work. (or can masters actually be cleaned up if there is ONLY one shape instance on a page in the document?).

Thank you for sharing your insights & experience!
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Surrogate on October 04, 2021, 08:50:20 AM
You can drag master-shape from vss(x)-document to Document stencil!
(https://b.radikal.ru/b37/2110/9f/7a24d7b619a1.gif)
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Visisthebest on October 04, 2021, 08:52:59 AM
Thank you I need to do it with code, will see what Visio generates when I do that!
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Visisthebest on October 04, 2021, 08:59:36 AM
Ok I get some really easy code from the macro recorder so that will be very simple to do in code Surrogate thank you!

Application.Documents.Item("Visio document test file.vsdx").Masters.Drop Application.Documents.Item("BASIC_M.vssx").Masters.ItemU("Can"), 0#, 0#

The next question is, should I worry that is could be 'cleaned up' by Visio removing unused Masters at some point? Can I lock masters in to the Document Stencil just like I can protect shapes from delete on the page? (this also makes it harder for users to remove shapes).
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Surrogate on October 04, 2021, 08:59:45 AM
Quote from: Visisthebest on October 04, 2021, 08:52:59 AM
Thank you I need to do it with code, will see what Visio generates when I do that!
This code worksActiveDocument.Masters.Drop Documents.Item("Basic Shapes.vss").Masters.ItemU("Circle"), 0#, 0#
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Visisthebest on October 04, 2021, 09:08:18 AM
Thank you Surrogate using the ActiveDocument object even better!
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Surrogate on October 04, 2021, 09:21:52 AM
Quote from: Visisthebest on October 04, 2021, 08:59:36 AMThe next question is, should I worry that is could be 'cleaned up' by Visio removing unused Masters at some point?
1. You can make master as hidden in document stencil
ActiveDocument.Masters.ItemU("Can").Hidden = True It can prevent deletion from user!
2. You can create background page, and make it invisible. Drop there all masters which you need protect from purge.
    Dim vsoPage1 As Visio.Page
    Set vsoPage1 = ActiveDocument.Pages.Add
    vsoPage1.Name = "Background-4"
    vsoPage1.Background = True
    vsoPage1.Drop Application.Documents.Item("BASIC_M.vssx").Masters.ItemU("Square"), 2.362205, 5.846457
    vsoPage1.PageSheet.Cells("UIVisibility").FormulaU = 1

Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Visisthebest on October 04, 2021, 09:24:20 AM
Super Surrogate thank you, even better to use a background page rather than a layer, as I don't use the background page functionality ever!
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Surrogate on October 04, 2021, 09:38:39 AM
Quote from: Visisthebest on October 04, 2021, 09:24:20 AM
Super Surrogate thank you, even better to use a background page rather than a layer
if we talk about not advanced user, he It can accidentally detect a layer, unlock it and delete the shapes it contains. it can also, through the user interface, delete all pages in the document, including the one containing the layer storing the important wizard.
using the user interface it is not easy to get to the hidden backgroundpage  ;D
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Visisthebest on October 04, 2021, 09:44:51 AM
Yes the background page is a much better option, and just to be sure I will lock the shapes for delete as well.
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Surrogate on October 04, 2021, 09:53:58 AM
You can also add an additional level of protection:
Prevent changes to a Visio file (https://support.microsoft.com/en-us/office/prevent-changes-to-a-visio-file-eb71372a-9a10-4f92-b910-dfeb8de421b9)
Title: Re: Is there a good way to get a Master in to the document stencil without drop
Post by: Visisthebest on October 04, 2021, 10:11:28 AM
Did not know about that option as well, and I see you can protect Master shapes at this level too!

Thank you will explore this option as well.