Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Hurra on February 27, 2018, 02:26:45 am

Title: Move element as child element
Post by: Hurra on February 27, 2018, 02:26:45 am
Hello!

I have imported a massive excel and want to move elements to be child elements.

The setup is like this:

Name of elem:

x§ y kap zzz

where x = int, y = int and zzz = a string.

I have created a script which, not most effectively, selects the y kap, and then finds all x§ y kap. Now i want to move these x§ elements to be a child of the y kap element.

I could probably find the correct elements to move with SQL which I know is more efficient. That is something I should invest more time mastering!

However.. how do I move elements to be child elements? I found EAEelement.TreePos, but I doubt that is what I'm looking for. Should I use something in the EARepository class?

Thank you!
Title: Re: Move element as child element
Post by: Uffe on February 27, 2018, 02:39:06 am
Hello!


Element.TreePos represents the element's top-to-bottom position at its level in the project browser -- not what you want. (Also only becomes non-zero after a user has manually moved an element at that level. Weird.)

To move an element to be the child of another element, simply set the child element's ParentID to the ElementID of the desired parent element. Don't worry about .PackageID, EA will update it as necessary.

FYI:
For a non-child element, the ParentID is 0. For a child element, its PackageID is the same as its parent element's.
Element.Elements contains child elements which can stand alone (so classes in classes, etc).
Element.EmbeddedElements contains structural child elements, which cannot exist outside a parent (Port, Pin, etc).

HTH,


/Uffe
Title: Re: Move element as child element
Post by: Arshad on February 27, 2018, 04:29:28 pm

However.. how do I move elements to be child elements? I found EAEelement.TreePos, but I doubt that is what I'm looking for. Should I use something in the EARepository class?

How did you import that massive excel into EA ?
Did you try MDG Integration for Microsoft Office (https://sparxsystems.com.au/products/mdg/int/office/office-integration.html) ?

It allows user to import an excel file contents directly into EA and you can even map the child parent settings in the profile of excel importer.



HTH
Arshad
Title: Re: Move element as child element
Post by: Hurra on February 27, 2018, 06:34:51 pm
@Uffe: of course! thank you!

@Arshad: yes, with the Office MDG. I wasn't involved in creating the excel, couldn't get the automation with parents to work. Therefore I thought it might be easier to create a script rather then changing stuff in the excel, perhaps I was wrong, but the script is done.