Book a Demo

Author Topic: Move element as child element  (Read 4693 times)

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Move element as child element
« 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!
always learning!

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Move element as child element
« Reply #1 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
My theories are always correct, just apply them to the right reality.

Arshad

  • EA User
  • **
  • Posts: 286
  • Karma: +20/-1
    • View Profile
Re: Move element as child element
« Reply #2 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 ?

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

Hurra

  • EA User
  • **
  • Posts: 183
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Re: Move element as child element
« Reply #3 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.
always learning!