Morning Jon,
I realised that I chose the wrong option with intellisense choosing .TagDefinitionName instead of .TagSetName though regardless my code still would not work anyway.
I tried using your suggested function but I was not successful no doubt due to my own incorrect invokation or perhaps it may be due a non-standard declaration which was not stated in the original post. As you know there has been some issues reported over the years accessing tags from an external process (typically from the office family products such as Excel and Access). The previous version of my macro relied on using oScanCriteria.IncludeType msdElementTypeTag however I changed to oScanCriteria.IncludeType msdElementTypeLine as I read you had advised before. My original declarations specified Dim oTag() As TagElement however this causes Excel to crash. I began searching through many threads on tags and read another user discovered that they had to change the declartion to Dim oTag As Variant. I did the same and I am able to retrieve all the valid tag values. I since realised this morning that the answer to my problem is quite simple. I already had the line :
Dim vTagValue As Variant
and this works just fine so I realised all I needed to do to achieve the desired filtering was:
Set oEnumerator = oDGN.Models(sModel).Scan(oScanCriteria) While oEnumerator.MoveNext Set oEl = oEnumerator.Current If oEl.IsValid Then Debug.Print "Element type " & CStr(oEl.Type) & " ID " & DLongToString(oEl.ID) If oEl.IsGraphical Then If Not oEl.IsHidden Then If (oEl.HasAnyTags) Then bTagFound = True Debug.Print "Found valid Tags" Dim i As Integer Dim vTagValue As Variant Dim sTagSetName As String Dim sTagDefinitionName As String Dim lTagDefsRow As Long oTags = oEl.GetTags For i = LBound(oTags) To UBound(oTags) vTagValue = oTags(i).Value sTagSetName = oTags(i).TagSetName sTagDefinitionName = oTags(i).TagDefinitionName Select Case sTagSetName Case ShtTagDefs.Cells(1, 1) lTagDefsRow = 1 TagCriteria sModel, vTagValue, sTagDefinitionName, lTagDefsRow Case ShtTagDefs.Cells(2, 1) lTagDefsRow = 2 TagCriteria sModel, vTagValue, sTagDefinitionName, lTagDefsRow Case ShtTagDefs.Cells(3, 1) lTagDefsRow = 3 TagCriteria sModel, vTagValue, sTagDefinitionName, lTagDefsRow Case ShtTagDefs.Cells(4, 1) lTagDefsRow = 4 TagCriteria sModel, vTagValue, sTagDefinitionName, lTagDefsRow Case ShtTagDefs.Cells(5, 1) lTagDefsRow = 5 TagCriteria sModel, vTagValue, sTagDefinitionName, lTagDefsRow End Select Debug.Print "Tag [" & CStr(i) & "] = " & vTagValue Next i Else Debug.Print "No valid tags found" End If Else Debug.Print "Not visible" End If Else Debug.Print "Not graphical" End If Else Debug.Print "Not valid" End If Wend
and
Public Sub TagCriteria(sModel As String, vTagValue As Variant, sTagDefinitionName As String, lTagDefsRow As Long) 'write Model name ShtDrawings.Cells(CurRow, 2) = sModel 'Write Drawing Number If sTagDefinitionName = (ShtTagDefs.Cells(lTagDefsRow, 2)) Then ShtDrawings.Cells(CurRow, 3) = vTagValue End If
etc....