.NET

.NET

Reply
*Expert Elite*
chiefbraincloud
Posts: 752
Registered: ‎02-13-2008
Message 21 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-02-2009 04:45 PM in reply to: myspambox111
That's because the enumerator returned by the AttributeCollection is a System type which does not implement IDisposable, not a SymbolTableEnumerator, which does.



Hard to call something that's not implemented.
Dave O.                                                                  Sig-Logos32.png
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 22 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-02-2009 04:55 PM in reply to: myspambox111


The GetEnumerator method of the BlockTableRecord returns a BlockTableRecordEnumerator which does implement IDisposable.



GetEnumerator is being called on the BlockTableRecord in the examples above not on an AttributeCollection.

Contributor
myspambox111
Posts: 22
Registered: ‎10-07-2008
Message 23 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-02-2009 05:08 PM in reply to: myspambox111
Well, without digressing further guys, can someone please post an example addressing my original question?

I realize I still have things to learn about autocad programming in .NET but I seem to get more understanding from an example containing a few lines of code than an hours worth of reading. It allows me (and others) to see how it works rather than trying to comprehend ambiguous concepts in an API thats lacking a lot of references and resources. I understand that sometimes giving someone the answer right away can be counterproductive, but in the instance of autocad in .net, theres really little else we can rely on than answers from you guru's who have done this full time for years. If you have the answer, please post it. It not only saves the inquirer time, but also those who are seeking the same answers on the forums.
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 24 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-02-2009 07:58 PM in reply to: myspambox111


Just a bit of my 2¢ and having seen an example from ADN ID: TS88193 which applies to AutoCAD® 2007 and AutoCAD® 2008 versions, you will see that they also use as an example:





Dim iEnumerator As IEnumerator = btr.GetEnumerator()

'Try to get the attribute in the block definition

While (iEnumerator.MoveNext())

....





C# or VB both use it. Of course that doesn't have to make it correct, look how well these forums work. Bottom line: Does it work for you? If so run with it and get on with the show.





I've used something like this in the past to read attributes.





<CommandMethod("attRefs")> Public Sub attRefs()

Call GetAttributes("YourBlockName")

End Sub



Private Sub GetAttributes(ByVal NameOfBlock As String)

Dim findThis() As TypedValue = {New TypedValue(0, "INSERT"), New TypedValue(2, NameOfBlock)}

Dim sf = New SelectionFilter(findThis)

Dim psr As PromptSelectionResult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll(sf)

If psr.Status = PromptStatus.OK Then

Using t As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

For Each h As ObjectId In From q As ObjectId In psr.Value.GetObjectIds()

Dim br = CType(t.GetObject(h, OpenMode.ForRead), BlockReference)

For i As Integer = 0 To br.AttributeCollection.Count - 1

Dim ar As AttributeReference = CType(t.GetObject(br.AttributeCollection(i), OpenMode.ForRead), AttributeReference)

MsgBox(ar.TextString)

Next

Next

t.Commit()

End Using

End If

End Sub



Tony, I really would like to see your For Each AttributeReference Next example. I could probably learn even more and somebody might even hire my unemployed a$$ but then we would all miss these lively discussions.

Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 25 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-02-2009 08:21 PM in reply to: myspambox111


That looks like a pretty poor example from ADN given that the GetEnumerator method of BlockTableRecord returns a BlockTableRecordEnumerator type. Although I am making the assumption they have not changed the return type from IEnumerator in 2009.

Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 26 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-02-2009 08:51 PM in reply to: myspambox111
The connection between the examples above that use GetEnumerator and using For Each is as follows.



The code that uses GetEnumerator calls the Current property of the BlockTableRecordEnumerator which returns an ObjectId.



Therefore the For Each approch is as follows.



For Each objEntId as ObjectId in objBTR





Next objEntId
*Tony Tanzillo
Message 27 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-03-2009 12:01 AM in reply to: myspambox111
Wrong.

The object returned by AttributeCollection.GetEnumerator()
most certainly does implement IDisposable.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6116732@discussion.autodesk.com...
That's because the enumerator returned by the AttributeCollection is a
System type which does not implement IDisposable, not a
SymbolTableEnumerator, which does.



