.NET

Reply
Contributor
tracer123
Posts: 15
Registered: ‎08-05-2008
Message 1 of 5 (428 Views)

AcadAttribute vs AcadAttributeReference

428 Views, 4 Replies
03-01-2012 03:36 PM

What is the difference between the two? I am running some code to pull the .TextString from the attribute but if I pull it from an AcadAttribute I usually just get a '-' and if I pull it from an AcadAttributeReference I get the correct thing.

 

Currently I'm looping through the entire model spaces entity collection to find blocks and then attributes in that block. Is there an easier way? Can one use selection sets?

ADN Support Specialist
Balaji_Ram
Posts: 715
Registered: ‎03-21-2011
Message 2 of 5 (412 Views)

Re: AcadAttribute vs AcadAttributeReference

03-02-2012 03:24 AM in reply to: tracer123

Hi,

 

For example, Block Definition is a template and Block reference is an instance created using that template.

On similar lines, we have an attribute definition and an attribute reference.

For this reason, when you extract the text info from the attribute definition, it returns nothing because it is only a template.

Only the instances will have valid values.

 

Regarding your other query : You will need to iterate through the model space to find the block references. Selection API do not work on entities not visible in the editor, but a zoom all before you use it may help.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Contributor
tracer123
Posts: 15
Registered: ‎08-05-2008
Message 3 of 5 (396 Views)

Re: AcadAttribute vs AcadAttributeReference

03-02-2012 07:37 AM in reply to: tracer123

Thanks for the reply. That clears up my first question. For the second, one I am still a bit confused. For example I have this:

 

For Each entity As AcadEntity In modelSpace

If TypeOf entity Is AcadBlockReference Then

Dim block = DirectCast(entity, AcadBlockReference)

'//loop through the attributes

End If Next

 Can this be made any faster? Enumerating all the entities in an ACAD drawing can take some time.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 5 (384 Views)

Re: AcadAttribute vs AcadAttributeReference

03-02-2012 10:11 AM in reply to: tracer123

If you're using Interop so you can try this quick code scratch,

just you don't forget to change the drawing name before.

See result in the command line

{code}

         Public Sub InteropDemo()

        Dim miss As Object = Type.Missing

        Dim AcadApp As AcadApplication = New Autodesk.AutoCAD.Interop.AcadApplication()

        AcadApp.Visible = True

        AcadApp.WindowState = AcWindowState.acMax

        Dim adoc As AcadDocument = AcadApp.Documents.Open("c:\test\MyDrawing.dwg")

        adoc.Application.ZoomExtents()

        Dim util As AcadUtility = adoc.Utility

        Dim oSset As AcadSelectionSet = adoc.SelectionSets.Add("mySset")
        '  get current tab name
        Dim layout As Object = adoc.GetVariable("ctab")
        '  using filter
        '  important: use short[] for dxf codes:
        Dim dxfcode As Short() = New Short() {0, 66, 410}
        '  use object[] for dxf values:
        Dim dxfvalue As Object() = New Object() {"insert", 1, layout}
        '  select all attributed block instances in the current tab
        oSset.Select(AcSelect.acSelectionSetAll, miss, miss, DirectCast(dxfcode, Object), DirectCast(dxfvalue, Object))
        '  send  message to the command line:
        adoc.Utility.Prompt(String.Format(vbLf & "Selected: {0} objects", oSset.Count))

        For Each ent As AcadEntity In oSset
            '  important: cast if AcadEntity is AcadBlockReference
            Dim oblkRef As AcadBlockReference = TryCast(ent, AcadBlockReference)

            If oblkRef IsNot Nothing Then
                '  send  message to the command line:
                util.Prompt(String.Format(vbLf & "Block Name:" & vbTab & "{0}", oblkRef.Name))

                Dim attVar As Object = oblkRef.GetAttributes()
                '  important: cast if object is array
                If attVar.GetType().IsArray Then

                    Dim attColl As Object() = TryCast(DirectCast(attVar, Object()), Object())

                    If attColl IsNot Nothing Then

                        For i As Integer = attColl.GetLowerBound(0) To attColl.GetUpperBound(0)
                            '  important: cast if object is AcadAttributeReference
                            Dim attRef As AcadAttributeReference = TryCast(attColl(i), AcadAttributeReference)

                            If attRef IsNot Nothing Then
                                '  send  message to the command line:
                                util.Prompt(String.Format(vbLf & "Tag:   {0}" & vbTab & "Value:   {1}", attRef.TagString, attRef.TextString))

                            End If
                        Next
                    End If
                End If
            End If
        Next

    End Sub

{code}

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
tracer123
Posts: 15
Registered: ‎08-05-2008
Message 5 of 5 (379 Views)

Re: AcadAttribute vs AcadAttributeReference

03-02-2012 12:27 PM in reply to: tracer123

Thanks! I'll dissect your code and see how it turns out.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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