Stencils help

P

Paul

Hi,
after loading the required stencils in my application, the document stencil
is always the one that gets expanded, so I was wondering if there was a way
to have a different stencil selected on startup (would it be possible to hide
the document stencil?)

Also, how do I make the stencils read only? As of right now I am able to
drag and drop objects from other stencils, however this is definitely not the
desired behavior in my case.

Thank you
 
P

Paul Herber

Hi,
after loading the required stencils in my application, the document stencil
is always the one that gets expanded, so I was wondering if there was a way
to have a different stencil selected on startup (would it be possible to hide
the document stencil?)

The document stencil should not normally be visible, if you close the
stencil and save the document then it shouldn't open next time.
Also, how do I make the stencils read only? As of right now I am able to
drag and drop objects from other stencils, however this is definitely not the
desired behavior in my case.

Do the stencils have a small red asterisk visible at the left hand
edge of the stencil header?
Stencils shouldn't normally be open for writing.

Is your application an addon that opens these stencils?
 
P

Paul

Hi,
This is how I open the stencils:

private void LoadStencil(String stencilLocation)
{
// Open the stencil
Document currentStencil =
axDrawingControl1.Document.Application.Documents.OpenEx(stencilLocation,
(short)VisOpenSaveArgs.visOpenDocked);

// Show the stencil
Window stencilWindow = currentPage.Document.OpenStencilWindow();
}

It appears that the stencil is read-only at first, however if I copy / paste
an object inside the stencil, a message box pops up asking me if I want to
allow editing. Clicking Yes, will then add the object to the stencil and a
Save icon appears on the right hand side of the stencil header.

For some reason I'm not able to get rid of the document stencil, is it
possible to do it from the code?

Thanks
 
D

David Parker

But you explicitly asked to show the document stencil?
It is always there, even if you don't call OpenStencilWindow to make it
visible.
 
P

Paul Herber

Hi,
This is how I open the stencils:
// Show the stencil
Window stencilWindow = currentPage.Document.OpenStencilWindow();

This is the line the opens the document stencil, you don't need it.
It appears that the stencil is read-only at first, however if I copy / paste
an object inside the stencil, a message box pops up asking me if I want to
allow editing. Clicking Yes, will then add the object to the stencil and a
Save icon appears on the right hand side of the stencil header.

I don't understand why you are doing a copy/paste within the stencil.
But just make the stencil file read-only.
 
G

Gunslingor

I think I am having the same/similar problem. Explaination after code. Heres
my code:

Private Sub AutoAddMenus()

'DrawingControl0.vsoapp.StencilPaths =
DrawingControl0.vsoapp.StencilPaths & ";" & Stencil_Path

Dim vsoWin As Visio.Window
Set vsoWin = DrawingControl0.Window

Dim vsoWins As Visio.Windows
Set vsoWins = DrawingControl0.Window.Application.Windows

Dim vsoDoc As Visio.Document
Set vsoDoc = DrawingControl0.Document

Dim vsoDocs As Visio.Documents
Set vsoDocs = DrawingControl0.Window.Application.Documents

Dim vsoApp As Visio.Application
Set vsoApp = DrawingControl0.Window.Application

Dim vsoStencilWindow As Visio.Window

Dim vsoTVAstencil As Visio.Document

Dim Path As String
Dim Stencil1_Name As String
Dim Stencil_Path As String
Path = CurrentProject.Path()
Stencil1_Name = "Customer Cyber Network.vss"
Stencil_Path = Path & "\Visio Stencils\" & Stencil1_Name

'add the standard customer stencil to documents collection
'Set vsoStencilWindow = vsoApp.Window
'vsoStencilWindow.AllowEditing = False
'Set vsoStencilWindow = vsoTVAstencil.OpenStencilWindow


Set vsoTVAstencil = vsoDocs.Add(Stencil_Path)
vsoTVAstencil.Title = "Customer Standard Stencils"
'Set vsoStencilWindow = vsoDoc.OpenStencilWindow
'Open the Document Stencil window.
'Set vsoStencilWindow = vsoWins.Add()
'vsoStencilWindow.AllowEditing = False

