.NET

Reply
Active Member
8 Posts
0 Kudos
Registered: ‎07-21-2006
Post 11 of 16

Re: reading AttributeDefinition

07-25-2006 05:29 AM in reply to: pipo2007
hi Tony,
sorry this is my code.
_
Public Sub Countblok()

Try
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
'CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
'CType(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead), BlockTableRecord)
Dim id As ObjectId
Dim idnr As Int32

idnr = 0
For Each id In btr
Dim ent As Entity = trans.GetObject(id, OpenMode.ForRead, False)
'CType(trans.GetObject(id, OpenMode.ForRead, False), Entity)
If TypeOf ent Is BlockReference Then
Dim saEmployeeList(-1) As String

Dim Blk As BlockReference = CType(ent, BlockReference)
Dim br As BlockTableRecord = CType(trans.GetObject(Blk.BlockTableRecord, OpenMode.ForRead, False), BlockTableRecord)
blockname = br.Name
Dim idreffrence As ObjectId

idreffrence = Blk.AttributeCollection.Item(0)

'ListBlocks(id, saEmployeeList, blockname)
Dim sEmployeeData As String
Dim empBtr As BlockTableRecord = trans.GetObject(bt(blockname), OpenMode.ForRead)

ac = Blk.AttributeCollection
Dim entid As ObjectId
For Each entid In empBtr

Dim entt As Entity = trans.GetObject(entid, OpenMode.ForRead, False)
If TypeOf entt Is AttributeDefinition Then
Dim attDef As AttributeDefinition = CType(entt, AttributeDefinition)
Dim attRef As AttributeReference = New AttributeReference()
attRef.SetAttributeFromBlock(attDef, Blk.BlockTransform)

attRef.SetPropertiesFrom(attDef)
'attref.Tag = attDef.Tag


ed.WriteMessage("attref tag = " + attRef.Tag + ControlChars.Lf)
ed.WriteMessage("attdef tag = " + " " + attDef.Tag + ControlChars.Lf)

ed.WriteMessage("Tag value = " + " " + attRef.TextString + ControlChars.Lf)
End If
Next
'
' blocks(i) = blockname
i = i + 1

End Sub
Active Member
8 Posts
0 Kudos
Registered: ‎07-21-2006
Post 12 of 16

Re: reading AttributeDefinition

07-25-2006 05:33 AM in reply to: pipo2007
and this is the block that i use, and i want to get the attribute out of it.
thanks
*Tony Tanzillo
Post 13 of 16

Re: reading AttributeDefinition

07-25-2006 06:56 AM in reply to: pipo2007
Please go back and read my previous posts.

It explains what you need to do, but you code
does not do that.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5247195@discussion.autodesk.com...
hi Tony,
sorry this is my code.
_
Public Sub Countblok()

Try
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
'CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
'CType(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead), BlockTableRecord)
Dim id As ObjectId
Dim idnr As Int32

idnr = 0
For Each id In btr
Dim ent As Entity = trans.GetObject(id, OpenMode.ForRead, False)
'CType(trans.GetObject(id, OpenMode.ForRead, False), Entity)
If TypeOf ent Is BlockReference Then
Dim saEmployeeList(-1) As String

Dim Blk As BlockReference = CType(ent, BlockReference)
Dim br As BlockTableRecord = CType(trans.GetObject(Blk.BlockTableRecord, OpenMode.ForRead, False), BlockTableRecord)
blockname = br.Name
Dim idreffrence As ObjectId

idreffrence = Blk.AttributeCollection.Item(0)

'ListBlocks(id, saEmployeeList, blockname)
Dim sEmployeeData As String
Dim empBtr As BlockTableRecord = trans.GetObject(bt(blockname), OpenMode.ForRead)

ac = Blk.AttributeCollection
Dim entid As ObjectId
For Each entid In empBtr

Dim entt As Entity = trans.GetObject(entid, OpenMode.ForRead, False)
If TypeOf entt Is AttributeDefinition Then
Dim attDef As AttributeDefinition = CType(entt, AttributeDefinition)
Dim attRef As AttributeReference = New AttributeReference()
attRef.SetAttributeFromBlock(attDef, Blk.BlockTransform)

attRef.SetPropertiesFrom(attDef)
'attref.Tag = attDef.Tag


ed.WriteMessage("attref tag = " + attRef.Tag + ControlChars.Lf)
ed.WriteMessage("attdef tag = " + " " + attDef.Tag + ControlChars.Lf)

ed.WriteMessage("Tag value = " + " " + attRef.TextString + ControlChars.Lf)
End If
Next
'
' blocks(i) = blockname
i = i + 1

End Sub
Distinguished Contributor
212 Posts
6 Kudos
Registered: ‎10-03-2003
Post 14 of 16

Re: reading AttributeDefinition

07-25-2006 08:02 AM in reply to: pipo2007
Is this what your looking for?

Dim db As Database = HostApplicationServices.WorkingDatabase
Dim t As Transaction = db.TransactionManager.StartTransaction()
Dim blkname As String = "E6534-11"
Dim bt As BlockTable = CType(t.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = CType(t.GetObject(bt(blkname), OpenMode.ForRead), BlockTableRecord)
Dim oic As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)
Dim br As BlockReference = CType(t.GetObject(oic(0), OpenMode.ForRead), BlockReference)
Dim ac As Integer = br.AttributeCollection.Count
Dim i As Integer
For i = 0 To ac - 1
Dim ar As AttributeReference
ar = CType(t.GetObject(br.AttributeCollection(i), OpenMode.ForRead), AttributeReference)
MsgBox(ar.TextString)
Next
t.Commit()
t.Dispose()
Active Member
8 Posts
0 Kudos
Registered: ‎07-21-2006
Post 15 of 16

Re: reading AttributeDefinition

07-26-2006 04:12 AM in reply to: pipo2007
hi Tony,
I get it now thank you very much.
Active Member
8 Posts
0 Kudos
Registered: ‎07-21-2006
Post 16 of 16

Re: reading AttributeDefinition

07-28-2006 08:08 AM in reply to: pipo2007
thanks
I solved the problem know with the same methoud you'r using
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!