I am not sure about your exact problem. But this Visio SDK code is
perfectly working. Also see, its code. It is going to open stencil
document before using page.drop. I think in your case, stencil is not
opened. Just try this code to drop shape on your page instead of your own.
Thanks
Shahzad Godil
Karachi-Pakistan
MSN Messenger : (e-mail address removed)
'// DropMaster.vb
'// <copyright>Copyright (c) Microsoft Corporation. All rights reserved.
'// </copyright>
'// <summary>This module demonstrates how to drop a master onto a page at a
'// specific location.</summary>
Imports System
Namespace Microsoft.Samples.Visio.VBNet
Module DropMaster
'// <summary>This function 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 Function DropMasterOnPage( _
ByVal pageToDrop As Microsoft.Office.Interop.Visio.Page, _
ByVal masterNameU As String, _
ByVal stencilName As String, _
ByVal pinX As Integer, _
ByVal pinY As Integer, _
ByVal units As Object) As Microsoft.Office.Interop.Visio.Shape
Dim visioApplication As
Microsoft.Office.Interop.Visio.Application
Dim visioDocuments As Microsoft.Office.Interop.Visio.Documents
Dim stencil As Microsoft.Office.Interop.Visio.Document
Dim masterInStencil As Microsoft.Office.Interop.Visio.Master
Dim droppedShape As Microsoft.Office.Interop.Visio.Shape =
Nothing
Dim cellPinX As Microsoft.Office.Interop.Visio.Cell
Dim cellPinY As Microsoft.Office.Interop.Visio.Cell
Dim pinXInternal As Double
Dim pinYInternal As Double
visioApplication = CType(pageToDrop.Application, _
Microsoft.Office.Interop.Visio.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) Then
Throw New System.ArgumentNullException("masterNameU", _
"Zero length string input.")
End If
If (stencilName.Length() = 0) Then
Throw New System.ArgumentNullException("stencilName", _
"Zero length string input.")
End If
' Find the stencil in the Documents collection by name.
visioDocuments = visioApplication.Documents
Try
stencil = visioDocuments.Item(stencilName)
Catch
' The stencil is not in the collection; open
' it as a docked stencil.
stencil = visioDocuments.OpenEx(stencilName, _
CShort(Microsoft.Office.Interop.Visio. _
VisOpenSaveArgs.visOpenDocked))
End Try
' Get a master from the stencil by its universal name.
masterInStencil = stencil.Masters.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.CellsSRC( _
CShort(Microsoft.Office.Interop.Visio. _
VisSectionIndices.visSectionObject), _
CShort(Microsoft.Office.Interop.Visio. _
VisRowIndices.visRowXFormOut), _
CShort(Microsoft.Office.Interop.Visio. _
VisCellIndices.visXFormPinX))
cellPinY = droppedShape.CellsSRC( _
CShort(Microsoft.Office.Interop.Visio. _
VisSectionIndices.visSectionObject), _
CShort(Microsoft.Office.Interop.Visio. _
VisRowIndices.visRowXFormOut), _
CShort(Microsoft.Office.Interop.Visio. _
VisCellIndices.visXFormPinY))
cellPinX.Result(units) = pinX
cellPinY.Result(units) = pinY
Catch err As Exception
droppedShape = Nothing
System.Diagnostics.Debug.WriteLine(err.Message)
End Try
Return droppedShape
End Function
End Module
End Namespace