how to use hscript and python to output point position

   5895   7   1
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
I have the following hscript to output the xyz positioins of 3 points as text, something like a string of “-0.755747, -0.65044, 0.0759825 -0.715619, -0.658654, 0.232518 -0.830901, -0.524088, 0.18691”

point(“../each1”, 0, “P”, 0) + “, ” +
point(“../each1”, 0, “P”, 1) + “, ” +
point(“../each1”, 0, “P”, 2) + “ ” +
point(“../each1”, 1, “P”, 0) + “, ” +
point(“../each1”, 1, “P”, 1) + “, ” +
point(“../each1”, 1, “P”, 2) + “ ” +
point(“../each1”, 2, “P”, 0) + “, ” +
point(“../each1”, 2, “P”, 1) + “, ” +
point(“../each1”, 2, “P”, 2)

I want to make it generally applicable to polygons with whatever number of points. However, I can't get the following python script to output the same thing:

points = hou.pwd().geometry().points()

txt = “”

for point in points:
pos = point.attribValue(“P”)
x = pos
y = pos
z = pos
txt = txt + str(x) + “, ” + str(y) + “, ” + str(z) + “ ”

return txt

May I ask how to correct it? and How to achieve it use Hscript programming using command like “for”?

Thanks!
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
any advices? Thanks!
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
advices are greatly appreciated, thanks!
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
That python snippet you posted gives position for all points, there is difference in hscript only in rounding (the amount of digits) during displaying those values.

For hscript you can loop with something like this:

{
# path to the node
string node = “../each1”;

# number of points to loop over
nbpt = npoints(node);

# output text
string buffer = “”;

# components
string x = “”;
string y = “”;
string z = “”;

# loop over points
for (i=0;i<nbpt;i++)
{
x = point(node, i, “P”, 0);
y = point(node, i, “P”, 1);
z = point(node, i, “P”, 2);
buffer = buffer + x + “, ”+ y + “, ” + z + “ ”;
}

return buffer;
}

Attachments:
pz_hscript_for_loop.hipnc (62.0 KB)

User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
Thank you very much, pezetko!

You advice works!

However, it seems the point coordinates obtained only works for triangle polygon if I want to use it to get a closed cubic NURBS surface based on a polygon with more than 3 corners. (http://www.derivative.ca/wiki088/index.php?title=Spline) [derivative.ca]

I wonder how to do this using your method…

Attachments:
Screen Shot 2014-11-12 at 12.23.39 pm.png (161.2 KB)
pz_hscript_for_loop_237_JS.hipnc (100.8 KB)
Screen Shot 2014-11-12 at 12.23.45 pm 1.png (154.4 KB)

User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
Hi, I think there's a point order issue, so a “sort” node is needed before the curve node.

Thanks!

Attachments:
pz_hscript_for_loop_237_js_971_v2.hipnc (184.1 KB)
Screen Shot 2014-11-12 at 11.36.01 pm.png (222.9 KB)
Screen Shot 2014-11-12 at 11.36.19 pm.png (327.8 KB)

User Avatar
Member
4512 posts
Joined: Feb. 2012
Offline
You can use Radial Sort SOP if I understand what you are trying to do:
https://www.orbolt.com/asset/animatrix::radialSort::1.00 [orbolt.com]
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
Thanks, Animatrix! will take a look of your tool
  • Quick Links