DropManyLinkedU - addin for visio [RESOLVED]

Started by rezance, December 14, 2012, 02:52:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rezance

I am working on my diploma work. The goal is to create addin in visio that should be able to load data from access and vizualize them. I am working in Visual Studio 2010.
I have problem with one sub (the most important), which should take data from visio.datarecordset a draw them on active page.

i tried do it this way http://msdn.microsoft.com/en-us/library/office/ff765214.aspx
My version looks like this:
    Private Sub DrawDataset()
        Dim avarObjects(0 To 2) As Object
        Dim adblXYs(0 To 5) As Double
        Dim alngDataRowIDs(0 To 2) As Long
        Dim alngShapeIDs() As Long
        Dim vsoDataRecordset As Visio.DataRecordset
        Dim intRecordesetCount As Integer
        Dim lngReturned As Long
        Dim intCounter As Integer

        intRecordesetCount = pjVis.Application.ActiveDocument.DataRecordsets.Count
        vsoDataRecordset = pjVis.Application.ActiveDocument.DataRecordsets(intRecordesetCount)

        adblXYs(0) = 2
        adblXYs(1) = 2
        adblXYs(2) = 4
        adblXYs(3) = 4
        adblXYs(4) = 6
        adblXYs(5) = 6

        alngDataRowIDs(0) = 1
        alngDataRowIDs(1) = 2
        alngDataRowIDs(2) = 3


        pjVis.Application.ActivePage.DropManyLinkedU(ObjectsToInstance:=appVis.Documents("BASIC_M.VSS").Masters.ItemU("Rectangle"), XYs:=adblXYs, DataRecordsetID:=1, DataRowIDs:=alngDataRowIDs, ApplyDataGraphicAfterLink:=False, ShapeIDs:=alngShapeIDs)

    End Sub

but it doesnt work. Error looks like:
IvalidCastException was unhandled by user code
Unable to cast COM object of type 'Microsoft.Office.Interop.Visio.MasterClass' to class type 'System.Array'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

I think that there is some problem with arrays conversion or ..but iam newbie

I have also try DropLinked, and it works, but DropManyLinkedU is better for my purpose.
pjVis.Application.ActivePage.DropLinked(appVis.Documents("BASIC_M.VSS").Masters.ItemU("Rectangle"), 1, 1, 1, 1, True)
I have also try those codes above in visio development enviroment in VBa and its works, but i want use Visual Studio.

aledlund

ObjectToInstance is required to be an array and you are only applying a single master (appVis.Documents("BASIC_M.VSS").Masters.ItemU("Rectangle")), thus an improper instantiation. You didn't initialize and fill avarObjects.
al

rezance

#2
thx, i found that misteak right now,...but i have another problem. ObjectToInstance should be array of variants... but Variant arent supported in vb.net or?... when i type Dim avarObjects(0 To 2) As Variant, editor change it to Object automatically
there comes error
Specified array was not of the expected type.

aledlund

I'd suggest you download the v2010 sdk. There are vb.net examples on dropping arrays that use the same general format of dropmanylinked.
http://www.microsoft.com/en-us/download/details.aspx?id=12365
al

rezance

#4
Dim avarObjects(0 To 2) As Object
        Dim adblXYs(0 To 5) As Double
        Dim alngDataRowIDs(0 To 2) As Integer
        Dim alngShapeIDs() As integer
        Dim vsoDataRecordset As Visio.DataRecordset
        Dim intRecordsetCount As Integer

        intRecordsetCount = pjVis.DataRecordsets.Count
        vsoDataRecordset = pjVis.DataRecordsets(intRecordsetCount)

        avarObjects(0) = appVis.Documents("BASIC_M.VSS").Masters.ItemU("Rectangle")
        avarObjects(1) = appVis.Documents("BASIC_M.VSS").Masters.ItemU("Rectangle")
        avarObjects(2) = appVis.Documents("BASIC_M.VSS").Masters.ItemU("Rectangle")


        adblXYs(0) = 2
        adblXYs(1) = 2
        adblXYs(2) = 4
        adblXYs(3) = 4
        adblXYs(4) = 6
        adblXYs(5) = 6

        alngDataRowIDs(0) = 1
        alngDataRowIDs(1) = 2
        alngDataRowIDs(2) = 3



pjVis.Application.ActivePage.DropManyLinkedU(avarObjects, XYs:=adblXYs, DataRecordsetID:=vsoDataRecordset.ID, DataRowIDs:=alngDataRowIDs, ApplyDataGraphicAfterLink:=False, ShapeIDs:=alngShapeIDs)

This works if anyone needs it.

This examplehttp://msdn.microsoft.com/en-us/library/office/ff765214.aspx is in VBA, so to convert this code to VB.net we need to realize that:
VB6/VBA data type Variant isnot supported in  VB.Net, we need to use Object
VB6/VBA data type Long is data type Integer in VB.Net
Thx for help

source http://msdn.microsoft.com/en-US/library/7f5ztkz3%28v=vs.80%29.aspx