Author Topic: How do you add a package to diagram via automation interface?  (Read 3862 times)

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1296
  • Karma: +119/-10
  • Its the results that count
    • View Profile
How do you add a package to diagram via automation interface?
« on: January 19, 2018, 02:38:32 pm »
I'm trying to get a jscript to work that creates a diagram for each package and adds child elements and packages to the diagram.  I've managed to get the child elements to be added to the diagram but not the child packages.

I think its because I'm passing a Package ID to Diagram.Object.ElementID

theDiagramObject.ElementID( childElement.ElementID);
//Substituted the above code that works with element with this below
theDiagramObject.ElementID( childPackage.PackageID);

Here is a snippet of code
Code: [Select]
function AddDiagramToPackage(  thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;

    var theDiagram as EA.Diagram;

    theDiagram = thePackage.Diagrams.AddNew( thePackage.Name, "Logical" );
    theDiagram.Update();

    var diagramObjects as EA.Collection;
    diagramObjects = theDiagram.DiagramObjects;
 
    // iterate through all child elements and add them to the diagram -THIS DOES WORK
    var elementEnumerator = new Enumerator( currentPackage.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var childElement as EA.Element;
        childElement = elementEnumerator.item();
var theDiagramObject as EA.DiagramObject;
theDiagramObject = diagramObjects.AddNew("","");
theDiagramObject.ElementID( childElement.ElementID );
theDiagramObject.Update();
  elementEnumerator.moveNext();
    }

    // iterate through all child packages and add them to the diagram -THIS DOESN'T WORK
    var childPackageEnumerator = new Enumerator( currentPackage.Packages );
    while ( !childPackageEnumerator.atEnd() )
    {
        var childPackage as EA.Package;
        childPackage = childPackageEnumerator.item();
childPackage.ElementID;
  var theDiagramObject as EA.DiagramObject;
theDiagramObject = diagramObjects.AddNew("","");
theDiagramObject.ElementID( childPackage.PackageID);
theDiagramObject.Update();

        childPackageEnumerator.moveNext();
    }

I've scoured the help but can't seem to see how to add packages to a diagram via the automation interface. Any thoughts/help welcome.
Happy to help
:)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13091
  • Karma: +544/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How do you add a package to diagram via automation interface?
« Reply #1 on: January 19, 2018, 03:35:13 pm »
PackageID is not the same as ElementID.
You have to use Package.Element.ElementID

Geert

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1296
  • Karma: +119/-10
  • Its the results that count
    • View Profile
Re: How do you add a package to diagram via automation interface?
« Reply #2 on: January 20, 2018, 09:37:34 am »
PackageID is not the same as ElementID.
You have to use Package.Element.ElementID

Geert
Of course, that worked a treat. Thanks Geert.
Happy to help
:)