End Sub

It is still in development. As displayed above, everything works great
except that the "Customer Standard Stencils" document is open for editing.
Everytime I close the window it asks me if I want to save the stencil. There
is a property of a "window" object called "AllowEditing" (True/False); it
doesn't work on document objects. So I need the stencil window. I don't know
how to get the window of the stencils other than using the OpenStencilWindow
function. But this also opens the document stencil and only appears to run
successfully on the first open of the form; after that, I get an error
something like "objects property is currently disabled". So, how do I not
allow people to edit stencils and stop the save as message each time the form
closes?
 
A

AlEdlund

An observation from the side, what you're trying to protect from writing
isn't the window but the stencil (which is a document). The second issue of
the message on close has to do with flagging any open documents as having
been saved before trying to close them. Perhaps these code snippets might
help.
al

Private Function TestStencilLoaded _
(ByVal strStencil As String) _
As Boolean

On Error GoTo TestStencil_err

Dim vsoDocs As Visio.Documents
Dim vsoDocStencil As Visio.Document
Dim intDoc As Integer
Dim blnReturn As Boolean
Dim strDocName As String
blnReturn = False

' Find the stencil in the Document collection by name.
Set vsoDocs = ThisDocument.pWorkDoc.Application.Documents

For intDoc = 1 To vsoDocs.Count
strDocName = vsoDocs.Item(intDoc).Name
If LCase(strDocName) = LCase(strStencil) Then
blnReturn = True
Exit For
End If
Next intDoc

TestStencilLoaded = blnReturn
Exit Function

TestStencil_err:
TestStencilLoaded = blnReturn

End Function


Private Function LoadStencil _
(ByVal strStencil As String) _
As Boolean

Dim blnReturn As Boolean
Dim retDocument As Visio.Document

On Error GoTo LoadStencil_Err


If TestStencilLoaded(strStencil) = True Then GoTo LoadStencilComp

Dim strPath As String
strPath = ThisDocument.pBaseDoc.Path

Dim fs As FileSystemObject
Set fs = CreateObject("scripting.filesystemobject")

Dim strFile As String
strFile = strPath & strStencil

If fs.FileExists(strFile) = False Then
MsgBox "Stencil " & strFile & " not in directory with drawing"
End If

'Constant Value
'visOpenCopy 1
'visOpenRO 2
'visOpenDocked 4
'visOpenDontList 8
'visOpenMinimized 16
'visOpenRW 32
'visOpenHidden 64
'visOpenMacrosDisabled 128
'visOpenNoWorkspace 256


Set retDocument = Application.Documents.OpenEx _
(strFile, visOpenDocked + visOpenRO)

LoadStencilComp:
LoadStencil = True
Exit Function

LoadStencil_Err:

LoadStencil = False

End Function


Private Sub closeDocument(ByRef docClose As Visio.Document)

If Not (docClose Is Nothing) Then
' flag as having already been saved so we do not get message
docClose.Saved = True
docClose.Close
Set docClose = Nothing
End If
Exit Sub

ErrHandler:

Debug.Print "close document failed " & Err.Number & " " &
Err.Description

End Sub
 
G

Gunslingor

I got it working well, but not reliably. I say not reliably because I kept
getting the message "requested operation is currently diabled" when the code
got to the OpenStencilsWindow command. Then I closed and reopend the program
and everything works great. So, hopefully that message might not come back.
Here is the critical part of the code that works.

' Load the stencil we want
Set vsoTVAstencil = vsoDocs.OpenEx(Stencil_Path, visOpenDocked)
'// show the stencil window
Set vsoStencilWindow = vsoTVAstencil.OpenStencilWindow
vsoStencilWindow.AllowEditing = False

the allowediting appears to have defaulted to "false" when I use the openEx
method instead of the Add or Open method. Still don't know why I kept getting
that error message. Hopefully, it will continue to work.
 
P

Paul Herber

I got it working well, but not reliably. I say not reliably because I kept
getting the message "requested operation is currently diabled" when the code
got to the OpenStencilsWindow command. Then I closed and reopend the program
and everything works great. So, hopefully that message might not come back.
Here is the critical part of the code that works.

