option explicit

!INC Local Scripts.EAConstants-VBScript

'
' An example of File IO with VBScript. This script will dump some basic top
' level information about the model to the output window and to file
' 
' Related APIs
' =================================================================================
' Scripting.FileSystemObject - http://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx
'

' Global attributes for File IO
Dim fileSystemObject
Dim outputFile

sub FileIOExample()

	' Show the script output window
	Repository.EnsureOutputVisible "Script"

	Session.Output( "VBScript FILE IO EXAMPLE" )
	Session.Output( "=======================================" )

	' Define Global File IO Objects
	set fileSystemObject = CreateObject( "Scripting.FileSystemObject" )
	set outputFile = fileSystemObject.CreateTextFile( "c:\\EAOutput.txt", true )

	' Process the model
	ProcessModel()

	' Close the output file
	outputFile.Close()

	Session.Output( "Done!" )

end sub

sub ProcessModel()

	' Iterate through all model nodes in the repository
	dim currentModel as EA.Package
	for each currentModel in Repository.Models
		
		VBTrace( currentModel.Name )
		
		' Iterate through all packages in the model
		dim currentPackage as EA.Package
		for each currentPackage in currentModel.Packages
			
			VBTrace ( "    " & currentPackage.Name )
			
			' Iterate through all elements in the current package
			dim currentElement as EA.Element
			for each currentElement in currentPackage.Elements
			
				VBTrace( "        " & currentElement.Name )
				
				' Iterate through all methods in the current element
				dim currentMethod as EA.Method
				for each currentMethod in currentElement.Methods
				
					VBTrace( "            " & currentMethod.Name )
					
					' Iterate through all parameters in the current method
					dim currentParam as EA.Parameter
					for each currentParam in currentMethod.Parameters
						VBTrace( "                " & currentParam.Name )
					next
				next
			next
		next
	next

end sub

'
' Dumps the provided msg string to file and the output window
'
Sub VBTrace( msg )
	
	dim trimmedMessage
	trimmedMessage = trim(msg)

	if len( trimmedMessage ) > 0 then
		outputFile.WriteLine( msg )
		Session.Output( msg )
	end if
	
End Sub

FileIOExample
