Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: pianoman on November 05, 2019, 03:17:31 pm

Title: Automation to make diagrams with part properties/instances?
Post by: pianoman on November 05, 2019, 03:17:31 pm
Hey everyone, I'm curious whether it's possible to script the creation of diagrams with elements that are Property type objects. I know diagrams can be created with scripting, but curious as to how they could be populated with Property type objects that don't yet exist. The case I am considering is something like this:

Diagram A has a number of <<ResourceArtifact>> elements that create a hierarchy.

Can Diagram B be made such that it is contained simply of the the Property type version of the elements in Diagram A? Diagram B needs no connectors between the Property type objects.

Would this be something of a partitioned approach to scripting? Something where one script creates the Property type elements, and another will then create a diagram to dump them in.

Is this possible? Any related examples anyone can point me to?

Title: Re: Automation to make diagrams with part properties?
Post by: Geert Bellekens on November 05, 2019, 06:12:55 pm
Yes, you can create anything you want.

The "trick" to create new objects in EA is to us the AddNew() method on the collection of the owner. (e.g. myPackage.Element.AddNew())

Geert
Title: Re: Automation to make diagrams with part properties?
Post by: qwerty on November 05, 2019, 06:34:03 pm
Can Diagram B be made such that it is contained simply of the the Property type version of the elements in Diagram A? Diagram B needs no connectors between the Property type objects.
I doubt that. Embedded elements need their parent to appear on a diagram. Maybe the automation can "tweak" what tha GUI does not make that happen (like it can (still?) create duplicates of elements). I would nor recommend it. though.

q.
Title: Re: Automation to make diagrams with part properties?
Post by: pianoman on November 07, 2019, 04:18:03 am
Hi All,

I managed to at least work on getting a script together to create new "instance" elements and a diagram within a selected package. This is about a 1/4 of the way there. For some reason, despite making a diagram object variable to add the instance element to the new diagram, it won't show up on the diagram. Can someone see what the problem could be here? I've searched this forum for past issues such as this, and Geert has mentioned a cast-discrepancy can cause this, but I'm not certain what this is or how to resolve this. I'm guessing it's something to do with me trying to equalize variable sets EA.DiagramObject and EA.Element

Code: [Select]
Dim element3 as EA.Element
Dim package as EA.Package
Dim diagram as EA.Diagram
Dim diagramobj as EA.DiagramObject

set package = Repository.GetTreeSelectedPackage()

set element3 = package.Elements.AddNew("ActualTestResource", "UAFP::ActualResource")
element3.ClassifierID(2651)
element3.Update

set diagram = package.Diagrams.AddNew("Test", "Class")
set diagramobj = diagram.DiagramObjects.AddNew("", "")

diagramobj.ElementID = element3.ElementID
diagramobj.Update
diagram.Update
diagram.DiagramObjects.Refresh
package.Elements.Refresh
package.Diagrams.Refresh

Once I can get this basic functionality done, I am looking to utilize a SQL Query to call multiple classifier IDs to make multiple "instance" elements to drop them on a diagram. Does anyone have any pointers for this end goal? I am guessing it will have something to do with Repository.SQLQuery which will return an XML string that I will need to parse for classifier IDs. And I will have to run this in a loop.

Am I on the right track here? TYIA
Title: Re: Automation to make diagrams with part properties/instances?
Post by: qwerty on November 07, 2019, 08:10:50 am
element3.ClassifierID(2651)
 
is just a no-op. No VB guy I am, but

element3.ClassifierID = 2651

it rather shall be.

The refresh calls at the end are just noise. Just throw them away.

q.
Title: Re: Automation to make diagrams with part properties/instances?
Post by: pianoman on November 07, 2019, 10:19:41 am
element3.ClassifierID = 2651

it rather shall be.

This still doesn't drop the newly created instance on the newly created diagram though.
Title: Re: Automation to make diagrams with part properties/instances?
Post by: pianoman on November 07, 2019, 12:29:48 pm
Hey guys, finally was able to marry up querying and VBScript to flexibly create arrays and reference to them to automate creation of instances. This is nifty and could have many other automation capabilities!

I want to give a big shoutout to Geert for his code here https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/Util.vbs
There are nice little examples of SQLQuery and VBScript harmonious usage.

I'm still only stuck on why I can't get the diagram object to appear on the new diagram I'm creating according to my script above. Any pointers there? I'd be good for this after!
Title: Re: Automation to make diagrams with part properties/instances?
Post by: Paolo F Cantoni on November 07, 2019, 03:52:33 pm
Hey guys, finally was able to marry up querying and VBScript to flexibly create arrays and reference to them to automate creation of instances. This is nifty and could have many other automation capabilities!

I want to give a big shoutout to Geert for his code here https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/Util.vbs
There are nice little examples of SQLQuery and VBScript harmonious usage.

I'm still only stuck on why I can't get the diagram object to appear on the new diagram I'm creating according to my script above. Any pointers there? I'd be good for this after!
Hi pianoman,

You ARE saving and reloading the diagram, aren't you - after adding the diagram objects?

Paolo
Title: Re: Automation to make diagrams with part properties/instances?
Post by: qwerty on November 07, 2019, 06:42:07 pm
What Paolo means:

Repository.ReloadDiagram (diagram.DiagramID);

is missing.

q.
Title: Re: Automation to make diagrams with part properties/instances?
Post by: pianoman on November 08, 2019, 03:02:57 am
That doesn't seem to be like the missing piece  :-\
Title: Re: Automation to make diagrams with part properties/instances?
Post by: Geert Bellekens on November 08, 2019, 05:29:55 am
Diagram.Update might be the culprit here.
It might be undoing you new diagram objects.

Have you tried removing that line?

I just checked in my scripts, and this one:
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/ef73f2a3523b3ed31c194a6b8f15dfb3ec7ef79b/Projects/Project%20A/A%20Scripts/Test.vbs (https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/ef73f2a3523b3ed31c194a6b8f15dfb3ec7ef79b/Projects/Project%20A/A%20Scripts/Test.vbs)
add elements on a diagram and it doesn't do a diagram.Update

Here's another example that doesn't call diagram.Update
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/ef73f2a3523b3ed31c194a6b8f15dfb3ec7ef79b/Projects/EA-Matic%20Scripts/BI-RepActions.vbs (https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/ef73f2a3523b3ed31c194a6b8f15dfb3ec7ef79b/Projects/EA-Matic%20Scripts/BI-RepActions.vbs)

Geert
Title: Re: Automation to make diagrams with part properties/instances?
Post by: pianoman on November 08, 2019, 06:34:48 am
Diagram.Update might be the culprit here.
It might be undoing you new diagram objects.

Have you tried removing that line?

So I removed it and ran the script and curiously enough the diagram does not show up on the project browser. But what I did after is move the diagram.Update before I set the diagramobj and that worked!

That was quite a headscratcher, and I'm not entirely certain why that move was necessary, but I'm glad it works now!

Thanks all for your help!