how to use hscript and python to output point position
5898 7 1- oat
- 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!
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!
- oat
- Member
- 479 posts
- Joined: Dec. 2009
- Offline
- oat
- Member
- 479 posts
- Joined: Dec. 2009
- Offline
- pezetko
- 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;
}
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;
}
- oat
- 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…
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…
- oat
- Member
- 479 posts
- Joined: Dec. 2009
- Offline
- animatrix_
- Member
- 4515 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]
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
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- oat
- Member
- 479 posts
- Joined: Dec. 2009
- Offline
-
- Quick Links