Script to align axis

old piece of code to rearrange orientation of the axis of mesh without moving the mesh.
i use the vect.py from martin strubel cos i’m bored to rewrite standard vector operations

#Realign Script
#
#Aout 2001
#[email protected]
#
#Choisir la source puis la cible, appuyer sur Alt+P, les axes de cible sont alignés sur ceux de source mais le mesh ne bouge pas.
#l'échelle ne joue pas
#
#
#Select Source then Cible, press Alt+p, Cible's axis are realigned with Source's axis but the mesh don't move.
#The rotation is size free
#
#Free for use with Blender
#



from Blender import Object, NMesh, Redraw
import vect
from math import *

def applyTransform(mesh,mat):
	for v in mesh.verts:
		vec = (v.co[0], v.co[1], v.co[2])
		vec = vect.matxvec(mat,vec)
		v.co[0], v.co[1], v.co[2] = vec[0], vec[1], vec[2]

def matrot(ob):
	vx=ob.mat[0]
	vy=ob.mat[1]
	vz=ob.mat[2]
	isizex=1/ob.size[0]
	isizey=1/ob.size[1]
	isizez=1/ob.size[2]
	matx=vect.scale3(isizex,vx)
	maty=vect.scale3(isizey,vy)
	matz=vect.scale3(isizey,vz)
	mat=(matx,maty,matz)
	return mat




oblist =Object.GetSelected()
lenob=len(oblist)

if lenob !=2:
	raise ValueError,'Select 2 objects'

cible=oblist[0]
source=oblist[1]


if source.rot!=cible.rot:
	rotcible=matrot(cible)
	rotsource=matrot(source)
	rotsourcet = vect.invmat(rotsource)
	mat=vect.matxmat(rotcible,rotsourcet)
	ncible=cible.name
	me=NMesh.GetRaw(ncible)
	applyTransform(me,mat)
	NMesh.PutRaw(me,ncible)
	cible.rot=source.rot


hope it could be useful