Hi,
If you use VBA, please refer to this snippet:
Extract all attributes to a text file:
Code: Select all
Public Sub AttOut()
Dim SSetCol As SelectionSets
Dim sset As SelectionSet
Dim BlkInsert As BlockInsert
Dim BlkAtts As Variant
Set SSetCol = ActiveDocument.SelectionSets
For Each sset In SSetCol
If sset.Name = "SS" Then
ActiveDocument.SelectionSets.Item("SS").Delete
Exit For
End If
Next
Set sset = ActiveDocument.SelectionSets.Add("SS")
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 66: FilterData(1) = "1"
sset.SelectOnScreen FilterType, FilterData
' open a text file
Dim filePath As String
filePath = ActiveDocument.GetVariable("DwgPrefix")
Set fso = New FileSystemObject
Set txtFSO = fso.CreateTextFile(filePath & "\Attributes.txt", True, True)
' write the attributes into a text file
For Each BlkInsert In sset
Set BlkAtts = BlkInsert.GetAttributes
txtFSO.WriteLine "BlockName: " & BlkInsert.Name
For Each objAttrib In BlkAtts
txtFSO.Write vbTab & "(" & objAttrib.TagString & " ; " & objAttrib.TextString & ")"
Next
txtFSO.WriteLine
Next
txtFSO.Close
End Sub
And set value for attributes:
Code: Select all
Public Sub SetAtts()
Dim SSetCol As SelectionSets
Dim sset As SelectionSet
Dim BlkInsert As BlockInsert
Dim BlkAtts As Variant
' tag value data, change here to fix your data (tagName _ tagValue)
Dim tagValuesDict As New Scripting.Dictionary
tagValuesDict.Add Key:="NAME-1", Item:="Tesla"
tagValuesDict.Add Key:="DESCRIPTION-1", Item:="Automation"
tagValuesDict.Add Key:="DESIGNED", Item:="Design name"
tagValuesDict.Add Key:="DRAWN", Item:="Drawer name"
Set SSetCol = ActiveDocument.SelectionSets
For Each sset1 In SSetCol
If sset1.Name = "SS" Then
ActiveDocument.SelectionSets.Item("SS").Delete
Exit For
End If
Next
Set sset = ActiveDocument.SelectionSets.Add("SS")
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 66: FilterData(1) = "1"
sset.SelectOnScreen FilterType, FilterData
For Each BlkInsert In sset
Set BlkAtts = BlkInsert.GetAttributes
For Each objAttrib In BlkAtts
If tagValuesDict.Exists(objAttrib.TagString) Then
' set the attributes value
objAttrib.TextString = tagValuesDict(objAttrib.TagString)
End If
Next
Next
ActiveDocument.Regen (vicActiveViewport)
End Sub