Reading tags

I have a line element drawn in my design file.  It has a tag whose value is "tel-1-1-001".  The line also has a note that points to the line.  If the line is altered by the user, ie, the start or end point are manually moved, the note will no longer point to the line, so it needs to be moved to the line.  I'm trying to write some code that will:

1) find the line

2) get its tag value

3) find the note with that corresponding text

4) reposition the note so that it points to the line once again.

I'm having no problems with (or do not anticipate having any problems with) steps 1, 3, or 4.  Step 2 has got me stumped though.  I've followed the code found here at la-solutions.  In the code below thisFileModel has been declared as a ModelReference

Dim oScan As ElementEnumerator
Set oScan = thisFileModel.Scan
Do While oScan.MoveNext
    If (oScan.Current.IsGraphical) Then
         Dim oHost As Element
        If (oScan.Current.HasAnyTags) Then
            Set oHost = thisFile.GetElementByID(DLongFromLong(DLongToLong(oScan.Current.ID)))
            Dim oTags() As TagElement
            Dim nTags As Integer
            Dim j As Integer
            Dim vtValue As Variant
            oTags = oHost.GetTags()
            For j = LBound(oTags) To UBound(oTags)
                vtValue = oTags(j).Value
                MsgBox ("Tag[" & CStr(j) & "] = " & CStr(vtValue))
            Next j
        End If
    End If
Loop

 This, however,results in a message box that shows, "Tag[0] = ".  It doesn't show the value of the tag and I don't know why.  Can anyone help?

Parents
  • alternate_exterior:

    I have a line element drawn in my design file.  It has a tag. Step 2 [get its tag value] has got me stumped though.

    Using the scanned element's ID to find the same element seems a little long-winded. Why not do this:

    
    Dim oHost As Element
    If (oScan.Current.HasAnyTags) Then
      Set oHost = oScan.Current
      Dim oTags() As TagElement
      Dim oTag As TagElement
      Dim nTags As Integer
      Dim j As Integer
      Dim vtValue As Variant
      oTags = oHost.GetTags()
      For j = LBound(oTags) To UBound(oTags)
        Set oTag = oTags(j)
        vtValue = oTag.Value
        MsgBox ("Tag[" & oTag.TagSetName & ":" & oTag.TagDefinitionName & "] = " & CStr(vtValue))
      Next j
    End If
    
    

     

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Worked like a charm, Jon.  Thanks a million.

    Using the scanned element's ID to find the same element seems a little long-winded.

    Indeed it was long winded.  Not sure why I didn't just use "Set oHost = oScan.Current" like you suggested.   My brain must have been fried when I wrote that.

    Thanks again!

  • Thanks for the solution pasted on this forum. My requirement is, to read tag values from opened file and paste in separate text file but i am getting error always like object required by using above codes (has any tag etc. line and sometimes no current object). it is compiling but givin object error. plese help.

Reply Children
  • Debugging Remote Code by Telepathy

    Unknown said:
    I am getting error always like object required by using above codes (has any tag etc. line and sometimes no current object). It is compiling but giving object error

    Your question is the same as this: "My car doesn't work. Can you fix it?"

    Just as you can't see my car, we can't see your code. We don't know what error messages you see. You can't test my car, so you can't diagnose what may be wrong with it. We can't see your error messages, so we can't diagnose problems in your code.

    If you want help on this Forum, don't rely on paranormal capabilities in your audience. We can't help if you don't provide useful evidence.

    Tags to Text File Example

    Fortunately for you, we already pubished an example VBA project about Writing Tag data into a Text File.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions