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

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
Gedinfo - Wed Nov 07 09:28:04 EST 2012

Re: Script to determine if a child object exists under a child object.
Gedinfo - Wed Nov 07 09:41:36 EST 2012

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.

Re: Script to determine if a child object exists under a child object.
Gedinfo - Wed Nov 07 10:09:17 EST 2012

Parent
    Child1
        Child2
            Child3
                Child4

 


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

 

Re: Script to determine if a child object exists under a child object.
adevicq - Wed Nov 07 11:17:47 EST 2012

Gedinfo - Wed Nov 07 10:09:17 EST 2012

Parent
    Child1
        Child2
            Child3
                Child4

 


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

 

Re: Script to determine if a child object exists under a child object.
Mathias Mamsch - Wed Nov 07 12:22:39 EST 2012

Gedinfo - Wed Nov 07 09:41:36 EST 2012
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

 

Re: Script to determine if a child object exists under a child object.
llandale - Wed Nov 07 15:17:24 EST 2012

Gedinfo - Wed Nov 07 09:41:36 EST 2012
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

 

Re: Script to determine if a child object exists under a child object.
Gedinfo - Thu Nov 08 13:18:07 EST 2012

Thanks for the help. I was able to create my script with your comments.

Re: Script to determine if a child object exists under a child object.
ChrisHardy68 - Mon Nov 12 22:34:46 EST 2012

Gedinfo - Thu Nov 08 13:18:07 EST 2012
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