Python infinite incursion self-node reference

   2563   12   1
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
I was wondering if anyone might know how I can get the equivalent of an Hspcript expression in python without infinite recursion:

For Hscript I can do the following referencing the same node the parameter expression is being used in;

point(opinputpath('.',0),5,'P',2)

But I can't do something like that in Python:

Point_list = pwd().geometry().points() # does not work - infinite incursion
return Point_list[5].position()[2]
Edited by BabaJ - May 29, 2019 11:51:59
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
I'm not getting an infinite recursion with your example, it says the pwd() is not defined.

Anywway, have you tried this?
hou.pwd().geometry().points()



one question for me:
what is the difference of using opinputpath or a simple integer 0, like u would do in vex?

My understanding is that they are the very same, with the latter vex like functionality being added later by sidefx to make input referencing cleaner and faster? Am I correct?
Edited by Andr - May 29, 2019 12:22:46
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
Yeah Andr…I meant to use hou.pwd()

But either way it still is infinite recursion.

Funny you ask about opinputpath.

Yes, 0 works fine…I was only using optinputpath because in my case when I looked at the docs for the point function it shows as examples a string quote for the first argument, and in my case using that doesn't work(infinite recursion);


point('.',5,'P',2)

nor
point('../This_Nodes_Name/',5,'P',2)

So in trying different things from searching I saw reference to opinputpath, and tried that, and it works with no recursion.

So I have a simpler option now too, just 0;

But still looking how to do the same with python.
Edited by BabaJ - May 29, 2019 14:17:36
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
Are you working on an python sop node?
I'm not getting infinite recursion with that code.

can you post hip?
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
If you know the point number you want then this should work:

hou.pwd().geometry().point(5).position()[2]
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
Hey Andr…no any other sop is what I am after.

As an example…transform node…and here's an example with mkps suggestion,

which still gives infinite recursion.

Attachments:
Python recursion Node self_referral.hiplc (65.8 KB)

User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
This looks like a limitation with what you're trying to do and it's creating an infinite loop. I can create a float parameter and put the python code I have above in it and it evaluates fine. I can create a new vector parameter and put that python code in the z component and it works fine too. The error occurs though when trying to put that code in a parameter that's going to update the transform node. Even trying to relative reference the custom vector parameter breaks the transform node. I'd guess hscript is more built for that kinda of looping feedback.
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
And the infinite recursion comes from when you try to access the hou.pwd().geometry() itself, not just the points…
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
Yes..it's like the Hscript takes point data first, ‘before entering’ the sop.

I noticed that too, if the python is simply a spare parameter created on the SOP…then it's fine.

Not an issue, just going to go with an Hscript approach; Was making a preset and this works with Hscript for Pivot Translate of Transform node:

{
Pts = npoints(0);
Selected = abs(ch('pivot_pt_num')) % Pts;
Pos = point(0, Selected, 'P', 0);
return Pos;
}


…thought I might not be aware of/missing an approach that could have be done with python.
Edited by BabaJ - May 29, 2019 16:18:27
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
try accessing the input upstream instead of the very same node?

Test = pwd().inputs()[0].geometry().point(5).position()[2]
return Test


I guess this is actually the very same of what you do with the opinputpath in hscript, you access the input node.
Indeed in hscript, if you use the path of the very same node, you get the same recursion error

In your example file, if in the transform2 node you set one paramter as the following:
point("/obj/geo1/transform2",5,'P',2)

you get recursion
Edited by Andr - May 29, 2019 16:42:44
User Avatar
Member
191 posts
Joined: Oct. 2018
Offline
Andr
try accessing the input upstream instead of the very same node?

I guess this is actually the very same of what you do with the opinputpath in hscript, you access the input node.
Indeed in hscript, if you use the path of the very same node, you get the same recursion error

That makes sense and I completely overlooked that the hscript is getting the input node and not working on it's own geo..
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
ye, I was on the same boat before Babaj brought up the issue
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
try accessing the input upstream instead of the very same node?

Actually, for some time now that's the way I have been doing it.

But I'm just beginning to explore setting up presets.

The idea behind the presets, is like in this case, just drop down a transform node and select the preset; That will work in any context regardless of upstream node names.

If I have to rely on upstream for referencing, that means everytime I use the preset, I have to still go in and define the name of the upstream node in the expressions;

Defeats the purpose of the preset; In my case, not having to always write the expression out.

Which is why I'm going with the Hscript I posted above. It doesn't need to be in Python…I was just curious to know how it could be done.


Edit: My apologies Andr…I missed your post about using inputs()…I had tried that earlier, but I guess I got the syntax wrong(needed the square brackets also)…so thanks for that solution. So yes, can be done in either Hscript or Python. Cheers!
Edited by BabaJ - May 29, 2019 18:19:21
  • Quick Links