Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - GeordieKiwi

Pages: [1]
1
Thanks Qwerty hadn't thought of looking in StyleEx

2
We have a model with a few hundred diagrams and a few thousand elements in BPMN notation and we want to convert to ArchiMate Notation using a script as it would be too tedious to do manually.

We have managed to convert the elements okay using theElement.Type and theElement.StereotypeEx properties

Code: [Select]
function TypeConversion(sourceType, sourceStereotype, targetType, targetStereotype)
{
    this.sourceType = sourceType;
    this.sourceStereotype = sourceStereotype;
    this.targetType = targetType;
    this.targetStereotype = targetStereotype;
}
var elementConversions = new Array();
elementConversions[0] = new TypeConversion( "Activity", "BusinessProcess","Activity", "ArchiMate_BusinessProcess");
...
   for ( var i = 0 ; i < elementConversions.length ; i++ )
    {
        // If stereotype matches source list then convert
        if ( (theElement.Stereotype == elementConversions[i].sourceStereotype) && (theElement.Type == elementConversions[i].sourceType ))
        {
            theElement.Type = elementConversions[i].targetType;
            theElement.StereotypeEx = elementConversions[i].targetStereotype;
            theElement.Update();
        }
    }
...
Was planning on doing a similar thing with diagrams but discovered that theDiagram.Type contains the basic UML diagrams types like 'Analysis' or 'Logical' instead of the BPMN type "Business Process" or ArchiMate type "Business Layer" as shown in the properties window. The  theDiagram.Stereotype appears not to be used as its empty.

However I found another diagram property called MetaType that appeared to have values such as "BPMN2.0::Business Process" and "Archimate3::Business" so tried the following code

Code: [Select]
//Diagram Conversion Table
var diagramConversions = new Array();
diagramConversions[0] = new TypeConversion("Analysis", "BPMN2.0::Business Process", "Logical", "Archimate3::Business");
...
theDiagram.Type=diagramConversions[i].targetType // "Logical"
theDiagram.MetaType=diagramConversions[i].targetStereotype; //"Archimate3::Business"
        theDiagram.Update();
...

But it didn't seem to work so I've kind of stumped at how to proceed in changing diagram types via Script.

Anyone know how do I change a BMPN diagram to ArchiMate Diagram so I get the ArchiMate Business toolbox come up when I open the diagram?


3
General Board / Re: Benefits Maps and EA reporting capabilities
« on: July 09, 2016, 10:12:47 am »
Wow thats really cool. I like the wizard for creating the Investment logic diagram and docs

4
Here is some jscript that could be used.

Code: [Select]
!INC Local Scripts.EAConstants-JScript

function TypeConversion(sourceObject,sourceStereotype,targetObject, targetStereotype)
{
    this.sourceObject = sourceObject;
    this.sourceStereotype = sourceStereotype;
    this.targetObject = targetObject;
    this.targetStereotype = targetStereotype;
}

var Conversions = new Array();
// sourceObject,sourceStereotype,targetObject, targetStereotype

//Add one or more Conversion mappings here
Conversions[0] = new TypeConversion("Requirement", "", "Requirement", "extendedRequirement");


// =================================================================================
// Converts elements type and stereotype as defined in the element conversation table.
// Navigates from selected package or element and recursively modifies each element from source to target
// NOTE: Requires a package to be selected in the Project Browser
//
// Related APIs
// =================================================================================
// Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/element2.html
// Repository API http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/repository3.html

/*
 * Project Browser Script main function
 */