' Load the stencil we want
Set vsoTVAstencil = vsoDocs.OpenEx(Stencil_Path, visOpenDocked)
'// show the stencil window
Set vsoStencilWindow = vsoTVAstencil.OpenStencilWindow
vsoStencilWindow.AllowEditing = False

the allowediting appears to have defaulted to "false" when I use the openEx
method instead of the Add or Open method. Still don't know why I kept getting
that error message. Hopefully, it will continue to work.

I'd still like to know what you are trying to do here. Whatever it is
I'm very surprised that it works, OpenStencilWindow is a method that
operates on the Document stencil, not any stencil that you specify.
And then you are trying to prevent any write operations on the
document stencil. I think you are asking for trouble there.
 
G

gunslingor

I'd still like to know what you are trying to do here. Whatever it is
I'm very surprised that it works, OpenStencilWindow is a method that
operates on the Document stencil, not any stencil that you specify.
And then you are trying to prevent any write operations on the
document stencil. I think you are asking for trouble there.

Strange. I posted this to thread to another form, and here it is in
this one listed with a wierd name. Oh well. Anyway, it is working.
documentation for openstencils window says, "Opens a stencil window
that shows the masters in the document." So it appears you are right.
All I was trying to do was have the drawing control opened with a
specified stencil that would not be editable. The only thing that
appeared to control editability of stencils was the AllowEditing
property; BUT this is only applicable to window objects. But when I
said openEx(.....), I am talking about a stencil document. So I needed
the window that that document was in. Thats where the "Set
vsoStencilWindow = vsoTVAstencil.OpenStencilWindow" came in. from the
sme "openstencilswindow" documentation "objRet A Window object
that represents the opened window."

Not sure how or why it works, but it is working like a charm at the
moment.

I am still confused as to what these windows, document, and
applications objects really are and how to work correctly with them.
 
S

Siva

We are in the process of porting our project from Visio 2003 to Visio 2007.
We are getting "Requested operation is presently disabled." in
OpenStencilWindow method.
It is a dotnet windows application developed using C#. How to solve this.
Please help
 
G

gunslingor

I think I got a similar message. I couldn't find sufficient informatio
as to the correct way to open stencils. I think some of th
documentation is misleading. This is the code that worked for me:

Path = CurrentProject.Path()
Stencil1_Name = "___NAME__"
Stencil_Path = Path & "\Visio Stencils\" & Stencil1_Name

' Load the stencil we want
Set vsoTVAstencil = vsoDocs.OpenEx(Stencil_Path, visOpenDocked)
' Show the stencil window
Set vsoStencilWindow = vsoTVAstencil.OpenStencilWindow
vsoStencilWindow.AllowEditing = Fals
 
P

Paul Herber

We are in the process of porting our project from Visio 2003 to Visio 2007.
We are getting "Requested operation is presently disabled." in
OpenStencilWindow method.
It is a dotnet windows application developed using C#. How to solve this.

Is that a question or a statement?
If it's a question then Visio is probably in the wrong mode for this
operation, for instance, the C# application has put Visio into a
different edit mode, group edit, text edit or something.
It could be that the C# application has asked Visio to do something
and hasn't given Visio a chance to do it yet.
 
P

Paul Herber

I think I got a similar message. I couldn't find sufficient information
as to the correct way to open stencils. I think some of the
documentation is misleading. This is the code that worked for me:

Path = CurrentProject.Path()
Stencil1_Name = "___NAME__"
Stencil_Path = Path & "\Visio Stencils\" & Stencil1_Name

' Load the stencil we want
Set vsoTVAstencil = vsoDocs.OpenEx(Stencil_Path, visOpenDocked)
' Show the stencil window
Set vsoStencilWindow = vsoTVAstencil.OpenStencilWindow
vsoStencilWindow.AllowEditing = False

Why are you going back to this OpenStencilWindow again?
OpenStencilWindow is for the Document Stencil only. Leave it alone,
especially don't set the AllowEditing to false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top