View Full Version : selecting particular edges without knowing the exact number
07-24-2011, 12:01 PM
I have made a script that generates the back of a book as seen in the picture:
I've manually selected the edges highlighted in the picture. However, I'd like my script to do this as well. But how? The mesh is different every time and i can't find any logic in the distribution of the edge's numbers.
Basically, I've extruded a curve.
backsubdiv=4+int(random.random()*8) # defines the amount of vertical subdivisions in the back
[...] #creating the curve
with a random amount of vertical subdivisions for the back.
Any idea how i can select the same amount of edges in every subdivision row? :/
07-24-2011, 02:27 PM
There will be a logic to it, it's just possibly not any logic that you could reasonably fathom or exploit in a simple script situation. If you can't figure the logic out, even by going via verts or something (I had a quick look but was left mostly scratching my head too) you'll probably have to write a function to parse the edges individually and discard the "vertical" edges (by comparing their vector to an "up" vector). I can't really think of an easier way atm...
07-24-2011, 02:30 PM
actually, here's another thought. edge  is always the first border "horizontal" edge. If you use the polySelect command to get the edge RING from this starting index, then convert that to a series of edge LOOPs (again using polySelect) you'll be pretty much there I think.
07-24-2011, 02:42 PM
[…]have to write a function to parse the edges individually and discard the "vertical" edges (by comparing their vector to an "up" vector). I can't really think of an easier way atm...
Thanks, that's an idea.
However here's my next question: how do i get information about a particular edge?
A sample script that selects only edges that are not vertical would be great.
(the other idea doesn't really help me because it works only on the first row.)
07-24-2011, 03:45 PM
to get an edge's "direction vector" simply convert it to verts (polyListComponentConversion), get the position of each of the two verts (pointPosition) as a vector and then subtract one from the other. This will give you a vector for the edge. if you then get the dotProduct of that and up (<<0,1,0>>) you will know if it's vertical or horizontal (or what percentage of either). This approach will only work if your book spines are all generated totally upright, whereas the second idea will work no matter what orientation the book is.
the second idea is much better in terms of versatility, performance and efficiency (it only works on the first row if you forget to include the edge->RING step!). However it would involve messing around with component index integers and this is always a tedious extra step.
07-24-2011, 04:33 PM
here you go, this is basically it I think (assuming your object is named "bookspine", obviously you need to swap this for your mesh variable name):
import maya.cmds as mc
hIds = mc.polySelect('bookSpine', er=1, ns=1)
del(hIds,hIds[-1]) # remove the first and last edges (borders)
mc.polySelect('bookSpine', el=hIds)doing it in python is far easier than in MEL, which I think would require you to mess around constructing dreadful command strings with multiple "-el $id" flags, very nasty.
The only issue with this I can see is that on your screenshot you've omitted the side edges, if you want these removed it's still pretty simple, you just have to del the first and the last ids returned by the final line and then reselect those edges.
07-27-2011, 05:26 PM
thanks, it works now :) at least, all horizontal edges are selected.
however, i don't know how to deselect the first and last edge in each row. What you mean is that I should read what the last line returns and then deselect the first and the last, right? the problem about this is that i'll deselect the first and the last of all selected edges and not only all selected edges in one row because it only returns me everything that has been selected and not the individual rows.
Any idea? :/
07-27-2011, 05:26 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.