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
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.