option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Example illustrating how to add and delete Stereotypes.
' 
' Related APIs
' =================================================================================
' Stereotype API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/stereotype.html
' Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html
'
sub ManageStereotypesExample()
	
	' Show the script output window
	Repository.EnsureOutputVisible "Script"
	
	dim i

	Session.Output( "VBScript MANAGE STEREOTYPES EXAMPLE" )
	Session.Output( "=======================================" )
		
	' Create a new stereotype in the repository
	dim stereotypes as EA.Collection
	set stereotypes = Repository.Stereotypes
	
	dim testStereo as EA.Stereotype
	set testStereo = stereotypes.AddNew( "TestStereotype", "Class" )
	testStereo.Update()
	stereotypes.Refresh()
	
	Session.Output( "Added Stereotype: " & testStereo.Name )
	
	set testStereo = nothing
	
	' Navigate the stereotype collection. Delete the newly added stereotype
	' when we find it
	for i = 0 to stereotypes.Count - 1
		dim currentStereo as EA.Stereotype
		set currentStereo = stereotypes.GetAt( i )
		
		Session.Output( "Stereotype: " & currentStereo.Name )
		
		' If the stereotype is the one we just added, then delete it
		if currentStereo.Name = "TestStereotype" then
			stereotypes.DeleteAt i, false
			Session.Output( "Deleted Stereotype: " & currentStereo.Name )
		end if
	next
	
	Session.Output( "Done!" )
	
end sub

ManageStereotypesExample
