Cancel
Showing results for 
Search instead for 
Did you mean: 

Reference child via name

Pioneer
Pioneer

Dear community,

 

I'm currently looking for a way to refer to a child just by it's name.

 

I figured the function <path>.childNo(i) refers to the child by index. I now could of course check all child.names using a for-loop, but I guess that if there is a built-in function provided by PS, this will work a lot faster.

Has someone encountered that issue before?

 

As always,

 

thanks a lot in advance

 

best regards

 

Tim

4 REPLIES 4

Re: Reference child via name

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

just for better understanding: you know the name, but you dont know the location of the object?

 

if you know both you can use str_to_obj to create a reference

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: Reference child via name

Pioneer
Pioneer

Hi Steffen,

 

thanks for the fast reply,

 

I don't know the exact location, otherwise you are right and the str_to_obj would be my choice. But since the exact location may be a subject to change, I would like to decouple my method from it.

 

Best regards

 

Tim

Re: Reference child via name

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

I guess, there is no ready function for this.

 

I would search in the frames instead in the instances of the class. This would result less loops, like this (not tested) as function:

 

(objName:string; objClass:object; objFrame:object):object
is
do
if objFrame.isNameUnique(objName)=false and
str_to_obj(to_str(frame)+"."+objName).class=objClass then
return str_to_obj(to_str(frame)+"."+objName);
else
return void;
end;

end;
Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net

Re: Reference child via name

Siemens Phenom Siemens Phenom
Siemens Phenom

The standard method 'extendPath' might be exactly what you are looking for.

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.