I want to create a simple command, that will take the selected components and align them to a point under the users mouse, limiting the movement to a single axis.
This can be done in default Maya but its cumbersome and involves multiple steps:
- Select components to be moved
- Activate the axis they are to be moved along (by clicking on the pivots/gizmos axis)
- Turn on point snapping on the status line (or hotkey)
- with pointer under the target vertex, middle click to complete the operation
The above is one of my favourite features in Maya, I uses it all the time. I really need to streamline it. The command I have in mind is:
- Select components to be moved
- with pointer under the target vertex, trigger command (or hotkey) to complete the operation
The following is what I so far have, it works but with one limitation, the “target” vertex is hardcoded:
global proc snapToPoint(string $axis){
string $sel[]= `ls -flatten -orderedSelection`;
vector $target = `pointPosition -world pPlane1.vtx[1]`; // <--- replace this hardcoded value with the vertex under the pointer
if ($axis == "x")
move -x ($target.x) ($target.y) ($target.z) -worldSpace $sel;
else if ($axis == "y")
move -y ($target.x) ($target.y) ($target.z) -worldSpace $sel;
else if ($axis == "z")
move -z ($target.x) ($target.y) ($target.z) -worldSpace $sel;
}
This is why I need a way to get the vertex under the users mouse or the one that is being highlighted, as shown here:
I have searched for solutions and I keep coming across C++ answers like this
I have looked at the Mel reference as well and did not come across potential commands.
I am on the latest Maya.