- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everyone,
Please help me with this
I need to add a attribute Tag and a value (position Z) to each block on my dwg
But doing this in vb.net
Here is my code so far
<CommandMethod("LISTATT")> _
Public Sub ListAttributes()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db2 As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tr As Transaction = db.TransactionManager.StartTransaction()
' Start the transaction
Try
' Build a filter list so that only
' block references are selected
Dim values() As TypedValue = { _
New TypedValue(DxfCode.BlockName, "DOT")
}
Dim sfilter As New SelectionFilter(values)
Dim opts As New PromptSelectionOptions()
opts.MessageForAdding = "Select blocks: "
Dim res As PromptSelectionResult = ed.GetSelection(opts, sfilter)
' Do nothing if selection is unsuccessful
If res.Status <> PromptStatus.OK Then
Return
End If
Dim selSet As SelectionSet = res.Value
Dim idArray As ObjectId() = selSet.GetObjectIds()
For Each blkId As ObjectId In idArray
Dim blkRef As BlockReference = DirectCast(tr.GetObject(blkId, OpenMode.ForRead), BlockReference)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
ed.WriteMessage(vbLf & "Block: " + btr.Name)
btr.Dispose()
Dim attCol As AttributeCollection = blkRef.AttributeCollection
For Each attId As ObjectId In attCol
' Dim attRef As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)
' attRef.Tag = "COTA" ---------it repace other attribute
' attRef.TextString = attRef.Position.Z
' Dim str As String = ((vbLf & " Attribute Tag: " + attRef.Tag &
vbLf & " Attribute String: ") + attRef.TextString)
' ed.WriteMessage(str)
Next
Next
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage(("Exception: " + ex.Message))
Finally
tr.Dispose()
End Try
End Sub
The problem is that it replace other atribute with COTa and the value of Position Z
Solved! Go to Solution.