.NET

.NET

Reply
Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 1 of 6 (184 Views)
Accepted Solution

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

184 Views, 5 Replies
05-23-2014 10:10 AM

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

Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 2 of 6 (176 Views)

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

05-23-2014 11:24 AM in reply to: cjacobi

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

Valued Mentor
Gary_J_Orr
Posts: 314
Registered: ‎09-23-2008
Message 3 of 6 (154 Views)

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

05-26-2014 07:01 AM in reply to: cjacobi
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)
Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 4 of 6 (129 Views)

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

05-27-2014 05:47 AM in reply to: Gary_J_Orr

Thanks so much Gary,

 

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

 

cj

Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 5 of 6 (92 Views)

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

06-02-2014 01:29 PM in reply to: cjacobi

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

Valued Mentor
Gary_J_Orr
Posts: 314
Registered: ‎09-23-2008
Message 6 of 6 (85 Views)

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

06-02-2014 03:37 PM in reply to: cjacobi
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)
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.