You are on page 1of 3

Option Explicit

Private Sub Command1_Click()

On Error GoTo errorHandler

Dim oTaggedText As New INSERTTAGGEDTXTINTOFILELib.TaggedTxtIO


Dim lNumStreams As Long
Dim arrStreamNames() As String
Dim iCounter As Integer
Dim sData As String
Dim oDomDoc As DOMDocument
Dim oNode As IXMLDOMNode
Dim oChildNode As IXMLDOMNode
Dim oRootStorageHelper As igrRADRootStorage.CHelper
Dim oDocument As SmartSketch.Document
Dim oApplication As SmartSketch.Application
Dim ii As Integer
Dim oMyLoader As igrRADRedir.CLoader

Const STR_Storage As String = "TaggedTxtData"

On Error Resume Next


Set oApplication = GetObject(, "SmartSketch.Application")
On Error GoTo errorHandler

Set oMyLoader = New CLoader


oMyLoader.InitializeApplication "SmartSketch.application"

If Not oApplication Is Nothing Then


Set oDocument = oApplication.ActiveDocument
If Not oDocument Is Nothing Then

'// NOTE: You'll have to use this Helper object to get the root storage
of the
'// Document you want to process. Then call .SetStorage() with
the return from
'// GetRootStorage() <instead of using .SetFileName()>; you can
use .SetFileName()
'// without running SmartSketch, if you want. This example uses
the ActiveDocument.
'// It can be any Document...
'//
Set oRootStorageHelper = New igrRADRootStorage.CHelper
oTaggedText.SetStorage oRootStorageHelper.GetRootStorage(oDocument)
Else
MsgBox "No Active Document!"
GoTo done
End If
Else

'// Open a File with the Tagged Text library


'// Works with files that are not actively loaded in a running instance of
SmartSketch.
'//
oTaggedText.SetFileName "C:\Temp\TitleBlock.igr"
End If
'// Get the stream names and count from the TaggedTxtData storage
'//
oTaggedText.GetStreamNames STR_Storage, lNumStreams, arrStreamNames
Debug.Print "Number of Streams = " & lNumStreams
If lNumStreams <> 0 Then

'// Loop through all the streams...


'//
For iCounter = 1 To lNumStreams

'// Read the data from the stream


'//
oTaggedText.GetData STR_Storage, arrStreamNames(iCounter), sData

'// Create a DOMDocument and load the data into it


'//
Set oDomDoc = New DOMDocument
If oDomDoc.loadXML(sData) Then

'// Loop through the root level nodes of the DOMDocument


'//
Set oNode = oDomDoc.firstChild
Do
Debug.Print oNode.nodeName

'// If it has child Nodes...


'//
If oNode.childNodes.Length > 0 Then

'// Loop through the child nodes of the root node


'//
Set oChildNode = oNode.firstChild
Do
Debug.Print "..." & oChildNode.nodeName & " = " &
oChildNode.nodeTypedValue

'// Let's change the value of the DrawingNumber field


'//
If oChildNode.nodeName = "DrawingNumber" Then
oChildNode.nodeTypedValue = "DrawingNumber by VB"
End If

'// Get the next sibling of the Child node


'//
If Not oChildNode.nextSibling Is Nothing Then
Set oChildNode = oChildNode.nextSibling
Else
Set oChildNode = Nothing
End If

Loop While Not oChildNode Is Nothing

End If

'// Get the next sibling of the root level node


'//
If Not oNode.nextSibling Is Nothing Then
Set oNode = oNode.nextSibling
Else
Set oNode = Nothing
End If

Loop While Not oNode Is Nothing

End If

'// Now write the data back to the stream


'//
sData = oDomDoc.xml
oTaggedText.SetData STR_Storage, arrStreamNames(iCounter), sData

Set oDomDoc = Nothing


Next
End If

done:
'// IMPORTANT NOTE:
'// ALWAYS call Complete or else you will not be able to open the file again
'// until you log off and log back in!
'// NEVER set a break point after opening the file and then stop debugging
'// without calling complete (see above)
'//
If Not oTaggedText Is Nothing Then
oTaggedText.Complete 1
End If
Set oTaggedText = Nothing
Set oMyLoader = Nothing

If Not oDocument Is Nothing Then


oRootStorageHelper.RefreshTitleBlockFieldsDisplay oDocument
Set oDocument = Nothing
End If
Set oRootStorageHelper = Nothing

Exit Sub

errorHandler:
MsgBox Err.Number & " - " & Err.Description
GoTo done
End Sub

Private Sub Command2_Click()

End

End Sub

You might also like