I changed the script and added a BPY, how do I make it work? Here is the script:
#!BPY
“”"
Name:‘Rotation’
Blender:240
Group:‘Object’
Tooltip:‘rotate object’
“”"
import Blender
from math import pi,sqrt,cos,atan2,asin
X,Y,Z=0,1,2
EJE=Y
PREFIX=‘Roll’
def mat2euler(mat, size): # Algoritmo de eeshlo
scale = [0.0, 0.0, 0.0]
if size[0]!=0.0: scale[0] = 1.0/size[0]
if size[1]!=0.0: scale[1] = 1.0/size[1]
if size[2]!=0.0: scale[2] = 1.0/size[2]
angle_y = -asin(mat[0][2] * scale[0])
C = cos(angle_y)
if abs(angle_y)>1.0e-10:
C = 1.0/C
angle_x = atan2((mat[1][2] * scale[1]) * C, (mat[2][2] * scale[2]) * C)
angle_z = atan2((mat[0][1] * scale[0]) * C, (mat[0][0] * scale[0]) * C)
else:
angle_x = 0.0
angle_z = -atan2((mat[1][0] * scale[1]), (mat[1][1] * scale[1]))
return [angle_x, angle_y, angle_z]
def gtLoc(object):
mtx = object.matrix
return (mtx[3][0], mtx[3][1], mtx[3][2])
def ProdVectZ(v,w):
return v[0]*w[1]-v[1]*w[0]
for o in Blender.Object.Get():
if o.name[:len(PREFIX)]==PREFIX:
sc=Blender.Scene.getCurrent()
print “Processing object”,o.name
RADIO=o.size[2-EJE]
try:
oBuff=Blender.Object.Get('.Buff.'+o.name)
print " Recovering buffer info..."
L=oBuff.getLocation()
L0=L[0],L[1],L[2]
L=gtLoc(o)
oBuff.setLocation(L[0],L[1],L[2])
except AttributeError:
oBuff=Blender.Object.New('Empty')
oBuff.setName('.Buff.'+o.name)
print" Empty buffer not exist. Creating..."
sc.link(oBuff)
L=gtLoc(o)
oBuff.setLocation(L[0],L[1],L[2])
L0=oBuff.getLocation()
L1=gtLoc(o)
V=L1[0]-L0[0],L1[1]-L0[1],L1[2]-L0[2]
esp2=V[0]**2+V[1]**2+V[2]**2
ang=sqrt(esp2)/RADIO
s=ProdVectZ(o.mat[EJE],V)
if s>0: ang=-ang
if EJE==0:
o.RotX+=ang
elif EJE==1:
o.RotY+=ang
elif EJE==2:
o.RotZ+=ang