Detecting Template Load

R

rdanielwells

I am trying to detect when a document has been created using the sam
method as the TutorialAddin Project of the Lesson 2 of the Visio SDK.
The project uses the function:


Code
-------------------
Private Function IsManagedTutorialTemplate( _
ByVal currentDocument As Document) As Boolean
If CBool(currentDocument.DocumentSheet.SectionExists( _
CShort(VisSectionIndices.visSectionUser), 0)) _
Then
If CBool(currentDocument.DocumentSheet.CellExistsU( _
TEMPLATE_USER_CELL, 0)) Then
MsgBox("cell exists")
Return True
Else
MsgBox("cell doesn't exist")
End If
Else
MsgBox("section doesn't exist")
End If
Return False
End Functio
-------------------


where TEMPLATE_USER_CELL is the const string "User.IsManagedTutorial".
This seems to work perfectly for the example, however when I change thi
string to "User.MyApplication" and add the same named property to th
"User-Defined Cells" section of the document shapesheet for m
template, this function no longer detects the cell.

I believe I may be adding this cell to the wrong section? as I canno
find any property named "User.IsManagedTutorial" in the documen
shapesheet for the Managed Tutorial template file (or any new documen
created with the template) that comes with the lesson 2 project.

Does anyone know where the User.IsManagedTutorial cell is placed in th
example?

Thanks in Advanc
 
A

Al Edlund

Is it safe to assume that you added the persistent events to your template
(as I remember I got burned by that).
al
 
R

rdanielwells

Indeed I didn't - but I'm not quite sure what you're talking about.
Would you mind to describe this task in more detail? I'm an ASP.NE
programmer - this application is my first time working with COMs an
Visio

Thanks so much
 
D

David Parker

The event is Application.DocumentCreated, and this is normally used to
trigger a QueueMarkerEvent by a Persistent Event in the template document
that is focused at your solution by using arguments. See the Visio SDK...
 
A

Al Edlund

if you open the sample template and then go to tools => addons => sdk =>
tools => persistent events, you should get an idea of what I was referring
to

al
 
H

Heidi Munson [MSFT]

There are two approaches for this. The managed code to tutorial uses one of
them and the rest of the SDK samples use the other one. They are some
advantages and disadvantages to both. In most cases however either method
works just fine.

The managed code tutorial listens to the DocumentCreated event on the
Application object. This event fires whenever a new document is added
(create new file based on your template, create new file based a any Visio
template or when user create a copy of an existing document). In its
DocumentCreated Event handler the manage code tutorial checks for a user
cell in the document sheet to see the document being created is based on its
template. Users who try to mimic this often have trouble finding the
document sheet and end up modifying the page sheet of the first page
instead. The window > "show shapeSheet" menu item shows the shape sheet for
the page sheet. One way to get the documents sheet is to view the drawing
explorer window (available on the view menu). In the drawing explorer
sub-window right click on the top node (node text will be the path to your
document if its saved or the caption of the drawing window if its not). In
the right mouse menu, select the "show shapesheet" item.

The other approach which is used by the rest of the SDK samples is to add a
persisted event for the DocumentCreate Event. The persisted event will only
be triggered when a new document is created from a file that based on
document that contains the persisted event . Persisted events can be used
to call add-ons. If you're building an COM add-in you can get around this
by using the QueueMarkerEvent add-on, providing meaningful argument string
for that add-on, listen to marker event in the your add-in and in your
marker event handler parse marker string to determine what caused it. If
you need to listen to marker events for other reasons this can be a good
approach. Marker events will fire to your add-in later than the
DocumentCreated event . Look at the VB.Net flowchart sample for example of
how this works. You can see the persisted events in the persisted event
tool included in the SDK. This is the approach Al is talking about below.

-Heidi
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights


Al Edlund said:
if you open the sample template and then go to tools => addons => sdk =>
tools => persistent events, you should get an idea of what I was referring
to

al
 
R

rdanielwells

Thanks to everyone who replied so promptly. Heidi solved my proble
when she described how to access the Document ShapeSheet.

Thanks so much!
Da
 
A

Al Edlund

Heidi,
Thanks for the feedback,
al
Heidi Munson said:
There are two approaches for this. The managed code to tutorial uses one
of
them and the rest of the SDK samples use the other one. They are some
advantages and disadvantages to both. In most cases however either method
works just fine.

The managed code tutorial listens to the DocumentCreated event on the
Application object. This event fires whenever a new document is added
(create new file based on your template, create new file based a any Visio
template or when user create a copy of an existing document). In its
DocumentCreated Event handler the manage code tutorial checks for a user
cell in the document sheet to see the document being created is based on
its
template. Users who try to mimic this often have trouble finding the
document sheet and end up modifying the page sheet of the first page
instead. The window > "show shapeSheet" menu item shows the shape sheet
for
the page sheet. One way to get the documents sheet is to view the drawing
explorer window (available on the view menu). In the drawing explorer
sub-window right click on the top node (node text will be the path to your
document if its saved or the caption of the drawing window if its not).
In
the right mouse menu, select the "show shapesheet" item.

The other approach which is used by the rest of the SDK samples is to add
a
persisted event for the DocumentCreate Event. The persisted event will
only
be triggered when a new document is created from a file that based on
document that contains the persisted event . Persisted events can be used
to call add-ons. If you're building an COM add-in you can get around
this
by using the QueueMarkerEvent add-on, providing meaningful argument string
for that add-on, listen to marker event in the your add-in and in your
marker event handler parse marker string to determine what caused it. If
you need to listen to marker events for other reasons this can be a good
approach. Marker events will fire to your add-in later than the
DocumentCreated event . Look at the VB.Net flowchart sample for example
of
how this works. You can see the persisted events in the persisted event
tool included in the SDK. This is the approach Al is talking about
below.

-Heidi
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights
 

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