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

Blocks and Block attributes on Autocad 2006

3 REPLIES 3
Reply
Message 1 of 4
Steve-o
333 Views, 3 Replies

Blocks and Block attributes on Autocad 2006

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
3 REPLIES 3
Message 2 of 4
Mikko
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?
Message 3 of 4
Mikko
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
Message 4 of 4
Rudedog
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.

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