Originally Posted by
Ed Jobe
.NET is designed to work with xml, but vba is not. As you said, can use txt but you have to format your own lines and manually write them. See this post on writing to txt. You can search this forum for similar posts using the keywords you find in this post.
I had agreed, perhaps easier yet to write as plain text
something like this one
(tested on A2009 only)
Code:
Public Sub WriteBlocksToXML()
Dim oBlkRef As AcadBlockReference
Dim oAttrib As AcadAttributeReference
Dim oEnt As AcadEntity
Dim attArray As Variant
Dim i As Integer
Dim xmlFile
xmlFile = "C:\UsedFiles\MyBlocks.xml"
Open xmlFile For Output As #1
Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & _
" encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
'' < add xml-schema if it's needed here >
Print #1, "<blocks>"
For Each oEnt In ThisDrawing.ModelSpace
If TypeOf oEnt Is AcadBlockReference Then
Set oBlkRef = oEnt
If oBlkRef.HasAttributes Then
Print #1, "<block>"
Print #1, "<name>" & oBlkRef.EffectiveName & "</name>"
Print #1, "<id>" & CStr(oBlkRef.ObjectID) & "</id>"
Print #1, "<attributes>"
attArray = oBlkRef.GetAttributes
For i = LBound(attArray) To UBound(attArray)
Set oAttrib = attArray(i)
Print #1, "<attribute>"
Print #1, "<tag>" & oAttrib.TagString & "</tag>"
Print #1, "<value>" & oAttrib.TextString & "</value>"
Print #1, "</attribute>"
Next i
Print #1, "</attributes>"
Print #1, "</block>"
End If
End If
Next oEnt
Print #1, "</blocks>"
Close #1
End Sub
~'J'~