Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: Urpa on October 04, 2024, 08:27:09 am

Title: Generate parts by associations through scripting
Post by: Urpa on October 04, 2024, 08:27:09 am
Hi,
I am trying to generate parts by associations through scripting in VB.
I am using Sysml 1.5.
I have managed to create blocks and a composite aggregation connector between my blocks. But when i look in a diagram or the project prowser there is no part, just the relation. What am I doing wrong. If I do it manually it looks like the attached link, "Generate from Part Association"

https://sparxsystems.com/enterprise_architect_user_guide/17.0/modeling_languages/parts_from_association.html (https://sparxsystems.com/enterprise_architect_user_guide/17.0/modeling_languages/parts_from_association.html)

Regards Hannah
Title: Re: Generate parts by associations through scripting
Post by: Geert Bellekens on October 04, 2024, 03:40:09 pm
The part is an element. So if you need that, you'll need to create it as well.

I'm guessing it's an embedded element, but you'll need to verify that.

Geert
Title: Re: Generate parts by associations through scripting
Post by: philchudley on October 04, 2024, 05:22:04 pm
Yes its an embedded element (child of the block).

You will have to create the part element in your script and set its Parent_ID equal to the owning Block Element_ID.

BUT ... the "EA magic" that keeps the part association role name and multiplicity in sync is handled within our good old friend t_xref. The exact details I don't remember, its something like

XrefID,Name,Type,Visibility,Namespace,Requirement,Constraint,Behavior,Partition,Description,Client,Supplier,Link,

{BF1D8DE6-5274-40b0-AD03-7B05C4B6B036},CustomProperties,element property,Public, , , , ,0,@PROP=@NAME=_connectorRef@ENDNAME;@TYPE=string@ENDTYPE;@VALU=<SOURCE>@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;@PROP=@NAME=isReference@ENDNAME;@TYPE=boolean@ENDTYPE;@VALU=0@ENDVALU;@PRMT=@ENDPRMT;@ENDPROP;,{31294601-A49A-438f-AD49-59030143FD21},{DD41CA65-BE91-481b-919C-17AB0DFDB25D}, ,


In your script you will have to create this entry in t_xref which will involve you creating a new guid for the new t_xref record.

Have fun!

Phil

Title: Re: Generate parts by associations through scripting
Post by: Urpa on October 04, 2024, 06:35:31 pm
So what I must do is: create my two blocks (A,B ), create my composition to whole relation between them and also create a new element and add it to the block where I want it to be "embedded" (A) and then set the new element to the correct classifier ID  (B) and also set the correct ParentID (A). What type should my new element be so that it shows up under "Parts" and not "Properties"?

This seems very complicated as when I do i manually i just draw one relationship connector between my two blocks.
Title: Re: Generate parts by associations through scripting
Post by: Geert Bellekens on October 04, 2024, 07:59:28 pm
This seems very complicated as when I do i manually i just draw one relationship connector between my two blocks.

The problem is that you have to recreate all the stuff that EA does in the background for you.
Unfortunately the API is mainly a thin layer on top of the database. There are hardly any functional methods that you can call.

Geert
Title: Re: Generate parts by associations through scripting
Post by: Urpa on October 04, 2024, 09:27:21 pm
Hi again,
VB scripting and EA does not seem to be my thing.
How do I get the embedded element to be a part. If a add my block to a diagram it shows up under "Properties" not "Parts". This differense is also visible if I look at the properties of the embedded element it contains "slot" not "part".
If I add the part to I diagram. The correct would be Find->"Locate Property Type in Project Browser" but i get Find->"Locate Classifier in Project Browser"
What am I doing wrong?
How do I get the connector to be associated with the part? If I later delete the part from the project browser i want the connector to be deleted.
Title: Re: Generate parts by associations through scripting
Post by: Geert Bellekens on October 04, 2024, 11:41:13 pm
It's a matter of comparing the result of your script with the real thing.

That means checking each and every field in t_object, t_xref (and maybe more) to figure it out.

It's a painfully slow and tedious job, but I haven't found a better way just yet.

Geert
Title: Re: Generate parts by associations through scripting
Post by: Urpa on October 04, 2024, 11:58:39 pm
I found a way to do what I want partly by scripting and partly manually.
I script all the connectors, and then manually create IBD-diagrams for my blocks and then syncronize the elements.
Thanks for your tips.
Title: Re: Generate parts by associations through scripting
Post by: vrieg on October 05, 2024, 04:08:20 am
I would be interested in your solution as well. Did you find a solution how to keep the parts/ports synchronized when creating them via a script.

I do more or less the same I create an Aggregation, then the parts I set the PropertyType of the parts to the parent block. Then I synchronize all tags, create an ibd and add all parts/ports to the ibd. But I loose the sychronization.
However I want to have own guids for the embedded elements this is reached.