1
Automation Interface, Add-Ins and Tools / Re: Text beneath an DiagramObject (text is related to DiagramObject Element)
« on: March 21, 2025, 01:30:30 am »
Create a diagram,
Add an object with a tagged value. i.e. "under_text"
Here I used a 'Diagram group' to make my life easy but you could just as easily do this with a 'Normal Group'
Here's the code specific to the digram group:
Add an object with a tagged value. i.e. "under_text"
Here I used a 'Diagram group' to make my life easy but you could just as easily do this with a 'Normal Group'
Code: [Select]
const PADDING = 20;
const TAG_NAME = "under_text"
function addTextUnderElement( diagram, Object, text ){
var DObject as EA.DiagramObject;
DObject = Object;
var currentDiagram as EA.Diagram;
currentDiagram = diagram
var myPackage as EA.Package;
myPackage = Repository.GetPackageByID( currentDiagram.PackageID )
const element = myPackage.Elements.AddNew("","Text")
element.Notes = text
element.Update()
var newDObject as EA.DiagramObject;
newDObject = currentDiagram
.DiagramObjects
.AddNew(`l=${DObject.left},r=${DObject.right},t=${DObject.bottom-PADDING},b=${DObject.bottom+(DObject.top-DObject.bottom)}`,"")
newDObject.ElementID = element.ElementID
newDObject.Update()
}
Here's the code specific to the digram group:
Code: [Select]
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 )
{
for( let i = 0; selectedObjects.Count > i; i++){
const DObject = selectedObjects.GetAt(i)
var element as EA.Element;
element = Repository.GetElementByID( DObject.ElementID )
for( let j =0 ; j < element.TaggedValues.Count; j++){
var taggedV as EA.TaggedValue;
taggedV = element.TaggedValues.GetAt(j)
if ( taggedV.Name == TAG_NAME ){
addTextUnderElement( currentDiagram, DObject, taggedV.Value )
}
}
}
}
else
{
// Nothing is selected
}
}
else
{
Session.Prompt( "This script requires a diagram to be visible.", promptOK)
}
Repository.ReloadDiagram(currentDiagram.DiagramID)
Session.Output("Done")
}
OnDiagramScript();