Many times I need to select a edge and get the exact center of this edge. I thought there would be a simple single command but I have not found any such thing.
I have been making do with the mult-cut tool but I think holding control until I get “50%” to show then click to place the vertex. This is too convoluted for what should be a simple task, I also dont like switching tools.
Is there a command that I can just run to do this?
PS: I am not opposed to a mel/python script that download from somewhere
Any help would be greatly appreciated!
if you select an edge and then hold SHIFT
and right-click you will open the poly modelling Marking Menu, which contains many of the most of the common modelling functions. You should see Add Divisions To Edge which, when chosen will add a new vertex in the centre of the edge (assuming it’s still set on the default number of divisions, 1). However, this also reports, in the Script Editor:
polySubdivideEdge -ws 0 -s 0 -dv 1 -ch 1 pCube1.e[7];
so you now also know what the command to do that is. You could also simply use the multi-cut tool, snapped to 50% to add a vertex and you would see:
polySplit -ch 1 -sma 180 -ep 1 0.5 |pCube1|pCubeShape1;
reported in the Script Editor (albeit with some additional guff you don’t need to worry about).
Both of these commands will do what you want, using two different and useful approaches. If you were hoping the new vertex would be somehow “connected” to other verts on the faces, well that’s when it starts to get a bit more involved.
If you are not actually wanting to insert a vertex (as your post title suggests you are) but are simply looking for a way to locate the center of an edge, then the simplest way is to convert the selected edge into vertices using polyListComponentConversion
, then get both vertex positions, using pointPosition
, add the positions together, then get the average. then create a spaceLocator
at that new position.
in MEL:
string $edges[] = `filterExpand -sm 32 -ex true`;
for ($edge in $edges)
{
string $verts[] = `polyListComponentConversion -fromEdge -toVertex $edge`;
vector $P1 = `pointPosition -w $verts[0]`;
vector $P2 = `pointPosition -w $verts[1]`;
vector $C = ($P1+$P2)/2.0;
spaceLocator -p ($C.x) ($C.y) ($C.z);
}
1 Like
@Naughty
I will test this out as soon as I get to my home compueter, but I am confident your answer will suffice.
Thank you for helping me once again.