How can I get the Shape object by its ID or Name,or NameID in Visio?

Started by urmyfaith, July 30, 2014, 03:06:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

urmyfaith

How can I get the Shape object by its ID or Name,or NameID?



Sub ShapeArray()
    Dim pointSize As Integer
    pointSize = 4
    ReDim mShapeArray(1 To pointSize)
   
    Dim i As Integer
    For i = 1 To pointSize
        Set mShapeArray(i) = ActivePage.DrawRectangle(i - 0.25, i + 0.25, i + 0.25, i - 0.25)
    Next i
   
    'vsoShapes.Item(intCounter).Name   --->  "Sheet.99"
    MsgBox "DrawCompleted!"
   
End Sub


I want  to connect  the two Shapes, which is drawed above, by GlueToPos to method.

vsoCellObj.GlueToPos vso2DShape, 0.5, 0


Is there a way to get the Shape Object by its ID or Name?

like:
vsoShape = getShapeByID("Sheet.16")

Thanks for any help.



Yacine

Hi,
there is something wrong in your concept.
You do already store objects in the mShapeArray, so there is no need to get object from ID.
You can use mShapeArray(1) as the first shape object in your arrray.
For proof try "debug.print mShapeArray(1).ID".

If you intended to store IDs in the array, you should have written:
set shp = ActivePage.DrawRectangle(i - 0.25, i + 0.25, i + 0.25, i - 0.25)
mShapeArray(i) = shp.ID

And only then your request for getting the shape from the ID would make sence.
You'd call:
Set shp = ActivePage.Shapes.ItemFromID(mShapeArray(i))

Here's the code for handling the array as objects:

Sub ShapeArray()
    Dim pointSize As Integer
    pointSize = 4
    ReDim mShapeArray(1 To pointSize)
   
    Dim i As Integer
    For i = 1 To pointSize
        Set mShapeArray(i) = ActivePage.DrawRectangle(i - 0.25, i + 0.25, i + 0.25, i - 0.25)
    Next i
    Call connectShps(mShapeArray(1), mShapeArray(2))
   
End Sub

Sub connectShps(ByVal shp1 As Shape, ByVal shp2 As Shape)

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope("Drop On Page")
    Dim conn As Visio.Shape
    Set conn = Application.ActiveWindow.Page.Drop(Application.ConnectorToolDataObject, 1, 2)
    Dim vsoCell1 As Visio.Cell
    Dim vsoCell2 As Visio.Cell
    Set vsoCell1 = conn.CellsU("BeginX")
    Set vsoCell2 = shp1.CellsSRC(1, 1, 0)
    vsoCell1.GlueTo vsoCell2
    Set vsoCell1 = conn.CellsU("EndX")
    Set vsoCell2 = shp2.CellsSRC(1, 1, 0)
    vsoCell1.GlueTo vsoCell2
    Application.EndUndoScope UndoScopeID1, True

End Sub
Yacine

urmyfaith

Quote from: Yacine on July 30, 2014, 05:45:21 AM

And only then your request for getting the shape from the ID would make sence.
You'd call:
Set shp = ActivePage.Shapes.ItemFromID(mShapeArray(i))


Thanks for your reply.

I have stored the shape object in the array mShapeArray, but if the pointSize is too large, the mShapeArray would consum too much memory.That's why I want to get the Shape by NameID.

Once I stored the Shape's ID , the mShapeArray can be freed .In the later ,When  it is time  to connect  two shapes by GlueToPos Methed, we can get the Shapes by their IDs.    That's what I am thinking about.

Set shp = ActivePage.Shapes.ItemFromID(mShapeArray(i))

is the right  answer to my question.

And thanks for your  detailed reply.