Invalid Sheet Identifier

R

rdanielwells

Whenever a new shape is dropped onto the page, the id is added t
ShapeIDs (a sorted list) with EquipmentID as the key:


Code
-------------------
ShapeIDs.Add(oEquipment(x).EquipmentID, currentShape.ID)
DebugWrite("Added EquipmentID=" & oEquipment(x).EquipmentID & " shapeid=" & currentShape.ID
-------------------



After all equipment shapes have been added to the document, th
equipment is to be connected together. To get the ToShape an
FromShape, the following code is used:


Code
-------------------
currentShape = GetShapeItem(currentPage.Shapes, _
CInt(ShapeIDs.Item(Pigtails(X).End1ConnectedToPort.EquipmentID))
-------------------




Code
-------------------
Public Function GetShapeItem(ByVal theShapes As Shapes, _
ByVal ID As Object) As Shape
DebugWrite("GetShapeItem: ID.Type = " & ID.GetType.ToString)
DebugWrite("GetShapeItem theShapes.Count = " & theShapes.Count)
Dim returnValue As Shape
Try
returnValue = theShapes.Item(ID)
If returnValue Is Nothing Then
DebugWrite("GetShapeItem: returnValue is Nothing")
Else
DebugWrite("GetShapeItem: returnValue.id=" & _
returnValue.ID)
End If
Catch err As COMException
' Shape was not found. Ignore the error.
DebugWrite("GetShapeItem: " & err.Message)
End Try
Return returnValue
End Functio
-------------------


For simplicity's sake, in this case a pigtail is a set of tw
equipmentID's which are to be connected together. All pigtails onl
reference pieces of equipment that have already been dropped on th
page, however only two of the pieces of equipment (one pigtail) ar
found by the GetShapeItem function above.

Below is the sample debug output:

12/8/2005 4:04:00 PM :: Added EquipmentID=3209 shapeid=1
12/8/2005 4:04:00 PM :: Added EquipmentID=3210 shapeid=3
12/8/2005 4:04:00 PM :: Added EquipmentID=3211 shapeid=5
12/8/2005 4:04:00 PM :: Added EquipmentID=3516 shapeid=7
12/8/2005 4:04:00 PM :: Added EquipmentID=3517 shapeid=9
12/8/2005 4:04:00 PM :: Added EquipmentID=3684 shapeid=11
12/8/2005 4:04:00 PM :: Added EquipmentID=3689 shapeid=13
12/8/2005 4:04:00 PM :: Added EquipmentID=3691 shapeid=15
12/8/2005 4:04:00 PM :: Added EquipmentID=3694 shapeid=17
12/8/2005 4:04:01 PM :: Added EquipmentID=3695 shapeid=19
12/8/2005 4:04:01 PM :: Added EquipmentID=3703 shapeid=21
12/8/2005 4:04:01 PM :: Added EquipmentID=3709 shapeid=23
12/8/2005 4:04:01 PM :: Added EquipmentID=3712 shapeid=25
12/8/2005 4:04:01 PM :: Added EquipmentID=3713 shapeid=27
12/8/2005 4:04:01 PM :: Added EquipmentID=3714 shapeid=29
12/8/2005 4:04:01 PM :: Added EquipmentID=3724 shapeid=31
12/8/2005 4:04:01 PM :: Added EquipmentID=3728 shapeid=33
12/8/2005 4:04:01 PM :: Added EquipmentID=3732 shapeid=35
12/8/2005 4:04:01 PM :: Added EquipmentID=3734 shapeid=37
12/8/2005 4:04:01 PM :: Added EquipmentID=3737 shapeid=39
12/8/2005 4:04:01 PM :: Added EquipmentID=3738 shapeid=41
12/8/2005 4:04:01 PM :: Added EquipmentID=3739 shapeid=43
12/8/2005 4:04:01 PM :: Added EquipmentID=3741 shapeid=45
12/8/2005 4:04:01 PM :: Added EquipmentID=3747 shapeid=47
12/8/2005 4:04:01 PM :: Added EquipmentID=3753 shapeid=49
12/8/2005 4:04:01 PM :: shapeids.count=25
12/8/2005 4:04:01 PM :: pigtails.length = 9
12/8/2005 4:04:01 PM :: currentpage.shapes.count = 25
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3714, Got 29
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: From Shape is Nothing
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3734, Got 37
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: From Shape is Nothing
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3732, Got 35
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: From Shape is Nothing
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3732, Got 35
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: From Shape is Nothing
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3732, Got 35
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: From Shape is Nothing
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3728, Got 33
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: From Shape is Nothing
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem: returnValue.id=5
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3210, Got 3
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end2 EquipmentID=3747, Got 47
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: To Shape is Nothing
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 25
12/8/2005 4:04:01 PM :: GetShapeItem: returnValue.id=5
_12/8/2005_4:04:01_PM_::_Looking_For_end1_EquipmentID=3210,__Got_3
12/8/2005_4:04:01_PM_::_GetShapeItem_theShapes.Count_=_25
12/8/2005_4:04:01_PM_::_GetShapeItem:_returnValue.id=49
12/8/2005_4:04:01_PM_::_Looking_For_end2_EquipmentID=3712,__Got_25
12/8/2005_4:04:01_PM_::_connectWithDynamicGlueAndConnector_Called_
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 26
12/8/2005 4:04:01 PM :: GetShapeItem: returnValue.id=9
12/8/2005 4:04:01 PM :: Looking For end1 EquipmentID=3211, Got 5
12/8/2005 4:04:01 PM :: GetShapeItem theShapes.Count = 26
12/8/2005 4:04:01 PM :: GetShapeItem:

Invalid sheet identifier.
12/8/2005 4:04:01 PM :: Looking For end2 EquipmentID=3728, Got 33
12/8/2005 4:04:01 PM :: ConnectEquipmentPorts: To Shape is Nothing

I'm most interested in the "Invalid Sheet Identifier" error. I've
underlined the section that *kind of* works

Any help is greatly appreciated!
Dan
 
M

Mark Nelson [MS]

Do you happen to use grouping in your drawing? One reason why Visio can't
find shapes would be that they have been grouped. When a group is created,
a new shape is added to the Page.Shapes collection and the grouped shapes
are moved from the Page.Shapes collection to the GroupShape.Shapes
collection. To get at any shape on the page, you need to recurse through
groups.

If you work with the UniqueID property of a shape instead of the ID
property, there is a way to retrieve shapes without recursing through
groups. UniqueID generates and returns a GUID that can be stored as a
string. When requesting the shape again from the Page object, place an
asterisk before the GUID to tell Visio to find this shape somewhere on the
page. For instance: Shape = Page.Shapes.Item("*" + ShapeGUID).

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

rdanielwells

Thanks Mark,

The items are not grouped and I think I've solved the problem usin
returnValue = theShapes._ItemFromID(ID)_ instead of Item(ID) in th
GetShapeItem function. This works, but would it be a better practic
to use the UniqueID property?

Thanks in advance,
Da
 
D

Diver@home

Do you happen to use grouping in your drawing? One reason why Visio can't
find shapes would be that they have been grouped. When a group is created,
a new shape is added to the Page.Shapes collection and the grouped shapes
are moved from the Page.Shapes collection to the GroupShape.Shapes
collection. To get at any shape on the page, you need to recurse through
groups.

If you work with the UniqueID property of a shape instead of the ID
property, there is a way to retrieve shapes without recursing through
groups. UniqueID generates and returns a GUID that can be stored as a
string. When requesting the shape again from the Page object, place an
asterisk before the GUID to tell Visio to find this shape somewhere on the
page. For instance: Shape = Page.Shapes.Item("*" + ShapeGUID).

In C++, shapeid is unique only within the current page, it repeats
when a new page is created. My solution was to save the shapepointer
by key. The key is sheetindex+id. When I need to manipulate the
shape, I first find it in the table and then use the shapepointer as
required.
 
M

Mark Nelson [MS]

I believe that Item uses the index of the shape in the collection while
ItemFromID uses the ID of the shape.

This may be suitable for your needs. Keep in mind that shape IDs are not
unique from page to page. They are also not continuous since deleted shapes
will leave gaps in the sequence. Also if you are working with groups, you
will need to consider the issues from my previous post.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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