Hi All,
How to get attributes from block located at external drawing?
Thanks for any helps.
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
@ditran wrote:
Hi All,
How to get attributes from block located at external drawing?
Thanks for any helps.
Block - is a BlockTableRecord or a BlockReference?
Attribute - is a AttributeDefinition or a AttributeReference or some others?
Please use a "AutoCAD .NET API terminology"
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Try this code tested on A2010,
change block name to your suit
<CommandMethod("rad")> _ Public Sub ReadAttributesToDataBase() Dim blockName As String = "TITLEBLOCK" Dim ofd As New Autodesk.AutoCAD.Windows.OpenFileDialog( _ "Open source DWG for read", Nothing, "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles) Dim dr As System.Windows.Forms.DialogResult = ofd.ShowDialog() If dr <> System.Windows.Forms.DialogResult.OK Then Return Dim sourcedwg As String = ofd.Filename Dim dict As New Dictionary(Of String, String) Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument() Dim doclock As DocumentLock = doc.LockDocument() Dim ed As Editor = doc.Editor Dim db As Database = doc.Database Using doclock Using exdb As New Database(False, True) exdb.ReadDwgFile(sourcedwg, System.IO.FileShare.ReadWrite, True, "") Using extr As Transaction = exdb.TransactionManager.StartTransaction() Dim exbt As BlockTable = DirectCast(extr.GetObject(exdb.BlockTableId, OpenMode.ForRead), BlockTable) If exbt.Has(blockName) Then Dim id As ObjectId = exbt(blockName) Dim exbtr As BlockTableRecord = extr.GetObject(id, OpenMode.ForRead) For Each brid As ObjectId In exbtr.GetBlockReferenceIds(True, True) Dim exbref As BlockReference = extr.GetObject(brid, OpenMode.ForRead) For Each attid In exbref.AttributeCollection Dim attref As AttributeReference = extr.GetObject(attid, OpenMode.ForRead) If Not dict.ContainsKey(attref.Tag) Then dict.Add(attref.Tag, attref.TextString) End If Next Next End If extr.Commit() End Using End Using End Using 'use returned values here: For Each Kvp As KeyValuePair(Of String, String) In dict ed.WriteMessage(vbLf + "Tag: {0}" + vbTab + "Value: {1}" + vbLf, Kvp.Key, Kvp.Value) Next End Sub