Topic
  • 7 replies
  • Latest Post - ‏2012-11-13T03:34:46Z by ChrisHardy68
Gedinfo
Gedinfo
87 Posts

Pinned topic Script to determine if a child object exists under a child object.

‏2012-11-07T14:28:04Z |
I have seen some modules that have a parent object, and each object underneath the parent, all child objects, are under each preceding object.

For example
Parent
Child
Updated on 2012-11-13T03:34:46Z at 2012-11-13T03:34:46Z by ChrisHardy68
  • Gedinfo
    Gedinfo
    87 Posts

    Re: Script to determine if a child object exists under a child object.

    ‏2012-11-07T14:41:36Z  
    Sorry about the first post.
    Tab behaves differently in Chrome.

    Parent
    Child
    Child
    Child
    Child

    For normal modules

    Parent
    Child
    Child
    Child
    Child

    I wish for the script to find that the second Child object is below the first Child object, and each subsequent child objects that have a child that are not in the normal module pattern.

    Does such a script exist?

    Thank you.
  • Gedinfo
    Gedinfo
    87 Posts

    Re: Script to determine if a child object exists under a child object.

    ‏2012-11-07T15:09:17Z  
    Parent
        Child1
            Child2
                Child3
                    Child4
    

     


    Where Child1 is the "parent" of Child2, Child2 is the "parent" of Child3, etc.

     

    Updated on 2014-01-06T14:54:38Z at 2014-01-06T14:54:38Z by iron-man
  • adevicq
    adevicq
    154 Posts

    Re: Script to determine if a child object exists under a child object.

    ‏2012-11-07T16:17:47Z  
    • Gedinfo
    • ‏2012-11-07T15:09:17Z
    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">Parent Child1 Child2 Child3 Child4 </pre>

     


    Where Child1 is the "parent" of Child2, Child2 is the "parent" of Child3, etc.

     

    Hi,

    You can use the "parent" function:

    if (Child1 == parent(child2)) {
    etc...
    }
    

     


    Regards,
    Alain

     

    Updated on 2014-01-06T14:54:51Z at 2014-01-06T14:54:51Z by iron-man
  • Mathias Mamsch
    Mathias Mamsch
    2147 Posts

    Re: Script to determine if a child object exists under a child object.

    ‏2012-11-07T17:22:39Z  
    • Gedinfo
    • ‏2012-11-07T14:41:36Z
    Sorry about the first post.
    Tab behaves differently in Chrome.

    Parent
    Child
    Child
    Child
    Child

    For normal modules

    Parent
    Child
    Child
    Child
    Child

    I wish for the script to find that the second Child object is below the first Child object, and each subsequent child objects that have a child that are not in the normal module pattern.

    Does such a script exist?

    Thank you.

    Hi,

    you can iterate over the child objects of an object using:

    for Object in Object do { ... }

    you can access the n-th child of an object using

    Object = Object[n]

    e.g.:
     

    Object o = current 
     
    Object oChild; 
     
    // This loop will respect the current display set, e.g. filters, show deleted objects, etc. 
    for oChild in o do { print "Found child: " (identifier oChild) "\n" }
     
    // This loop will not respect the display set
    for oChild in all o do {
      if (isDeleted oChild) continue // skip over deleted objects
      print "Found non deleted child: " (identifier oChild) "\n"
    }
     
    // This will again respect the display set, e.g. filters, ...
    print "The 2nd visible child of the current object is: " (identifier o[2]) "\n"
    

     


    Regards, Mathias

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

    Updated on 2014-01-06T14:55:12Z at 2014-01-06T14:55:12Z by iron-man
  • llandale
    llandale
    3035 Posts

    Re: Script to determine if a child object exists under a child object.

    ‏2012-11-07T20:17:24Z  
    • Gedinfo
    • ‏2012-11-07T14:41:36Z
    Sorry about the first post.
    Tab behaves differently in Chrome.

    Parent
    Child
    Child
    Child
    Child

    For normal modules

    Parent
    Child
    Child
    Child
    Child

    I wish for the script to find that the second Child object is below the first Child object, and each subsequent child objects that have a child that are not in the normal module pattern.

    Does such a script exist?

    Thank you.

    I think you are asking that you want to find this structure...

    • Parent1
      • Child1
        • Child2
      • Child3

    ... when it should look like this:

    • Parent1
      • Child1
      • Child2
      • Child3


    If that is so... let me translate it: You want to find each object that is not qualified to be a "parent" and yet they indeed have child objects. Implementing that translation will result in this report:

     

    • "Object Child1 had a child object but is not a parent object".

    Let me scibble:

     

     

    bool  IsLegalParent(Object o)
    {    // Determine if this object qualifies as a "Parent".
         // Not sure what this means for you, but perhaps:
        string Heading = o."Object Heading"
        return(!null Heading)
    }   // end IsLegalParent()
     
    bool  IsParent_Legal, IsParent_Actual
    Object o
    Module mod = current()
    for o in entire mod do
    {  if (isDeleted(o))     continue
       IsParent_Legal  = IsLegalParent(o)
       IsParent_Actual = !null o[1]     // Is there a child object?
       if     ( IsParent_Legal and  IsParent_Actual) then{}  // No Problem
       elseif( IsParent_Legal and !IsParent_Actual) then {error, Parent has no children}
       elseif(!IsParent_Legal and  IsParent_Actual) then {error, Child has child objects}
       elseif(!IsParent_Legal and !IsParent_Actual) then {}  // no problem
       else{}   // all cases already covered
    }
    


    -Louie

     

    Updated on 2014-01-06T14:55:31Z at 2014-01-06T14:55:31Z by iron-man
  • Gedinfo
    Gedinfo
    87 Posts

    Re: Script to determine if a child object exists under a child object.

    ‏2012-11-08T18:18:07Z  
    Thanks for the help. I was able to create my script with your comments.
  • ChrisHardy68
    ChrisHardy68
    16 Posts

    Re: Script to determine if a child object exists under a child object.

    ‏2012-11-13T03:34:46Z  
    • Gedinfo
    • ‏2012-11-08T18:18:07Z
    Thanks for the help. I was able to create my script with your comments.
    Hi
    See the script in post
    http://www.ibm.com/developerworks/forums/thread.jspa?threadID=459257&tstart=0

    The "Structure" column should indicate the info you require