>>>>>>>> OK I got it to work <<<<<<<<<<<<<
this code gets a drawing already loaded.
Loops through each attribute in a Title block called B-AttributeBlock. adds them to a list box and then shows 4 of them in text boxes. also gets the drawing and path
You need these two References in VB.NET
AutoCAD = Autodesk.AutoCAD.Interop
AXDBLib = Autodesk.AutoCAD.Interop.Common
------------------
Private Sub btnLoadAttributes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadAttributes.Click
Dim AcadObj As Object
Dim Path1, dwg As String
Dim OldtitleBlock As Object
Dim ThisDrawing As Object
Dim a, b, I, j, FindSlash As Integer
'OLE Automation Object Calls
AcadObj = GetObject(, "AutoCAD.Application")
ThisDrawing = AcadObj.ActiveDocument
OldtitleBlock = False
Dim docName As String
docName = ThisDrawing.FullName
b = 1
For a = 1 To Len(docName)
FindSlash = InStr(b, docName, "\")
If FindSlash = 0 Then Exit For
b = FindSlash + 1
Next
Path1 = Microsoft.VisualBasic.Left(docName, b - 1)
dwg = Microsoft.VisualBasic.Right(docName, Len(docName) - b + 1)
Dim fType(1) As Short, fData(1) As Object
Dim ss As Autodesk.AutoCAD.Interop.AcadSelectionSet
Try
ss = ThisDrawing.SelectionSets("ss")
Catch ex As Exception
ss = ThisDrawing.SelectionSets.Add("ss")
End Try
ss.Clear()
fType(0) = 0
fData(0) = "INSERT"
fType(1) = 2
fData(1) = "B-AttributeBlock"
ss.Select(Autodesk.AutoCAD.Interop.Common.AcSelect.acSelectionSetAll, , , fType, fData)
' Now if the selection set count is greater than 0, you have every unnested instance of the block
' insert contained in the drawing. Since every item in the set is a BlockReference, you can use any
' property or method supported by AcadBlockReference and/or AcadEntity:
Dim hndl, atts As Object
For I = 0 To ss.Count - 1
OldtitleBlock = True
hndl = ss.Item(I).Handle
atts = ss.Item(I).GetAttributes
If VarType(atts) <> vbEmpty Then
For j = LBound(atts) To UBound(atts)
'
Me.lstAttributes.Items.Add(" Tag: " + atts(j).TagString + " Value: " + atts(j).TextString)
If atts(j).TagString = "QTYFORJOB" Then
If Val(atts(j).TextString) 0 Then
Me.txtQty.Text = atts(j).TextString
Else
MsgBox("The Job Qty is Zero, please key in a Quantity", vbInformation, "Missing Job Qty")
'GoTo Exit_Command16_Click
End If
End If
If atts(j).TagString = "TITLEBLCKSIZE" Then
If Microsoft.VisualBasic.Left(atts(j).TextString, 1) = "A" Then
'A size title block
Me.txtTitleBlock.Text = "A"
Else
' B size
Me.txtTitleBlock.Text = "B"
End If
End If
If atts(j).TagString = "THKXWIDXLNG" Then
Me.txtMaterialCutSize.Text = atts(j).TextString
End If
If atts(j).TagString = "MATERIALID" Then
Me.txtMaterialID.Text = atts(j).TextString
End If
Next
End If
Next
End Sub