function OnProjectBrowserScript()
{
// Get the type of element selected in the Project Browser
var treeSelectedType = Repository.GetTreeSelectedItemType();

// Handling Code: Uncomment any types you wish this script to support
// NOTE: You can toggle comments on multiple lines that are currently
// selected with [CTRL]+[SHIFT]+[C].
switch ( treeSelectedType )
{
case otElement :
{
// Code for when an element is selected
var theElement as EA.Element;
theElement = Repository.GetTreeSelectedObject();
ConvertElements( "", theElement );
break;
}
case otPackage :
{
// Code for when a package is selected
var thePackage as EA.Package;
thePackage = Repository.GetTreeSelectedObject();
NavigatePackage( "", thePackage );

break;
}
// case otDiagram :
// {
// // Code for when a diagram is selected
// var theDiagram as EA.Diagram;
// theDiagram = Repository.GetTreeSelectedObject();
//
// break;
// }
// case otAttribute :
// {
// // Code for when an attribute is selected
// var theAttribute as EA.Attribute;
// theAttribute = Repository.GetTreeSelectedObject();
//
// break;
// }
// case otMethod :
// {
// // Code for when a method is selected
// var theMethod as EA.Method;
// theMethod = Repository.GetTreeSelectedObject();
//
// break;
// }
default:
{
// Error message
        Session.Prompt( "This script requires a package to be selected in the Project Browser.\n" +
            "Please select a package or element in the Project Browser and try again.", promptOK );
}
}
}

//
// Outputs the packages name and elements, and then recursively processes any child
// packages
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function NavigatePackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Add the current package's name to the list
    Session.Output( indent + currentPackage.Name + " (PackageID=" +
        currentPackage.PackageID + ")" );
   
    // Convert the elements this package contains
    ConvertElementsInPackage( indent + "    ", currentPackage );
   
    // Recursively process any child packages
    var childPackageEnumerator = new Enumerator( currentPackage.Packages );
    while ( !childPackageEnumerator.atEnd() )
    {
        var childPackage as EA.Package;
        childPackage = childPackageEnumerator.item();
        NavigatePackage( indent + "    ", childPackage );
       
        childPackageEnumerator.moveNext();
    }
}

//
// Converts the elements of the provided package to the Script output window
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function ConvertElementsInPackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Iterate through all elements and add them to the list
    var elementEnumerator = new Enumerator( currentPackage.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var currentElement as EA.Element;
        currentElement = elementEnumerator.item();
        ConvertElements(indent+"    ",currentElement );

        elementEnumerator.moveNext();
    }
}

function ConvertElements( indent, theElement )
{
    // Cast theElement to EA.Element so we get intellisense
    var currentElement as EA.Element;
    currentElement = theElement;
    currentElement.ObjectType
    ConvertElement(indent+"    ",currentElement );
    // Iterate through all embedded elements and add them to the list
    var elementEnumerator = new Enumerator( currentElement.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var currentElement as EA.Element;
        currentElement = elementEnumerator.item();
        ConvertElements(indent+"    ",currentElement );
        elementEnumerator.moveNext();
    }
}

// Converts the element from source to target mappings from conversions array
//
// Parameters:
// - indent A string representing the current level of indentation
// - theElement The element object to be processed
function ConvertElement( indent, theElement )
{
// Debug Comment out when run for real
    //Session.Output( indent + "CALLED: ConvertElement with " + theElement.Name + " [" + theElement.Type + ", " + theElement.Stereotype + " )" );

    for ( var i = 0 ; i < Conversions.length ; i++ )
    {
        // If stereotype matches source list then convert
        if ( (theElement.Stereotype == Conversions[i].sourceStereotype) && (theElement.Type == Conversions[i].sourceObject ))
        {
            Session.Output( indent + "CONVERTED: " + theElement.Name + " (" + theElement.Type + ", " + theElement.Stereotype + ")" + "=>" +"("+Conversions[i].targetObject+","+Conversions[i].targetStereotype+")" );
            theElement.Type = Conversions[i].targetObject;
            //Over write the stereotype list to have only one stereotype
            theElement.StereotypeEx = Conversions[i].targetStereotype;
            theElement.Update();
            break; // once found cease iterating through for-loop.
        }
    }
}

OnProjectBrowserScript();

Good timing Sunshine, was just about to do a similar exercise of changing stereotypes.

5
Thanks Sunshine. That code worked  a treat.

6
General Board / Re: Enterprise Integration Patterns
« on: May 18, 2016, 08:22:31 pm »
Thanks Sunshine, really useful mdg for integration pattern

Pages: [1]