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

reading AttributeDefinition

15 REPLIES 15
Reply
Message 1 of 16
Anonymous
758 Views, 15 Replies

reading AttributeDefinition

hi all,
I have a block that have two attributes( description and amount) the user can fill these in when inserting the block. i can read the Tag and the Prompt, but when i read the textstring it return nothing.
anyone an idea, how do I read the value of the tag.

thanks in advance
15 REPLIES 15
Message 2 of 16
Anonymous
in reply to: Anonymous

Be sure you are getting the AttributeReference objects from the
BlockReference object's GetAttributes method.

--
R. Robert Bell


wrote in message news:5244546@discussion.autodesk.com...
hi all,
I have a block that have two attributes( description and amount) the user
can fill these in when inserting the block. i can read the Tag and the
Prompt, but when i read the textstring it return nothing.
anyone an idea, how do I read the value of the tag.

thanks in advance
Message 3 of 16
Anonymous
in reply to: Anonymous

Huh ?

What "GetAttributes" method ????

--
http://www.caddzone.com

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

"R. Robert Bell" wrote in message news:5244711@discussion.autodesk.com...
Be sure you are getting the AttributeReference objects from the
BlockReference object's GetAttributes method.

--
R. Robert Bell


wrote in message news:5244546@discussion.autodesk.com...
hi all,
I have a block that have two attributes( description and amount) the user
can fill these in when inserting the block. i can read the Tag and the
Prompt, but when i read the textstring it return nothing.
anyone an idea, how do I read the value of the tag.

thanks in advance
Message 4 of 16
Anonymous
in reply to: Anonymous

You're confusing AttributeDefinition and AttributeReference.

The former appears in the block definition and acts as
a template for creation of the latter, which appears in
each reference/insertion of the block (BlockReference).

You need read the TextString property of the attribute
reference (AttributeReference class). There is one of
these for each attribute, which is accessed via the
AttributeCollection property of the owning BlockReference.

--
http://www.caddzone.com

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

wrote in message news:5244546@discussion.autodesk.com...
hi all,
I have a block that have two attributes( description and amount) the user can fill these in when inserting the block. i can read the Tag and the Prompt, but when i read the textstring it return nothing.
anyone an idea, how do I read the value of the tag.

thanks in advance
Message 5 of 16
Anonymous
in reply to: Anonymous

Sorry, I missed what group I was in.

--
R. Robert Bell


"Tony Tanzillo" wrote in message
news:5244769@discussion.autodesk.com...
Huh ?

What "GetAttributes" method ????

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
Message 6 of 16
Anonymous
in reply to: Anonymous

hi,
so i need to read the attrbuteReference, do you have a sample code VB.net or C#.
now i'm doing this

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

Dim attref As AttributeReference = New AttributeReference()
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
'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)
attref.SetPropertiesFrom(attDef)
attref.Tag = attDef.Tag


ed.WriteMessage("Block tag = " + attDef.Tag + ControlChars.Lf)
ed.WriteMessage("Tag String = " + " " + attDef.Prompt + ControlChars.Lf)

ed.WriteMessage("Tag String = " + " " + attDef.TextString + ControlChars.Lf)
End If
Next

the above code just give me the Tag and prompt, thanks
Message 7 of 16
Anonymous
in reply to: Anonymous

hi,
ops srry it didn't work, if you have any examble pls send them to me

Message was edited by: pipo2007 Message was edited by: pipo2007
Message 8 of 16
Anonymous
in reply to: Anonymous

"R. Robert Bell" wrote

>> >> What "GetAttributes" method ????

>> Sorry, I missed what group I was in.

In that case, you have the wrong class names
('BlockReference' and 'AttributeReference'), which
are the proper names of the managed wrapper
classes, but don't exist in ActiveX/VBA.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
Message 9 of 16
Anonymous
in reply to: Anonymous

hi Tony,
I get the AttrbuteRefrence of a block, and I get the Tag and value that are constants of the block.
but only two tag's that are must be giving when you insert a block, the description tag and the amount tag, I cant get the value of these tags!!
Message 10 of 16
Anonymous
in reply to: Anonymous

You can't expect much help without posting
your code.

--
http://www.caddzone.com

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

wrote in message news:5247127@discussion.autodesk.com...
hi Tony,
I get the AttrbuteRefrence of a block, and I get the Tag and value that are constants of the block.
but only two tag's that are must be giving when you insert a block, the description tag and the amount tag, I cant get the value of these tags!!
Message 11 of 16
Anonymous
in reply to: Anonymous

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
Message 12 of 16
Anonymous
in reply to: Anonymous

and this is the block that i use, and i want to get the attribute out of it.
thanks
Message 13 of 16
Anonymous
in reply to: Anonymous

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
Message 14 of 16
Mikko
in reply to: Anonymous

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()
Message 15 of 16
Anonymous
in reply to: Anonymous

hi Tony,
I get it now thank you very much.
Message 16 of 16
Anonymous
in reply to: Anonymous

thanks
I solved the problem know with the same methoud you'r using

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