Thank you DeBAAT, but I am still officially confused, perhaps because it has been a long week and I am no longer used to writing code.
This script is doing some seriously strange things.
!INC Local Scripts.EAConstants-JavaScript
/*
* 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();
if ( currentDiagram != null )
{
// Get a reference to any selected connector/objects
var selectedConnector as EA.Connector;
var selectedObjects as EA.Collection;
selectedConnector = currentDiagram.SelectedConnector;
selectedObjects = currentDiagram.SelectedObjects;
if ( selectedConnector != null )
{
// A connector is selected
}
else if ( selectedObjects.Count > 0 )
{
// One or more diagram objects are selected
var objectCount = 0;
while (objectCount < selectedObjects.Count)
//while (objectCount < selectedObjects.Count())
{
Session.Output("Enumerating");
var currentDiagElement as EA.DiagramObject;
currentDiagElement = selectedObjects.GetAt(objectCount);
var currentElement = Repository.GetElementByID(currentDiagElement.ElementID);
Session.Prompt(currentElement.Type, promptOK); //[1]
Session.Prompt(currentElement.Name, promptOK); //[2]
//Session.Prompt(currentElement.Steretoype, promptOK); //[3]
currentElement.Type = "Class";
currentElement.Stereotype = "";
currentElement.Update();
//currentElement.Steretoype = "ArchiMate_Requirement"; //[5]
currentElement.Steretoype = "ArchiMate3::ArchiMate_Requirement"; //[6]
currentElement.Update();
Session.Prompt(currentElement.Type, promptOK); //[7]
Session.Prompt(currentElement.Name, promptOK); //[8]
Session.Prompt(currentElement.Steretoype, promptOK); //[9]
objectCount = objectCount + 1;
}
}
else
{
// Nothing is selected
}
}
else
{
Session.Prompt( "This script requires a diagram to be visible.", promptOK)
}
Repository.ReloadDiagram(currentDiagram.DiagramID);
}
OnDiagramScript();
1) Lines 47 & 48, marked [1] & [2], return the correct values.
2) Line 49, marked [3], always errors, if not commented out, but it is an exact copy of line 58. The error is "Parameter 1 type mismatch". I am attributing this to the stereotype being blank, but if that is the case, it must be a bug, see below.
3) Lines 53 and 54, marked [7] & [8], both work. We are settling with line 54.
4) Line 56, marked [7], returns the correct type, as per the change from line 50.
5) Line 58, marked [9], returns the stereotype as per the change from line 54.
6) Nothing else visibly errors.
7) Line 72 reloads a diagram with all elements changed as per line 50 - i.e., to a class,
but a blank/empty stereotype - i.e., the change applied by lines 54, mark as [7] and 55, and correctly displayed by line 58, marked as [9], disappear.
Just to help matters, sarcasm intended, line 58, marked [9], does not error, despite now having a blank/empty stereotype, but line 49, mark as [3], always errors when not commented out.