option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Lists all top level packages and diagrams underneath them in a non-recursive style.
' 
' Related APIs
' =================================================================================
' Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html
'
sub NonRecursiveModelDumpExample()

	' Show the script output window
	Repository.EnsureOutputVisible "Script"

	Session.Output( "VBScript NON RECURSIVE MODEL DUMP EXAMPLE" )
	Session.Output( "=======================================" )
	
	' Get the first model node
	dim theModel as EA.Package
	set theModel = Repository.Models.GetAt( 0 )
	
	' Iterate through all views (top level packages) in the model
	dim currentView as EA.Package
	for each currentView in theModel.Packages
		' Add the name of this view to the output window
		Session.Output( "View: " & currentView.Name )
		
		' Iterate through all diagrams in this view
		dim currentDiagram as EA.Diagram
		for each currentDiagram in currentView.Diagrams
			' Add the name of this diagram to the output window
			Session.Output( "    -> Diagram: " & currentDiagram.Name )
			
			' Iterate through all objects in this diagram
			dim currentDiagramObject as EA.DiagramObject
			for each currentDiagramObject in currentDiagram.DiagramObjects
				' Get the element that this Diagram Object represents
				dim currentElement as EA.Element
				set currentElement = Repository.GetElementByID( currentDiagramObject.ElementID )
				
				if not currentElement is nothing then
					' Add the element details to the list
					Session.Output("        -> Element: " & currentElement.Name & _
						" (" & currentElement.Type & _
						", ID=" & currentElement.ElementID & ")" )
				end if
			next
		next
	next
	
	Session.Output( "Done!" )
	
end sub

NonRecursiveModelDumpExample
