.NET

Reply
New Member
Posts: 1
Registered: ‎07-13-2005
Message 1 of 4 (145 Views)

Blocks and Block attributes on Autocad 2006

145 Views, 3 Replies
07-13-2005 09:17 AM
Does anyone have an example of how to extract block attribute information (I'm using c#)?

I seem to only be able to get at the *mspace object not any of the actual block references - refer to the following snippet:

//- Get the selection from the user....

//- Loop through each object id
foreach(ObjectId l_oObj in l_oObjs)
{
BlockReference l_oBlkRef = (BlockReference)m_oTransMgr.GetObject(l_oObj,OpenMode.ForRead);

BlockTableRecord l_oBlkTblRec = (BlockTableRecord)m_oTransMgr.GetObject(l_oBlkRef.BlockId,OpenMode.ForRead);

l_oEditor.WriteMessage("Scanning:" + l_oBlkTblRec.Name);
}

Any help would be great!

Thanks in advance,
Steve-o
Distinguished Contributor
Posts: 209
Registered: ‎10-03-2003
Message 2 of 4 (145 Views)

Re: Blocks and Block attributes on Autocad 2006

07-15-2005 05:21 AM in reply to: Steve-o
Did you get an answer? I'm stumped here.

Dim oid As ObjectId() = ss.GetObjectIds
Dim blkid As ObjectId
For Each blkid In oid
Dim br As BlockReference
br = tr.GetObject(blkid, OpenMode.ForRead, True)
Dim btr As BlockTableRecord
btr = tr.GetObject(br.BlockTableRecord(), OpenMode.ForRead, True)
If btr.HasAttributeDefinitions Then
Dim id As ObjectId
For Each id In btr
Dim ent As Entity = tr.GetObject(id, OpenMode.ForWrite, True)
If TypeOf ent Is AttributeDefinition Then
Dim ad As AttributeDefinition
ad = ent
'ed.WriteMessage(vbCrLf + ad.Tag.ToString + vbCrLf)
'ed.WriteMessage(vbCrLf + ad.Prompt.ToString + vbCrLf)
ed.WriteMessage(vbCrLf + ad.TextString + vbCrLf)
End If
Next
End If
Next

Using textstring gives the default value, not the actual string.
How do you get the typed string?
Distinguished Contributor
Posts: 209
Registered: ‎10-03-2003
Message 3 of 4 (145 Views)

Re: Blocks and Block attributes on Autocad 2006

07-16-2005 03:52 AM in reply to: Steve-o
Seemed to have got tangled up for a bit, this works.

Dim br As BlockReference
br = tr.GetObject(blkid, OpenMode.ForRead, True)
Dim ac As AttributeCollection
ac = br.AttributeCollection
If ac.Count > 0 Then
Dim attId As ObjectId
For Each attId In ac
Dim ar As AttributeReference
ar = tr.GetObject(attId, OpenMode.ForRead, False)
ed.WriteMessage(ar.TextString.ToString + vbCrLf)
Next
End If
Distinguished Contributor
Posts: 1,222
Registered: ‎10-14-2004
Message 4 of 4 (145 Views)

Re: Blocks and Block attributes on Autocad 2006

06-27-2007 09:32 AM in reply to: Steve-o
The OP asked for C#. You seem to have VB replies. I can help you out with a C# solution. (Yeah I know old post. I've searching to see if anyone has solved my problem or at least find some clues.) If you still need a sample, I could post a sample or post a link to samples.. I am still looking to how read dynamic block attributes in C#.

Rudedog
"Fooling computers since 1971."

Message was edited by: Rudedog

Just read the above. It's vague. I am wrestling with...
Autodesk.AutoCAD.Interop.Common.IAcadDynamicBlockReferenceProperty
...or am I on the wrong track.

Trying to modify this sample...
http://through-the-interface.typepad.com/through_the_interface/2007/06/creating_a_tabl.html
...to work with dynamic blocks in 2008.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community