MS Sample Code Master Drop

J

Jean Dophin

I am using vs2003 and visio 2003 sdk. I created a new project from the
wizard. Then I copied and pasted the master drop code sample to the
generated code. Anyway, it compiled fine, but it does not show anything on
the screen. Even when I disabled all the macros. Even the message box does
not show. I don't know why, any suggestion? see the code below
==================================
namespace VisioProject1 {
using System;
using System.Runtime.InteropServices;
using Extensibility;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Visio;

/// <summary>This class implements the IDTExtensibility2 interface in order
/// to connect to Microsoft Visio as a COM add-in.</summary>
[GuidAttribute("7ac11288-f428-4a12-9e8c-8bf3f2f6fa45"),
ProgId("VisioProject1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2 {

private Microsoft.Office.Interop.Visio.Application vsoApplication;
private object addInInstance;

/// <summary>This constructor intentionally left blank.</summary>
public Connect() {

// No initialization required.
}

/// <summary>This method implements the OnAddInsUpdate method of the
/// IDTExtensibility2 interface. It receives notification that the
/// collection of add-ins has changed.</summary>
/// <param name="custom">Array of parameters that are host application
/// specific</param>
public void OnAddInsUpdate(ref System.Array custom) {
}

/// <summary>This method implements the OnBeginShutdown method of the
/// IDTExtensibility2 interface. It receives notification that the host
/// application is being unloaded.</summary>
/// <param name="custom">Array of parameters that are host application
/// specific</param>
public void OnBeginShutdown(ref System.Array custom) {
}

/// <summary>This method implements the OnConnection method of the
/// IDTExtensibility2 interface. It receives notification that the
/// add-in is being loaded.</summary>
/// <param name="application">Root object of the host application
/// </param>
/// <param name="connectMode">Describes how the add-in is being loaded
/// </param>
/// <param name="addInInst">Object representing this add-in</param>
/// <param name="custom">Array of parameters that are host application
/// specific.</param>
public void OnConnection(
object application,
Extensibility.ext_ConnectMode connectMode,
object addInInst,
ref System.Array custom) {

vsoApplication = (Microsoft.Office.Interop.Visio.Application)
application;
addInInstance = addInInst;

System.Windows.Forms.MessageBox.Show("VisioProject1 connected.",
"VisioProject1 add-in");
}

/// <summary>This procedure is called when the add-in is about to be
/// unloaded. The add-in will be unloaded when Microsoft Visio is
/// shutting down or when a user has removed or deselected the add-in
/// from the "COM Add-Ins" dialog.</summary>
/// <param name="removeMode">Indicator telling the add-in why Visio is
/// disconnecting </param>
/// <param name="custom">Array of additional parameters for the add-in,
/// not used in this case</param>
public void OnDisconnection(
Extensibility.ext_DisconnectMode disconnectMode,
ref System.Array custom) {

}

/// <summary>This method implements the OnStartupComplete method of the
/// IDTExtensibility2 interface. It receives notification that the host
/// application has completed loading.</summary>
/// <param name="custom">Array of parameters that are host application
/// specific</param>
public void OnStartupComplete(ref System.Array custom)
{
System.Windows.Forms.MessageBox.Show("My message");
DropMaster myClass = new DropMaster();
myClass.DropMasterOnPage(vsoApplication.ActivePage, "Triangle", "Basic
Shapes", 2, 2, Microsoft.Office.Interop.Visio.VisUnitCodes.visInches);
}

public class DropMaster
{

/// <summary>This constructor is intentionally left blank.</summary>
public DropMaster()
{

// No initialization is required.
}

/// <summary>This method looks for the document with the name specified
/// in stencilName in the Documents collection and, if the document is
/// not in the collection, opens it as a docked stencil. It then gets
/// the master, using its universal name masterNameU, and drops it on
/// the specified page.</summary>
/// <param name="pageToDrop">Page where the master will be dropped
/// </param>
/// <param name="masterNameU">Universal name of the master in the
/// stencil</param>
/// <param name="stencilName">Name of the stencil from which the master
/// is to be found</param>
/// <param name="pinX">X-coordinate of the pin in the specified units
/// </param>
/// <param name="pinY">Y-coordinate of the pin in the specified units
/// </param>
/// <param name="units">Units used by pinX and pinY</param>
/// <returns>Shape that was created by dropping the master on the page
/// indicated by the page parameter</returns>
public Microsoft.Office.Interop.Visio.Shape DropMasterOnPage(
Microsoft.Office.Interop.Visio.Page pageToDrop,
string masterNameU,
string stencilName,
int pinX,
int pinY,
object units)
{

Microsoft.Office.Interop.Visio.Application visioApplication;
Microsoft.Office.Interop.Visio.Documents visioDocuments;
Microsoft.Office.Interop.Visio.Document stencil;
Microsoft.Office.Interop.Visio.Master masterInStencil;
Microsoft.Office.Interop.Visio.Shape droppedShape = null;
Microsoft.Office.Interop.Visio.Cell cellPinX;
Microsoft.Office.Interop.Visio.Cell cellPinY;
double pinXInternal;
double pinYInternal;

visioApplication = (Microsoft.Office.Interop.Visio.Application)
pageToDrop.Application;

try
{

// Verify that all incoming string parameters are not of zero
// length, except for the ones that have default values as ""
// and the output parameters.
if (masterNameU.Length == 0)
{

throw new System.ArgumentNullException("nasterNameU",
"Zero length string input.");
}

if (stencilName.Length == 0)
{

throw new System.ArgumentNullException("stencilName",
"Zero length string input.");
}

// Find the stencil in the Documents collection by name.
visioDocuments = visioApplication.Documents;

try
{

stencil = visioDocuments[stencilName];
}
catch
{

// The stencil is not in the collection; open it as a
// docked stencil.
stencil = visioDocuments.OpenEx(stencilName,
(short)Microsoft.Office.Interop.Visio.
VisOpenSaveArgs.visOpenDocked);
}

// Get a master from the stencil by its universal name.
masterInStencil =
stencil.Masters.get_ItemU(masterNameU);

// Convert the PinX and PinY into internal units.
pinXInternal = visioApplication.ConvertResult(pinX, units,
Microsoft.Office.Interop.Visio.VisUnitCodes.visInches);
pinYInternal = visioApplication.ConvertResult(pinY, units,
Microsoft.Office.Interop.Visio.VisUnitCodes.visInches);

// Drop the master on the page that is passed in.
// Set the PinX and PinY using pinXInternal and
// pinYInternal respectively.
droppedShape = pageToDrop.Drop(
masterInStencil, pinXInternal, pinYInternal);

// Update the units for PinX and PinY of the shape.
cellPinX = droppedShape.get_CellsSRC(
(short)Microsoft.Office.Interop.Visio.
VisSectionIndices.visSectionObject,
(short)Microsoft.Office.Interop.Visio.
VisRowIndices.visRowXFormOut,
(short)Microsoft.Office.Interop.Visio.
VisCellIndices.visXFormPinX);

cellPinY = droppedShape.get_CellsSRC(
(short)Microsoft.Office.Interop.Visio.
VisSectionIndices.visSectionObject,
(short)Microsoft.Office.Interop.Visio.
VisRowIndices.visRowXFormOut,
(short)Microsoft.Office.Interop.Visio.
VisCellIndices.visXFormPinY);

cellPinX.set_Result(units, pinX);
cellPinY.set_Result(units, pinY);
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine (err.Message);
}

return droppedShape;
}
}

}

}
 
N

Nikolay Belyh

Jean Dophin:
I am using vs2003 and visio 2003 sdk. I created a new project from the
wizard. Then I copied and pasted the master drop code sample to the
generated code. Anyway, it compiled fine, but it does not show anything on
the screen. Even when I disabled all the macros. Even the message box does

It seems that your problem is completely unrelated to dropping a
master.
Try creating new project from scratch (using wizard).
Run this new project. Does it show the message the box now?

If not, maybe you have disabled all add-ins events in visio? You can
check the value of this setting in visio options (it is NOT macro
setting, it is add-in's setting). Also, maybe your add-in (or rather
mscoree.dll) was placed by visio to "Disabled items". Try clearing
this list.

Kind regards.
 
J

Jean Dophin

What you said probably true, since I did not see the message box. Since I am
not in that computer today, I will try your suggestion on moday.

Thank you
 
J

Jean Dophin

I tried your suggestion, but it did not work. I am using visio 2003 and set
the security level to the lowest. I couldn't find the disable list, but I
went to tools->macro and saw a list. I don't know if this is the one you are
talking about. When I created an .exe applicaiton, I can see the dialog when
I ran it. But, when I created a com application, even when I checked allow
visio to load the add in when visio is loaded, I still don't see the message
box. I event set a breakpoint on it, still did not see. Maybe something
wrong; any suggestion?
 
P

Paul Herber

I tried your suggestion, but it did not work. I am using visio 2003 and set
the security level to the lowest. I couldn't find the disable list,

The Disabled Items list can be found at menu
Help -> About and look for the button at the bottom.
 
J

Jean Dophin

When I disabled it, visio came and quickly exit abruptly. I don't know why.
I will continue troubleshoot; maybe something wrong somewhere.
 
J

Jean Dophin

Right now, when I disable the option from the help menu, then visio just quit
after opening. Then when I ran the program back, it came up with a dialog
box says:

"visio experienced a seriosu error ...... would you like to disable this add
in ... ti reactuvate this add in click about .... yes/no"

basically it, I think something maybe wrong with the mscoree.dll

i a using vs 2003 sp1
 
P

Paul Herber

er, what have you disabled ?

When I disabled it, visio came and quickly exit abruptly. I don't know why.
I will continue troubleshoot; maybe something wrong somewhere.
 

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