Hard to call something that's not implemented.
*Tony Tanzillo
Message 28 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-03-2009 12:01 AM in reply to: myspambox111
Just because you see it in an ADN sample, doesn't make it
correct.

Shame on whomever in ADN approved that.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009
http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6116779@discussion.autodesk.com...

Just a bit of my 2¢ and having seen an example from ADN ID: TS88193 which
applies to AutoCAD® 2007 and AutoCAD® 2008 versions, you will see that they
also use as an example:







Dim iEnumerator As IEnumerator = btr.GetEnumerator()

'Try to get the attribute in the block definition

While (iEnumerator.MoveNext())

....







C# or VB both use it. Of course that doesn't have to make it correct, look
how well these forums work. Bottom line: Does it work for you? If so run
with it and get on with the show.







I've used something like this in the past to read attributes.







Public Sub attRefs()

Call GetAttributes("YourBlockName")

End Sub






Private Sub GetAttributes(ByVal NameOfBlock As String)

Dim findThis() As TypedValue = {New TypedValue(0, "INSERT"), New
TypedValue(2, NameOfBlock)}

Dim sf = New SelectionFilter(findThis)

Dim psr As PromptSelectionResult =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll(sf)

If psr.Status = PromptStatus.OK Then

Using t As Transaction =
HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

For Each h As ObjectId In From q As ObjectId In psr.Value.GetObjectIds()

Dim br = CType(t.GetObject(h, OpenMode.ForRead), BlockReference)

For i As Integer = 0 To br.AttributeCollection.Count - 1

Dim ar As AttributeReference = CType(t.GetObject(br.AttributeCollection(i),
OpenMode.ForRead), AttributeReference)

MsgBox(ar.TextString)

Next

Next

t.Commit()

End Using

End If

End Sub






Tony, I really would like to see your For Each AttributeReference Next
example. I could probably learn even more and somebody might even hire my
unemployed a$$ but then we would all miss these lively discussions.
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 29 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-03-2009 03:58 AM in reply to: myspambox111
Private Sub GetAttributes(ByVal NameOfBlock As String)

Dim findThis() As TypedValue = {New TypedValue(0, "INSERT"), New TypedValue(2, NameOfBlock)}

Dim sf = New SelectionFilter(findThis)

Dim psr As PromptSelectionResult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll(sf)

If psr.Status = PromptStatus.OK Then

Using t As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

For Each h As ObjectId In From q As ObjectId In psr.Value.GetObjectIds()

Dim br = CType(t.GetObject(h, OpenMode.ForRead), BlockReference)

For Each k As ObjectId In br.AttributeCollection

Dim ar As AttributeReference = CType(t.GetObject(k, OpenMode.ForRead), AttributeReference)

MsgBox(ar.TextString)

Next k

Next

t.Commit()

End Using

End If

End Sub



Yes you are correct but it doesn't seem to shorten my code any that I posted earlier. I'm off to Denny's for the free Grand Slam Breakfast. Today only. Later.....
*Paul Richardson
Message 30 of 63 (177 Views)

Re: Trouble getting textstring from attribute definition

02-03-2009 04:12 AM in reply to: myspambox111

you are missing the point - it's not about the
length of the code but not needing

dispose of the object returned by GetEnumerator().
As was pointed out - dispose()

is not called in most code that uses it! Including
my own at one point ~)


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Private
Sub GetAttributes(ByVal NameOfBlock As String)

Dim findThis() As
TypedValue = {New TypedValue(0, "INSERT"), New TypedValue(2,
NameOfBlock)}

Dim sf = New SelectionFilter(findThis)

Dim psr As
PromptSelectionResult =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll(sf)

If
psr.Status = PromptStatus.OK Then

Using t As Transaction =
HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()

For
Each h As ObjectId In From q As ObjectId In
psr.Value.GetObjectIds()

Dim br = CType(t.GetObject(h,
OpenMode.ForRead), BlockReference)

For Each k As ObjectId In
br.AttributeCollection

Dim ar As AttributeReference =
CType(t.GetObject(k, OpenMode.ForRead),
AttributeReference)

MsgBox(ar.TextString)

Next
k

Next

t.Commit()

End Using

End If

End
Sub



Yes you are correct but it doesn't seem to shorten my code
any that I posted earlier. I'm off to Denny's for the free Grand Slam
Breakfast. Today only. Later.....
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.