Author Topic: Text beneath an DiagramObject (text is related to DiagramObject Element)  (Read 1119 times)

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Hello,

on a Diagram I show a Property/Part as a DiagramObject with an image assigned to it.

Now I want to show a small text string beneath/beside the DiagramObject. The best would be the value of a TaggedValue but any related information would do.

I have experimented a bit with visualizing compartments. They are visualized as labels. Too much information.

I just want a small text.

Do you have an idea? Dynamic Diagrams? Or?

Thanks,

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Ruff

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
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'

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();