Author Topic: SOLVED: How do I move an element to a new parent?  (Read 1254 times)

Svend Erik Nygaard

  • EA User
  • **
  • Posts: 128
  • Karma: +1/-1
  • Business Information Architect
    • View Profile
SOLVED: How do I move an element to a new parent?
« on: July 08, 2014, 09:48:10 pm »
In an EA script, I want to move an element from one parent element to new parent element.
How do I do that?
« Last Edit: July 09, 2014, 01:45:25 am by svenderiknygaard »

qwerty

  • EA Guru
  • *****
  • Posts: 10393
  • Karma: +229/-178
  • I'm no guru at all
    • View Profile
Re: How do I move an element to a new parent?
« Reply #1 on: July 09, 2014, 12:01:02 am »
Code: [Select]
Element.ParentID = Package.PackageID // Package is the new parent
Element.Update()
q.

Svend Erik Nygaard

  • EA User
  • **
  • Posts: 128
  • Karma: +1/-1
  • Business Information Architect
    • View Profile
Re: How do I move an element to a new parent?
« Reply #2 on: July 09, 2014, 01:36:09 am »
Thanks Qwerty.

I was fooled by my own 'debug'function that wrote the element collections out before and after - I just forgot to refresh those collections :-/

Thanks for good response :-)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6721
  • Karma: +63/-6
    • View Profile
Re: How do I move an element to a new parent?
« Reply #3 on: July 23, 2014, 09:12:41 am »
Quote
Code: [Select]
Element.ParentID = Package.PackageID // Package is the new parent
Element.Update()
I'm afraid that's wrong.
Code: [Select]
// Move directly under a package
Element.PackageID = Package.PackageID;
Element.ParentID = 0; // Necessary only if the element was previously nested under another non-package object
Element.Update();

// Move under another element
Element.PackageID = Element2.PackageID; // Necessary only if the Element2 is in a different package to Element initially
Element.ParentID = Element2.ElementID; // Element2 is the new parent of Element
Element.Update();
Eve

support@sparxsystems.com

qwerty

  • EA Guru
  • *****
  • Posts: 10393
  • Karma: +229/-178
  • I'm no guru at all
    • View Profile
Re: SOLVED: How do I move an element to a new pare
« Reply #4 on: July 23, 2014, 07:32:40 pm »
Thanks for verifying that, Simon. I just wrote those lines out of my head without verification :-[

q.