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

How to extract attributes(text) from blocks with C# .NET

1 REPLY 1
Reply
Message 1 of 2
Anonymous
3250 Views, 1 Reply

How to extract attributes(text) from blocks with C# .NET

Hi dear friends

I'm trying to write a simple program which it can open the DWG file and read the text inside a block,

until now the software can open the AutoCAD software but I dont know how to access through the block attributes and text,


Autodesk.AutoCAD.Interop.AcadApplication app = null;
Autodesk.AutoCAD.Interop.AcadDocument doc;
Autodesk.AutoCAD.Interop.Common.AcadModelSpace modelspace;

try
{
string inFileName = "C:\\Users\\Paul\\Desktop\\drawing1.dwg";
app = new Autodesk.AutoCAD.Interop.AcadApplication();
doc = app.Documents.Open(inFileName, true, string.Empty);
modelspace = doc.ModelSpace;

foreach (Autodesk.AutoCAD.Interop.Common.AcadEntity myCadEntity in doc.ModelSpace) {
if (myCadEntity is AcadBlockReference)
{
if (myCadEntity.EntityType.ToString() == "7")
{//blocks
MessageBox.Show(myCadEntity.ToString());
MessageBox.Show("this is a block, now its time to read the atrributes inside");
}

}

}



..................

Any help is greatly appreciated,

Maz
1 REPLY 1
Message 2 of 2
chiefbraincloud
in reply to: Anonymous

You'll need to cast myCadEntity into an AcadBlockReference. Then you can check the myBref.HasAttributes property, and call the myBref.GetAttributes Function, which returns a Variant(Object) array of AcadAttributeReference's, which you can loop through.

You could also save some trouble by making a selection set which is filtered to only have block references with attributes.
Then you could do:
dim atts() as object
For Each Bref as AcadBlockReference in mySelectionSet
atts = Bref.GetAttributes
For Each AtRef as AcadAttributeReference in atts
'Do whatever you need to do
Next AtRef
Next Bref

Sorry, I use VB, but you should get the idea.
Dave O.                                                                  Sig-Logos32.png

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