Message 1 of 15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I get a block reference (has attribute) from other drawing as code follow:
Public Sub GetBlock_Info()
Dim blockName As String = "test"
Try
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim doclock As DocumentLock = doc.LockDocument()
Dim ed As Editor = doc.Editor
Dim ofd As New OpenFileDialog("Select Drawing", Nothing, "dwg; dwt", "ATS detai drawing", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles)
Dim dr As System.Windows.Forms.DialogResult = ofd.ShowDialog()
If dr <> System.Windows.Forms.DialogResult.OK Then
Return
End If
Dim filePath As String = ofd.Filename
'Using doclock
Using OpenDb As New Database
OpenDb.ReadDwgFile(filePath, System.IO.FileShare.ReadWrite, True, "")
Using opentrans As Transaction = OpenDb.TransactionManager.StartTransaction()
Dim openBT As BlockTable = DirectCast(opentrans.GetObject(OpenDb.BlockTableId, OpenMode.ForRead), BlockTable)
If openBT.Has(blockName) Then
Dim openbtrec As BlockTableRecord = openBT(blockName).GetObject(OpenMode.ForRead)
Dim openbref As New BlockReference(New Point3d(0, 0, 0), openbtrec.ObjectId)
If openbtrec.HasAttributeDefinitions Then
Dim attCol As AttributeCollection = openbref.AttributeCollection
For Each attId As ObjectId In attCol
Dim attRef As AttributeReference = DirectCast(opentrans.GetObject(attId, OpenMode.ForRead), AttributeReference)
MsgBox(attRef.TextString)
Next
End If
End If
opentrans.Commit()
opentrans.Dispose()
End Using
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
End Try
End SubBlock "test" contains some attributes but the code can not get them.
Hope for help.
Solved! Go to Solution.

