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

Pages: [1]
1
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();

2
I was inspired by Java inserting into a legend
I have no issues adding the legend to the diagram but they entries to the legend aren't added.  Any ideas why this my not work are welcome.  (version 15.2.1554)

Here's the SQL statement in generates:(I can't post code but a paste link like this works?!?)


Link to Stack Overflow since I can't post code here.

3
Automation Interface, Add-Ins and Tools / Posting with ANY type of code
« on: January 03, 2025, 07:16:41 am »
Is anyone else able to get a message passed the cleaner Spam protection.  If I add any code it fails... :(

4
I found your previous post on the subject.

I was able to get working code:

Code: [Select]
const regex = /<Diagram_ID>(.*?)<\/Diagram_ID>/g;

function parseDiagramIDs(xmlString) { //XML Parsers were not working for me so I modified to use regex.
    // Define a regex pattern to match all <Diagram_ID> tags and capture their values
   
    const diagramIDs = [];
    let match;

    // Execute regex and push all matches to the array
    while ((match = regex.exec(xmlString)) !== null) {
        if (match[1]) {
            diagramIDs.push(match[1]); // Push the captured value (Diagram ID) to the array
        }
    }

    if (diagramIDs.length === 0) {
        throw new Error("No Diagram_IDs found in the XML.");
    }
   
    return diagramIDs.map( id => new Number(id));
}

 function iutils_GetDiagramOccurences(anObject) {
var num_diagrams;
var theObject As EA.Element;
theObject = anObject;

// Construct and execute the query
var sql = "";

sql += " select do.Diagram_ID "
     + " from t_diagramobjects do "
     + " where do.Object_ID = " + theObject.ElementID+ ";"

var queryResult = Repository.SQLQuery( sql );

var diagramIdsNum = [];
if ( queryResult.length > 0 )
{
//Session.Output(queryResult)
diagramIdsNum = parseDiagramIDs( queryResult );
}
return diagramIdsNum;
 }

5
This seems to be a documentation issue.  'Left' is what is defined in the documentation but I saw you use 'left'
Code: [Select]
function main()
{
var diagram as EA.Diagram;
var diagramObject as EA.DiagramObject;
diagram = Repository.GetDiagramByGuid("{8D386671-458F-4285-B191-BEC91CDF7F20}")
const diagramObjectCollection = diagram.DiagramObjects
for( i = 0; i< diagramObjectCollection.Count; i++){
diagramObject = diagram.DiagramObjects.GetAt(i)
if (typeof diagramObject.Left !== 'undefined'){
Session.Output("Left:" +diagramObject.Left)
}else if(typeof diagramObject.left !== 'undefined'){
Session.Output("left:"+diagramObject.left)
}else{
Session.Output( diagramObject.ElementID + "Left/left is Undefined!")
}
}
}

main();

And in the output:
Code: [Select]
left:589
left:381
left:215
left:399
left:399
left:209
left:207
left:790
Thanks for helping me find this.

6
If an element is in a package, how can you script a way to located all the diagrams that it's contained in?

(I'm aware of Element.Diagrams and I'm not looking for sub-diagrams of the element, I'm talking across the repository.)

Would using the Element.Connectors.DiagramID be the answer or does the Connectors DiagramID hold another meaning?

7
I know that they're all underfined as a printed out their value, when I got them returned as an object.
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 )
{
forEachCollection( selectedObjects , dObject  =>{
out( get(dObject.ElementID).Name, dObject.InstanceGUID, dObject.Left+"") // short hand for Session.Output()

})
}
else
{
// Nothing is selected
}
}
else
{
Session.Prompt( "This script requires a diagram to be visible.", promptOK)
}

//currentDiagram.DiagramObjects.Update()
currentDiagram.Update()
Repository.ReloadDiagram(currentDiagram.DiagramID)
}

OnDiagramScript();

8
Also, if you want to replace an old element with a new one, you can simply change the elementID of the diagramObject to the new ElementID.

Thank you! This I think is the answer. 


(Big fan of your posts, you help a lot of people, thank you for what you do.)

9
I'm trying to import a new set of elements that supercede the existing ones.
I have migrate the relationships but when I try to replace the items in existing diagrams I'm having issues.

In the existing diagram DiagramObjects should have Top, Left, Bottom, Right.  This would help me to add the new relationship in the same spot.  But when I read this value, they're undefined.  I tried viewing their style and sure enough they're is no values for l,r,b,t.

I also just for giggles tried setting the value (DiagramObjects.Left = 50) updating the object and reloading the diagram, but this does nothing as well.

I can add an object with l,r,b,t and that works but how can we move thing via scripting?

Any ideas on how to get positioning of an DiagramObjects?

Pages: [1]