Page 1 of 2

findchild question

Posted: 16 Apr 2014 14:00
by AkaMed
Hello,

I am trying to modify an object's expression that is in another container, but I get lost trying...
The goal is to call a pads object inside a container from another pads object from another container.
I tried:

decl preset = firstof(x);
decl a=findchild('Container2', 'Seq');
decl b=findchild(a, 'Load');
setexpression(b, x[preset], 1);

But it doesn't work...
Any help?

Re: findchild question

Posted: 16 Apr 2014 14:29
by Softcore
Is there a particular reason you choose findchild() and not findobject()?

Re: findchild question

Posted: 16 Apr 2014 14:46
by AkaMed
Hello Softcore,

because with findobject I believe I can only find and object that has an unique name...Am I wrong?
And I have several objects with the same name inside different containers.
I am confused...

Re: findchild question

Posted: 16 Apr 2014 14:53
by AkaMed
i.e.
I would love to get something like...

decl preset=firstof(x);
Container2.Seq.Load.x[preset]=1;

Re: findchild question

Posted: 16 Apr 2014 14:56
by oldgearguy
I don't think setexpression ('someObject', x[number], 1); works. I thought setexpression() needed a quoted string as the second parameter.

So you'd have to build up a vector equal to the sixe of x and then do setexpression('someObject', 'x', newVectorOfValues);

Re: findchild question

Posted: 16 Apr 2014 14:58
by Softcore
Franky Im also at loss as to what findchild(object, name) means!

As in...does it expect the object AND name (string) of the parent or what? Not sure...if it expects the parent and the name of the child then why couldnt we just go

findobject('child') per se...Im lost

Re: findchild question

Posted: 16 Apr 2014 14:59
by Softcore
yes and oldgear guy is correct - I missed that....

Its setexpression(object, name-of-expression, val)

So the object msut be a direct reference, the expression must be the string name of the expression

Re: findchild question

Posted: 16 Apr 2014 15:07
by AkaMed
Thanks for the responses,
yes, the problem is if the expression contains a vector...what can we do then?

Re: findchild question

Posted: 16 Apr 2014 15:19
by oldgearguy
AkaMed wrote:Thanks for the responses,
yes, the problem is if the expression contains a vector...what can we do then?

decl i, newVector = {0,0,0,0};

i = findfirst(x);
newVector = x;
setexpression('myObject', 'x', newVector);


You can be more clever using sizeof(x) and fill(newVector...) to create the initial vector, but you should have the general idea now.

Re: findchild question

Posted: 16 Apr 2014 15:33
by AkaMed
Works!!!
Thanks oldgearguy!!!
My modified code is:

decl preset = firstof(x);
decl a=findobject('Container2.Seq.Load');
decl newVector = {0,0,0,0,0,0,0,0};
newVector[preset] = x[preset];
setexpression(a, 'x', newVector);

Now I can call any action from anywhere!
Thanks Softcore also!