.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get attribute value when it is a field to a layout tab

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
coralie.jacobi
707 Views, 5 Replies

get attribute value when it is a field to a layout tab

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

5 REPLIES 5
Message 2 of 6

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

Message 3 of 6
Gary_J_Orr
in reply to: coralie.jacobi

In a way you have answered your own question...
before trying to pass the field code string to your "helper function" test the string.
if it calles for the \AcVar ctab then, instead of parsing the string for an object ID you will need to step back up to the insert containing the attribute and determine which tab it was inserted into.with the property:
OwnerID

-G
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 4 of 6
coralie.jacobi
in reply to: Gary_J_Orr

Thanks so much Gary,

 

I will give that a try. Hopefully I can get that figured out.

 

cj

Message 5 of 6

Thanks Gary...got it working like a charm!!

Message 6 of 6
Gary_J_Orr
in reply to: coralie.jacobi

No problem
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost