# # # # # # # # # # # # # # # # # # # # # # # # # # # #
#"VirtualUndo" version A1.02
# by Michael Thoenes and
# Jean-Michel Soler
#
# Thanks to: Bradley Berthold *nikolatesla20*
# for his Blender 2.14 GUI WIZARD script
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
###########################################################
# You need to have Object selected before you start the script
#
# Alt-P to run script, X to Exit
###########################################################
import Blender
from Blender.BGL import *
from Blender.Draw import *
# Get selected object
obj = Blender.Object.getSelected() [0]
location = repr(obj.loc)
back=0
# These are you button object global variables!
#Here is the main Draw() routine. All your drawing
#Should be done in this function.
def Draw():
# You must use the global keyword here to allow you to
modify
# a variable outside the scope of the function.
global Button1
global Button2
global Button3
global Button4
# Change this color according to what you like ;)
glClearColor(0.4,0.5,0.6 ,0.0)
glClear(GL_COLOR_BUFFER_BIT)
Blender.Draw.Button("Store",1,5,62,100,60, "Writes data
to text file")
Blender.Draw.Button("<Back",2,5,30,47,25, "Back")
Blender.Draw.Button("Fwd>",3,58,30,47,25, "Forward")
Blender.Draw.Button("Exit",4,5,5,100,20, "Exit")
glColor3d(0,0,0)
glRasterPos2i(5, 155)
Text("VirtualUndo A1.02")
glColor3d(0,0,0)
glRasterPos2i(5, 135)
Text("Obj Location Undo")
# Here is the main Window Event function.
# Right now it only has a exit key defined.
def Events(eventnum,eventmod):
if eventnum==Blender.Draw.XKEY:
Blender.Draw.Exit()
if eventnum==Blender.Draw.QKEY:
Blender.Draw.Exit()
if eventnum==Blender.Draw.ESCKEY:
Blender.Draw.Exit()
# These are the button Events handlers.
def ButEvent(butnum):
global back
if butnum==1:
# EVENT HANDLER FOR Button1
# Put your code in here to respond to
the event
# Converts obj.Loc to string for use
in write(Zlocation)
location = repr(obj.loc)+";"+repr(obj.rot)+";"+repr(obj.size)
print "Store Loc=", obj.loc
try:
out_file = open(obj.name+"Undo.txt",
"a")
out_file.write(location+'\n')
out_file.close
except:
out_file = open(obj.name+"Undo.txt",
"w")
out_file.write(location+'\n')
out_file.close
if butnum==2:
# EVENT HANDLER FOR Button2
# Put your code in here to respond to
the event
in_file = open(obj.name+"Undo.txt",
"r")
text = in_file.readlines()
in_file.close()
if back<len(text):back+=1
n=0
n=back+1
if n<=len(text):
print back
t=text[len(text)-n].split(';')
#print t
exec 'obj.loc,obj.rot,obj.size
= %s,%s,%s'%(t[0],t[1],t[2])
Blender.Redraw()
if butnum==3:
# EVENT HANDLER FOR Button3
# Put your code in here to respond to
the event
in_file = open(obj.name+"Undo.txt",
"r")
text = in_file.readlines()
in_file.close()
if back>0: back-=1
n=0
n=back+1;print 'back',back
if n<=len(text) and n>=0:
t=text[len(text)-n].split(';')
exec 'obj.loc,obj.rot,obj.size
= %s,%s,%s'%(t[0],t[1],t[2])
Blender.Redraw()
if butnum==4:
# EVENT HANDLER FOR Button4
# Put your code in here to respond to
the event
Exit()
# The Main Blender.Draw.Register() Call...
Blender.Draw.Register(Draw,Events,ButEvent) |