Prevent Stencil being editted

Started by AndyW, November 19, 2009, 04:16:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AndyW

Is there any means to prevent a read-only stencil from being edited. I have some users who are dropping shapes from the diagram back onto the stencil and when asked if they want to edit the stencil they says yes!!!!

Although this should be prevented by suitable training of the users, I was hoping for a way to prevent the stencil from being changed from read-only to editable. The QueryCancelDocumentClose event does not seem to be triggered in this instance, I do get a BeforeDocumentClose event but this is rather too late.

Visio 2003
Live life with an open mind

wapperdude

#1
Have you tried using Windows Explorer to go to the stencil file and set it's attributes to read-only?

Wapperdude

Hmmmm...this did sound vaguely familiar...

Lars-Erick had a similar issue, only with a template file, it might give you some alternative ideas:  [Tutorial]Preventing unwanted user input (http://visguy.com/vgforum/index.php?topic=15.msg26#msg26)
Visio 2019 Pro

AndyW

Thanks

Yes, setting it read-only does prevent it being edited. Although not ideal it may be a solution I can use. I used ideas similar to Lars for managing pages, it just seems there are somethings in Visio that it can be hard to completely lock down to prevent users from changing. Or if you can find out, usually its a bit too late through the process. Still can't really complain given all the other great things that you can do with Visio.
Live life with an open mind

AndyW

Alas, whilst it does prevent the stencil form being changed the stencil is still closed and reopened. I have references to the stencil documents to handle events, locate masters etc so these are messed up when the stencil is closed and reopened as my stencil document reference is no longer valid.
Live life with an open mind

aledlund

I'm not quite sure what you're looking to do, but do you understand that references to stencils (and their code) can be built dynamically in vba?
al

vojo

so Al...help understand how VBA code can be tied to a stencil (aka if I send the stencil, the code goes with it).

aledlund

Of course you can put code into a stencil. A stencil at it's simplist is merely a drawing that has been renamed. There have been several discussions on calling code back and forth between stencils and drawings. The fun part is to test from the drawing document (.vsd) whether a stencil is a.) loaded and, b.) referenceable from the core code in the drawing. If I read correctly (old age is not for sissies) AndyW ran into the issue of an attached stencil with code being disconnected ("closed and reopened as my stencil document reference is no longer valid"). If you do a search on me (aledlund) and "reference", I think I posted some code on how to attach dynamically to the code in a stencil.
al
found it
http://visguy.com/vgforum/index.php?topic=249.0

Visio Guy

#7
The stencils that ship with Visio have some sort of edit-prevention that is NOT the read-only flag that we can set in Explorer. This edit prevention seems limited to when a stencil is opened with a template in the docked state, but you can't add new masters, and you can't click in the upper-left corner of the stencil and choose to "Edit Stencil".

I'm digging around, trying to find how to do it, but I haven't found it yet. Either it is buried in the Developer Help, or it is some sort of secret...
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

AndyW

My problem relates to users dragging shapes off the diagram and back into a stencil (thinking that is how they delete shapes, by dragging them off the diagram! training helps, but some users don't seem to learn). So my aim was to try and prevent a shape being dropped back into the stencil. However, any events related this come much to late to stop the user.

My Visio application has links to various masters in the stencils being used, so the stencil being closed and reopened breaks all these.
Live life with an open mind

Visio Guy

Yes I understand. Look at the stencils that open with the templates that come with Visio, like Flowcharts. They are locked in a way that don't allow any editing, but the files themselves (in Program Files\...\...) are NOT set to read-only. There is some MS-internal way that this is being done.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

AndyW

Oh right, not used any of the MS stencils so never noticed that. So yes, must be some internal setting somewhere, that is exactly the behaviour I want  :(
Live life with an open mind

AndyW

That was great, gave me something different to search for and I have found the solution.

It seems you have to set 'allowEditing' on the window containing the stencil to false. So now I just go through the windows for my document and set this false for all the docked stencils. Edit Stencil is no longer an enabled option on the stencil menu and a message is given if the user attempts to drop a shape back into the stencil.

Thanks for the clue.
Live life with an open mind

Visio Guy

Nice find Andy!!! I was going nuts trying to figure this out, checking Document ShapeSheets and other nonsense.

For those interested in locking down open stencils, have a look here:

Window.AllowEditing Property

When reading that help entry, it says something about "stencils published to Visio using an .msi file", which leads me to believe that if you install stencils using the Visio solution publishing technique, then they might be non-editable by default, or perhaps this is an install option. I'd have to research this further.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010