AcadBlockReference not AcadBlock. Here is some example code from AutoCAD's
ActiveX and VBA Developer's Guide. It's in VBA but should be easy to port to
C# if you're using COM Interop.
~tjr
///////////////////////CODE///////////////////////////////////////////
Sub Ch10_GettingAttributes() ' Create the block Dim blockObj As
AcadBlock Dim insertionPnt(0 To 2) As Double insertionPnt(0) = 0
insertionPnt(1) = 0 insertionPnt(2) = 0 Set blockObj =
ThisDrawing.Blocks.Add _ (insertionPnt,
"TESTBLOCK") ' Define the attribute definition Dim attributeObj As
AcadAttribute Dim height As Double Dim mode As Long Dim prompt As
String Dim insertionPoint(0 To 2) As Double Dim tag As String Dim
value As String height = 1# mode = acAttributeModeVerify prompt =
"Attribute Prompt" insertionPoint(0) = 5 insertionPoint(1) = 5
insertionPoint(2) = 0 tag = "Attribute Tag" value = "Attribute Value"
' Create the attribute definition object on the block Set attributeObj =
blockObj.AddAttribute _ (height, mode, prompt, _
insertionPoint, tag, value) ' Insert the block Dim blockRefObj
As AcadBlockReference insertionPnt(0) = 2 insertionPnt(1) = 2
insertionPnt(2) = 0 Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock
_ (insertionPnt, "TESTBLOCK", 1, 1, 1, 0) ZoomAll
' Get the attributes for the block reference Dim varAttributes As Variant
varAttributes = blockRefObj.GetAttributes ' Move the attribute tags
and values into a ' string to be displayed in a Msgbox Dim
strAttributes As String strAttributes = "" Dim I As Integer For I =
LBound(varAttributes) To UBound(varAttributes) strAttributes =
strAttributes + " Tag: " + _ varAttributes(I).TagString
+ vbCrLf + _ " Value: " + varAttributes(I).textString
Next MsgBox "The attributes for blockReference " + _
blockRefObj.Name & " are: " & vbCrLf _ & strAttributes
' Change the value of the attribute ' Note: There is no SetAttributes.
Once you have the ' variant array, you have the objects. ' Changing
them changes the objects in the drawing. varAttributes(0).textString =
"NEW VALUE!" ' Get the attributes again Dim newvarAttributes As
Variant newvarAttributes = blockRefObj.GetAttributes ' Again,
display the tags and values strAttributes = "" For I =
LBound(varAttributes) To UBound(varAttributes) strAttributes =
strAttributes + " Tag: " + _
newvarAttributes(I).TagString + vbCrLf + _ " Value: " +
newvarAttributes(I).textString Next MsgBox "The attributes for
blockReference " & _ blockRefObj.Name & " are: " & vbCrLf _
& strAttributesEnd
Sub///////////////////////CODE///////////////////////////////////////////
wrote in message news:5013028@discussion.autodesk.com...
Hi,
I am a dotnet developer and new to Autocad.
I am using Visual Studio 2003 and Autocad 2005.
In my project, the reference I created give me access to:
Autodesk.AutoCAD.Interop and
Autodesk.AutoCAD.Interop.Common
The project that I am working on requires me to open a drawing and to verify
the existance of certain Blocks and their Attributes. The name of the Blocks
and the Attributes that I want to search for are known.
I can get the application object, active document and Blocks collection and
find the block that I am looking for. However, I am unable to get the
Attributes collection. The block object does not give me any method like,
for example, GetAttributes.
Following is an example of how I my code looks like.
AcadApplication _app = new AcadApplication();
_app.Documents.Open(DrawingFileName, false, "");
AcadDocument _doc = _app.ActiveDocument;
AcadBlocks _blocks = _doc.Blocks;
foreach(AcadBlock _block in _blocks)
{
if(_block.Name.Equals("MYBLOCK"))
{
//here _block object provides me
//several properties and methods but
//I am unable to find a way get
//Attributes collection
}
}
//
Any help is highly appreciated
TIA
kr