Struggling with understanding how "hasfields" works. Got a big jump with a post from "through the interface" but can't seem to get the info I need. The drawing has a title block with attributes. One of the attributes is a field associated with a layout tab. There are multiple layout tabs in the drawing.
This is what I have so far, but the function "FindObjectid" is not returning anything.
Dim obj As DBObject = tr.GetObject(arId, OpenMode.ForRead) Dim ar As AttributeReference = TryCast(obj, AttributeReference) If ar IsNot Nothing Then 'Check to see if the attribute is referenced to a field If Not ar.HasFields Then ' ... to see whether it has ' the tag we're after TagName = ar.Tag.ToUpper() TagValue = ar.TextString Else ' Open the extension dictionary Dim extDict As DBDictionary = DirectCast(tr.GetObject(ar.ExtensionDictionary, OpenMode.ForRead), DBDictionary) Const fldDictName As String = "ACAD_FIELD" Const fldEntryName As String = "TEXT" ' Get the field dictionary If extDict.Contains(fldDictName) Then Dim fldDictId As ObjectId = extDict.GetAt(fldDictName) If fldDictId <> ObjectId.Null Then Dim fldDict As DBDictionary = DirectCast(tr.GetObject(fldDictId, OpenMode.ForRead), DBDictionary) ' Get the field itself If fldDict.Contains(fldEntryName) Then Dim fldId As ObjectId = fldDict.GetAt(fldEntryName) If fldId <> ObjectId.Null Then obj = tr.GetObject(fldId, OpenMode.ForRead) Dim fld As Field = TryCast(obj, Field) If fld IsNot Nothing Then '********************************************** ' And finally get the string ' including the field codes Dim fldCode As String = fld.GetFieldCode() ed.WriteMessage(vbLf & "Field code: " & fldCode) ' Loop, using our helper function ' to find the object references Do Dim objId As ObjectId fldCode = FindObjectId(fldCode, objId) If fldCode <> "" Then ' Print the ObjectId ed.WriteMessage(vbLf & "Found Object ID: " & objId.ToString()) obj = tr.GetObject(objId, OpenMode.ForRead) ' ... and the type of the object ed.WriteMessage(", which is an object of type " & obj.[GetType]().ToString()) End If Loop While fldCode <> "" '************************************************ End If End If End If End If End If End If
Public Shared Function FindObjectId(text As String, ByRef objId As ObjectId) As String Const prefix As String = "%<\_ObjId " Const suffix As String = ">%" ' Find the location of the prefix string Dim preLoc As Integer = text.IndexOf(prefix) If preLoc > 0 Then ' Find the location of the ID itself Dim idLoc As Integer = preLoc + prefix.Length ' Get the remaining string Dim remains As String = text.Substring(idLoc) ' Find the location of the suffix Dim sufLoc As Integer = remains.IndexOf(suffix) ' Extract the ID string and get the ObjectId Dim id As String = remains.Remove(sufLoc) objId = New ObjectId(Convert.ToInt32(id)) ' Return the remainder, to allow extraction ' of any remaining IDs Return remains.Substring(sufLoc + suffix.Length) Else objId = ObjectId.Null Return "" End If End Function
Any help would be greatly appreciated. Having a hard time understanding how the linked fields work.
thanks
Solved! Go to Solution.
Solved by Gary_J_Orr. Go to Solution.
A bit more info.... getfieldcode returns differently depending on the type of object that the block attribute is linked to.
If the attribute is linked to the viewport, the Field Code looks like this that contains the objID, and "FindObjectId" works
Field code: \AcObjProp Object(%<\_ObjId 8796087842208>%).CustomScale \f "1:%lu2%ct1%qf2816"
If the attribute is linked to the layout tab, the Field Code looks like this and NO objID. so that is why the "FindObjectId" function is not working
Field code: \AcVar ctab
So how do I get the objectID of the associated layoutTab?
I have three layouts each layout has a block in paperspace with an attribute linked to the layout tab name.
cj
Thanks so much Gary,
I will give that a try. Hopefully I can get that figured out.
cj