I'm not sure how to trap the events at the stencil from within an AddIn. I
thought that when an AddIn is loaded, it has control over all open document
windows, including the .vss stencil files.
Inside of the Connect.Onconnection I have the following code:
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array
custom)
{
vsoApplication =
(Microsoft.Office.Interop.Visio.Application)application;
vsoApplication.Documents.Open(@"C:\Documents and
Settings\wep85069\My Documents\test.vsd");
vsoApplication.Documents.OpenEx(@"C:\Documents and
Settings\wep85069\My Documents\My Shapes\Vision.vss",
(short)VisOpenSaveArgs.visOpenRW + (short)VisOpenSaveArgs.visOpenDocked);
addInInstance = addInInst;
// Listen to the marker events.
EventList applicationEventList = vsoApplication.EventList;
markerEvent =
applicationEventList.AddAdvise((short)VisEventCodes.visEvtApp +
(short)VisEventCodes.visEvtMarker, applicationEventSink, "", "");
shapeAddedEvent =
applicationEventList.AddAdvise((short)(-(int)VisEventCodes.visEvtAdd) +
(short)VisEventCodes.visEvtShape, applicationEventSink, "", "");
documentAddedEvent =
applicationEventList.AddAdvise((short)(-(int)VisEventCodes.visEvtAdd) +
(short)VisEventCodes.visEvtDoc, applicationEventSink, "", "");
masterAddedEvent =
applicationEventList.AddAdvise((short)(-(int)VisEventCodes.visEvtAdd) +
(short)VisEventCodes.visEvtMaster, applicationEventSink, "", "");
enterScopeEvent =
applicationEventList.AddAdvise((short)VisEventCodes.visEvtCodeEnterScope,
applicationEventSink, "", "");
selectionAddedEvent =
applicationEventList.AddAdvise((short)VisEventCodes.visEvtCodeSelAdded,
applicationEventSink, "", "");
documentChangedEvent =
applicationEventList.AddAdvise((short)VisEventCodes.visEvtMod +
(short)VisEventCodes.visEvtDoc, applicationEventSink, "", "");
}
and then inside the EventSink.IVisEventProc.VisEventProc I have the following:
object IVisEventProc.VisEventProc(short eventCode, object source,
int eventID, int eventSeqNum, object subject, object moreInfo)
{
Shape shapeSubject = (Shape)subject;
try
{
// Determine which event fired from the Event Code.
switch (eventCode)
{
case (short)(-(int)VisEventCodes.visEvtAdd) +
(int)VisEventCodes.visEvtShape:
System.Windows.Forms.MessageBox.Show("Shape added to
page.");
break;
case (short)(-(int)VisEventCodes.visEvtAdd) +
(int)VisEventCodes.visEvtMaster:
System.Windows.Forms.MessageBox.Show("Master added
to stencil.");
break;
case (int)VisEventCodes.visEvtApp +
(short)VisEventCodes.visEvtMarker:
System.Windows.Forms.MessageBox.Show("Marker event
fired.");
break;
case (short)VisEventCodes.visEvtCodeEnterScope:
System.Windows.Forms.MessageBox.Show("Enter Scope
event fired.");
break;
case (short)(-(int)VisEventCodes.visEvtAdd) +
(int)VisEventCodes.visEvtDoc:
System.Windows.Forms.MessageBox.Show("Enter
DocumentAdded event.");
break;
case (short)VisEventCodes.visEvtCodeSelAdded:
System.Windows.Forms.MessageBox.Show("Enter
SelectionAdded event.");
break;
case (short)VisEventCodes.visEvtMod +
(short)VisEventCodes.visEvtDoc:
System.Windows.Forms.MessageBox.Show("Enter
DocumentChanged event.");
break;
}
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine(err.Message);
}
return null;
}
The only event that seems to be being reliably trapped is the ShapeAdded
event. What am I doing wrong?