Thanks Geert, much appreciated. Out of curiosity, what version are you using? We should we getting the same error you are getting with selectedElements.Count but we are not.
This works and have not changed selectedElements.Count.
!INC Local Scripts.EAConstants-JScript
/*
* This code has been included from the default Diagram Script template.
* If you wish to modify this template, it is located in the Config\Script Templates
* directory of your EA install path.
*
* Script Name:
* Author:
* Purpose:
* Date:
*/
/*
* Diagram Script main function
*/
function OnDiagramScript()
{
// Get a reference to the current diagram
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();
Session.Output("Started");
if ( currentDiagram != null )
{
Session.Output(currentDiagram.Name);
// Get a reference to any selected connector/objects
var selectedConnector as EA.Connector;
var selectedElements as EA.Collection;
selectedElements = currentDiagram.SelectedObjects;
Session.Output(selectedElements.Count());
//selectedConnector = currentDiagram.SelectedConnector;
if ( selectedConnector != null )
{
// A connector is selected
}
else if (selectedElements.Count > 0 )
{
var objectCount = 0;
while (objectCount < selectedElements.Count())
{
Session.Output("Enumerating");
var currentDiagElement as EA.DiagramObject;
currentDiagElement = selectedElements.GetAt(objectCount);
var currentElement = Repository.GetElementByID(currentDiagElement.ElementID);
Session.Output(currentElement.Type);
Session.Output(currentElement.Name);
currentElement.Type = "Class"; //Change the type - it fails
currentElement.Stereotype = ""; //Clear the Current Stereotype - it fails with both Stereotype and StereotypeEx
currentElement.Update();
currentElement.Stereotype = "ArchiMate_Requirement"; //Clear the Current Stereotype - it fails with both Stereotype and StereotypeEx
currentElement.Update();
//currentElement.StereotypeEx = "ArchiMate3::ArchiMate_Requirement"; //This also fails
objectCount = objectCount + 1;
}
}
else
{
// Nothing is selected
}
}
else
{
Session.Prompt( "This script requires a diagram to be visible.", promptOK)
}
}
OnDiagramScript();