Getting selected UV-Points
-
On 15/10/2013 at 02:42, xxxxxxxx wrote:
Hey guys.
I'm afraid I already know the answer to this one, but is there a way to get the selected UV-points of an object using Python? Except for "UVWTag.GetSlow()" which gives me the UV-polygons there isn't any other function I'm aware of.
Thanks
Phil -
On 15/10/2013 at 03:14, xxxxxxxx wrote:
What do you mean with get the selected uvw points ? C4d does not make a distinction between
PointObject/PolygonObject selections and uv-point and uv-polygon selections. So op.GetPoints()
is also the active uv-point selection in Bodypaint.an example meant to be run on a polygon object with a point selection. the output will be
something like that :sel pid: 4
uvw coords: Vector(0.5, 0.5, 0)
sel pid: 5
uvw coords: Vector(0.5, 1, 0)import c4d from c4d import utils def main() : if op: uvwtag = op.GetTag(c4d.Tuvw) if uvwtag is not None: nbr = utils.Neighbor() nbr.Init(op) seldata = op.GetPointS().GetAll(op.GetPointCount()) pnt_ids = [id for id, val in enumerate (seldata) if val == True] for pid in pnt_ids: polys = nbr.GetPointPolys(pid) if polys is not None: cpoly = op.GetPolygon(polys[0]) uvwdict = uvwtag.GetSlow(polys[0]) print 'sel pid: ', pid if pid == cpoly.a: print 'uvw coords: ', uvwdict['a'] elif pid == cpoly.b: print 'uvw coords: ', uvwdict['b'] elif pid == cpoly.c: print 'uvw coords: ', uvwdict['c'] elif pid == cpoly.d: print 'uvw coords: ', uvwdict['d'] if __name__=='__main__': main()
-
On 15/10/2013 at 03:42, xxxxxxxx wrote:
Thanks for your input and the script.
But using it results in a problem when polygons share vertices. Let's say I have a cube and all uv-polygons are disconnected, so each of them has 4 UV-points, so I have a total of 24 different uv-points, but still only 8 vertices in geometry.
So in the worst case I select 3 UV-points which all correspond to the same vertex, and using your script it will only return one UV-point.
I hope my gibberish is somewhat comprehensible -
On 15/10/2013 at 05:05, xxxxxxxx wrote:
well simpy use polys = nbr.GetPointPolys(pid) to its full extend then. the method does return
all polygons attached to a point, so polys holds all polygons attached to a selected point from our
point selection list., which means you have access to all uvw_dict indices that define a uvw vector
for that point index. i just used the first polygon as this was just an example.import c4d from c4d import utils def main() : if op: uvwtag = op.GetTag(c4d.Tuvw) if uvwtag is not None: nbr = utils.Neighbor() nbr.Init(op) seldata = op.GetPointS().GetAll(op.GetPointCount()) pnt_ids = [id for id, val in enumerate (seldata) if val == True] for pid in pnt_ids: polys = nbr.GetPointPolys(pid) if isinstance(polys, list) : print 'point index: ', pid print 'attached uvw_coords:' for i in xrange(len(polys)) : cpoly = op.GetPolygon(polys[i]) uvwdict = uvwtag.GetSlow(polys[i]) if pid == cpoly.a: print 'polygon ID {0}, a : {1}'.format(polys[i], uvwdict['a']) elif pid == cpoly.b: print 'polygon ID {0}, b : {1}'.format(polys[i], uvwdict['b']) elif pid == cpoly.c: print 'polygon ID {0}, c : {1}'.format(polys[i], uvwdict['c']) elif pid == cpoly.d: print 'polygon ID {0}, d : {1}'.format(polys[i], uvwdict['d']) if __name__=='__main__': main()
point index: 1
attached uvw_coords:
polygon ID 4, a : Vector(0, 1, 0)
polygon ID 3, c : Vector(1, 0, 0)
polygon ID 0, b : Vector(0, 0, 0)
point index: 7
attached uvw_coords:
polygon ID 4, b : Vector(0, 0, 0)
polygon ID 3, b : Vector(0, 0, 0)
polygon ID 2, c : Vector(1, 0, 0) -
On 15/10/2013 at 06:34, xxxxxxxx wrote:
Thank you very much for your effort littledevil, but even with this great script (which would have probably taken me hours to code by myself) I'm still not able to identify a single selected uv-point.
I have the cube, I select a single uv-point and run your script: I'll get three points listed, and I still don't know which one of them is the selected one.
Do you know what I mean? Or maybe I am missing something really obvious. -
On 15/10/2013 at 08:20, xxxxxxxx wrote:
as i said in my first posting c4d does not make a distinction on SDK level between point and
uv-point selections. you cannot access these 'partial' selections made in the 2D UV editor.
maybe somehow in cpp, but at least i also do not know a way there either. -
On 15/10/2013 at 09:57, xxxxxxxx wrote:
Yeah, I was afraid something like this was the case.
Anyway thanks for the script, I wasn't aware of the Nieghbour-class until now.