option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Outputs the details of elements selected in the Project Browser
' 
' Related APIs
' =================================================================================
' Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html
'
sub MultiSelectionExample()

	' Show the script output window
	Repository.EnsureOutputVisible "Script"

	Session.Output( "VBScript Project Browser Multi Selection Example" )
	Session.Output( "=======================================" )
	
	' Get the set of selected items as a collection
	dim selectedElements as EA.Collection
	set selectedElements = Repository.GetTreeSelectedElements()
	
	dim selectedElementCount, i
	selectedElementCount = selectedElements.Count
		
	if selectedElementCount > 0 then
		' Iterate over all of the selected elements
		
		for i = 0 to selectedElementCount - 1
			dim theElement as EA.Element
			set theElement = selectedElements.GetAt( i )
			
			' Output the details of the current selected element
			dim message
			message = "Element Name: " & theElement.Name
			message = message & vbCrLf & "GUID: " & theElement.ElementGUID
			message = message & vbCrLf & "Type: " & theElement.Type
			message = message & vbCrLf & "Stereotype: " & theElement.StereotypeEx
			message = message & vbCrLf & "ID: " & theElement.ElementID
			message = message & vbCrLf & vbCrLf
			Session.Output( message )
		next
		
		Session.Output( "Done!" )
	else
		' No item selected in the tree, or the item selected was not an element
		Session.Prompt "This script requires one or more elements to be selected in the Project Browser." & _
			vbCrLf & "Please select a range of elements in the Project Browser and try again.", promptOK
	end if

end sub

MultiSelectionExample

