Selection set error; key not found

Selection set error; key not found

Anonymous
Not applicable
441 Views
4 Replies
Message 1 of 5

Selection set error; key not found

Anonymous
Not applicable
Hi everyone, I am trying to make a selection set of external references by using block collection. It does add external reference to selection set but only on alternate instances and causes an error "-2145386476; Key not found" on alternate instances. Any suggestion would be appreciated. Here is the routine I am using to create and populate the selection set. Thanks.
Private Sub SetXRefFlName()
Dim oSS As AcadSelectionSet
Dim intCode(0 To 1) As Integer
Dim strCodeVal(0 To 1) As Variant
Dim grpCode As Variant
Dim grpCodeVal As Variant
Dim oBlk As AcadBlock
Dim oXRef As AcadExternalReference
Dim xFlPath As String
Dim xFlName As String

On Error Resume Next
'Create a file manager object
Call CreateFileMgr
'Set SS object
Set oSS = ThisDrawing.SelectionSets.Item("SSXRef")
If oSS Is Nothing Then
Set oSS = ThisDrawing.SelectionSets.Add("SSXRef")
If oSS Is Nothing Then
MsgBox "unable to add selection set 'SSXRef'"
Exit Sub
End If
End If

'Set a code and value for a Xref blocks to populate selection set
intCode(0) = 0: strCodeVal(0) = "INSERT"
intCode(1) = 2
'Assign arrays to variant variables
grpCode = intCode
XRFls = ""
For Each oBlk In ThisDrawing.Blocks
If oBlk.IsXRef Then
strCodeVal(1) = oBlk.Name
grpCodeVal = strCodeVal
'Clear XRef selection set
oSS.Clear
'Add all objects on the layar selection set
oSS.Select acSelectionSetAll, , , grpCode, grpCodeVal
If Err Then
MsgBox Err.Number & ", " & Err.Description
Err.Clear
Exit Sub
End If
If oSS.Count > 0 Then
Set oXRef = oSS.Item(0)
xFlPath = oXRef.Path
xFlName = xFlMgr.GetFileName(xFlPath)
If XRFls <> "" Then
XRFls = XRFls & ","
End If
XRFls = XRFls & xFlName
End If
End If
Next
'Delete the XRef selection set
oSS.Delete
MsgBox XRFls
End Sub
0 Likes
442 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Hi,
It seems that the problem could be occuring when you call the CreateFileMgr. Without this code it is difficult to identify the problem. Have you tried making a standard SelectionSet, then looping through it to get the path property? If the block is not an xref then this will cause an error and can therefore be trapped. It all depends on what you want to do with the xrefs once you have collected them, I suppose. Roy.
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Roy, Thanks for your response. I found out what is causing the error "Key not found"? It's the selection set not the CreateFileMgr routine, when I try to get "SSXRef" selection set from selectionsets, if it does not find the "SSXRef" selection set it causes the error and exits the routine before deleting the "SSXRef" selection set, so when I run the routine again, it finds the "SSXRef" selection set that was created in the previous execution, so it does not cause an error and populates "SSXRef" selection set. Thanks, MArshad
0 Likes
Message 4 of 5

Anonymous
Not applicable
Sorry, I miunderstood the question. I thought your routine was finding every other xref in the drawing.


Glad you fixed it though, Well done.
.


Roy
0 Likes
Message 5 of 5

Anonymous
Not applicable
that was meant to be misunderstood. These fingers just can't spell!!!
0 Likes