Related Tag Extraction

I need to write a routine that will extract tags similar to the built in report function but through VBA macro.

 

For each tagset I have 2 definitions.  These tags have no base element attached to them so its not as easy i would hope.  I need to extract all the tags in the file from a specific tagset and report definition 1 & definition 2 in a tab or comma seperated file almost exactly as the built in function does it.  How can this be achieved?

 

Thanks.

Parents
  • Unknown said:
    These tags have no base element attached to them

    Tags are attached to host elements, not the other way around. One host element may have multiple tags. A tag can have only one host element. Here's an article about tags and VBA that may help.

    Tag Set Definitions

    Unknown said:
    I need to extract all the tags in the file from a specific tagset and report definition 1 & definition 2

    Use the TagSet and TagDefinition objects.

    Const TagSetName As String = "sobe1izard"
    Dim oTagSet As TagSet
    Set oTagSet = ActiveDesignFile.TagsSets (TagSetName)
    Debug.Print "Found tag set '" & oTagSet.Name & "'"
    Dim oDefinitions() As TagDefinition
    oDefinitions = oTagSet.TagDefinitions
    Dim oDefinition As TagDefinition
    For Each oDefinition In oDefinitions
         Select Case oDefinition.TagType
         Case msdTagTypeCharacter
          ComposeTagDef oDefinition, "Text"
         Case msdTagTypeShortInteger, msdTagTypeLongInteger
          ComposeTagDef oDefinition, "Integer"
         Case msdTagTypeDouble
          ComposeTagDef oDefinition, "Real"
         End Select
    Next oDefinition
    Function ComposeTagDef (ByRef oTagDef As TagDefinition, _
         ByVal typeName As String ) As String
         Dim s As String
         s = oTagDef.TagSetName & ":" & oTagDef.Name
         ComposeTagDef = s & " type: " & typeName
    End Function

    If you search the web you will find plenty of articles about writing CSV and other text files using VBA. In fact, we've an example on our web site: text file writer.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • I may have mistyped the issues.  I need the values extracted from the tags.  WHat i have is a Bill of Material that has two definitions per tag set, ASSY and QTY.  I need to extract the QTY and ASSY in one row, then move down to the next instince of that same tag set and do the same thing through the file.  I can extract tag sets and definitions all day long but these tags are orphans so i cannot simply grab its base elements and get the associated tags.  The tag template function does exactly what i need but the issue is formatting.  I need to match my specific formatting and be able to do batch processing much easier.  

  • I'm confused.  What do you mean by "The tags are orphans"?  That there is no associated element?  I thought once you delete the element, the tag is also deleted.  That's what the MicroStation help file also states.

  • I don't fully understand how you can have orphan tags either but maybe something like this would work:

    Sub exportTags()
        Dim fFile As Long: fFile = FreeFile
        Open "C:\Quantities.csv" For Output As #fFile
        Dim oScan As ElementEnumerator
        Set oScan = ActiveModelReference.Scan
        Do While oScan.MoveNext
            If (oScan.Current.HasAnyTags) Then
                Dim oTags() As TagElement
                Dim tag As Integer
                oTags = oScan.Current.GetTags()
                For tag = LBound(oTags) To UBound(oTags)
                    If oTags(tag).TagDefinitionName = "ASSY" Then
                        Print #fFile, oTags(tag).Value
                    End If
                Next Tag
            End If
        Loop
    End Sub


    Mike

Reply
  • I don't fully understand how you can have orphan tags either but maybe something like this would work:

    Sub exportTags()
        Dim fFile As Long: fFile = FreeFile
        Open "C:\Quantities.csv" For Output As #fFile
        Dim oScan As ElementEnumerator
        Set oScan = ActiveModelReference.Scan
        Do While oScan.MoveNext
            If (oScan.Current.HasAnyTags) Then
                Dim oTags() As TagElement
                Dim tag As Integer
                oTags = oScan.Current.GetTags()
                For tag = LBound(oTags) To UBound(oTags)
                    If oTags(tag).TagDefinitionName = "ASSY" Then
                        Print #fFile, oTags(tag).Value
                    End If
                Next Tag
            End If
        Loop
    End Sub


    Mike

Children
No Data