Maya Python script to show numerical vertex translation
Question: I want to write a script for Maya in Python which allows you to see the
numerical translation of a Vertex in a headup display.

So if a pick one Vertex and move it along an axis, in the headup display
should appear the moved value since the start world position of the Vertex.

as example the world position is '20, 20 , 50' of teh vertex and I move it to
'20, 20 , 30' in the headup display should be display '0 0 20'.

I am far away but this is what I have done until now.

    
    
    import maya.cmds as cmds
    
    selection = cmds.ls(sl=True) 
    
    for obj in selection:
        vertexWert = cmds.pointPosition( obj , w=True)
    
    print vertexWert
    


Answer: You can get a notification about the change with an `attributeChanged`
scriptJob on the `.outMesh` attribute of the object to fire a script when the
mesh is edited. However that won't know _why_ the mesh changed: for example it
will fire if you rotate a vertex selection instead of moving it. You'll have
to store a copy of the vert positions and compare the new ones with the old
ones to get the actual difference.

Here's a very basic example which uses prints (the
[headsUpDisplay](http://download.autodesk.com/us/maya/2011help/CommandsPython/headsUpDisplay.html)
command is very wordy so I'll leave that out). I'm also using a global
variable, which in general is a bad idea but it sounds like adding classes
into the problem will make it harder to demonstrate: the 'right' thing to do
is to make a callable class that manages the mesh differences for you.

    
    
    # to save the mesh positions. This does mean you can only use this code on one object at a time....
    global _old_positions
    _old_positions = None
    
    # this is the callback function that gets called when the mesh is edited
    def update_mesh_positions():
        selected = cmds.ls(sl=True, o=True)
        if selected:
            selected_verts = selected[0] + ".vtx[*]"
            global _old_positions
            # make sure we have something to work with....
            if not _old_positions:
                _old_positions = cmds.xform(selected_verts, q=True, t=True, ws=True)
    
            # gets all of the vert positions
            new_positions = cmds.xform(selected_verts, q=True, t=True, ws=True)
    
            # unpack the flat list of [x,y,z,x,y,z...] into 3 lists of [x,x], [y,y], etc...
            x1 = _old_positions[::3]
            y1 = _old_positions[1::3]
            z1 = _old_positions[2::3]
    
            x2 = new_positions[::3]
            y2 = new_positions[1::3]
            z2 = new_positions[2::3]
    
    
            old_verts = zip(x1, y1, z1)
            new_verts = zip(x2, y2, z2)
    
            # compare the old positions and new positions side by side
            # using enumerate() to keep track of the indices
            for idx, verts in enumerate(zip (old_verts, new_verts)):
                old, new = verts
                if old != new:
                    # you'd replace this with the HUD printing code
                    print idx, ":", new[0] - old[0],  new[1] - old[1], new[2] - old[2]
    
            # store the new positions for next time
            _old_positions = new_positions
    
    
    #activate the script job and prime it
    cmds.scriptJob(ac= ('pCubeShape1.outMesh', update_mesh_positions))
    cmds.select('pCubeShape1')
    update_mesh_positions()
    # force an update so the first move is caught
    

This isn't really something Maya is good at doing via script: on big meshes
this will be pretty slow since you're processing a lot of numbers. For small
examples it should work though.

