Hello Guys!
I'm new to autocad and visual studio. I'm trying to build a simple aplication that uses com interop with autocad. It creates an acad aplication. uses it to open a file, get the blocks and finally its attributes.
My problem is that on the attributes, i'm not able to get the value of the attribute. When i try att.textvalue I get and empty string. Can anyone help me on this one?
Thanks!!
Here is my very simple code:
Autodesk.AutoCAD.Interop.AcadDocument doc = _acad.Documents.Open(dwgpath, true, string.Empty);
Autodesk.AutoCAD.Interop.Common.AcadDatabase myDB = doc.Database;
Autodesk.AutoCAD.Interop.Common.AcadBlocks blocks = myDB.Blocks;
Autodesk.AutoCAD.Interop.Common.AcadBlock selblk = null;
foreach (Autodesk.AutoCAD.Interop.Common.AcadBlock myblock in blocks)
{
String myBlkName = myblock.Name.ToString();
if (String.Compare(myBlkName.ToLower(), "BOTTOMBLK_2") == 0)
{
selblk = myblock;
}
}
if (selblk == null)
{
return;
}
foreach (Autodesk.AutoCAD.Interop.Common.AcadEntity ent in selblk)
{
Autodesk.AutoCAD.Interop.Common.AcadAttribute att = ent as Autodesk.AutoCAD.Interop.Common.AcadAttribute;
if (att != null)
{
MessageBox.Show("EntityName = " + att.TextString);
MessageBox.Show("EntityName = " + att.TagString);
/*
MessageBox.Show("EntityName = " + att.TagString +
"\n Entity Prompt String = " + att.PromptString +
"\n Entity Text String = " + att.TextString.ToCharArray() +
"\n Entity Text String = " + att.TextString);
*/
}
}
If you're trying to find attributes that belong to a particular block reference, you'll need to first get the block reference. You're more likely to get help in the VBA or .NET discussion groups, as this group is for C++.