Calculator script?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
calli
Posts: 38
Joined: Wed Oct 16, 2002 10:59 am
Contact:

Calculator script?

Post by calli » Fri Nov 26, 2004 1:27 pm

Hi,

often I need some quick calculations while blending.

Is there already a python script providing a calculator?

Too bad I have no time to implement one.

Regards,
Carsten

theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Post by theeth » Fri Nov 26, 2004 2:11 pm

You could just do it interactly (sort of).

Code: Select all

form math import *
at the top of the script and then just type in the equations like this

Code: Select all

print cos(0.5) + 0.2 + log(10)
(not sure if log exists, but you get the idea).

Then run the script and look in the console.

Primitive, but it works.

Martin
Life is what happens to you when you're busy making other plans.
- John Lennon

calli
Posts: 38
Joined: Wed Oct 16, 2002 10:59 am
Contact:

Post by calli » Fri Nov 26, 2004 2:36 pm

@theeth: Sure but thats much more complicated than starting a calculator (xcalc or Windows whatever) and switching programms ;-)

Regards,
Carsten

halibut
Posts: 0
Joined: Fri Apr 25, 2003 2:02 pm
Contact:

Post by halibut » Fri Nov 26, 2004 4:47 pm

It would be really nice if you could enter such calculations straight in to number buttons and then have them evaluated when you press enter. I tried to look in to the code to do this myself but I couldn't work it out :?

ilac
Posts: 131
Joined: Mon Oct 14, 2002 8:24 am

Post by ilac » Fri Nov 26, 2004 8:21 pm

halibut wrote:It would be really nice if you could enter such calculations straight in to number buttons and then have them evaluated when you press enter. I tried to look in to the code to do this myself but I couldn't work it out :?
Like in Macromedia freehand! that is a really practical and useful means of updating info in num buttons!

halibut
Posts: 0
Joined: Fri Apr 25, 2003 2:02 pm
Contact:

Post by halibut » Sat Nov 27, 2004 12:01 am

ilac wrote:
halibut wrote:It would be really nice if you could enter such calculations straight in to number buttons and then have them evaluated when you press enter. I tried to look in to the code to do this myself but I couldn't work it out :?
Like in Macromedia freehand! that is a really practical and useful means of updating info in num buttons!
#

bah! they stole my idea :D

fligh
Posts: 31
Joined: Mon Dec 30, 2002 11:28 pm
Location: US

Post by fligh » Sat Nov 27, 2004 2:21 am

http://come.to/project5/mathter

Stick the script in a text window and it'll run in the console. Or you can run it as a standalone.

%<

oyster
Posts: 0
Joined: Sat Mar 29, 2003 4:41 pm
Contact:

Post by oyster » Sat Nov 27, 2004 4:43 am


jms
Posts: 33
Joined: Sat Oct 19, 2002 3:04 pm

Post by jms » Sun Nov 28, 2004 11:14 am

Code: Select all

import Blender
from Blender.Draw import *
from Blender.BGL import *
from math import *

datastring=Create('0+0')

def gui():
  global datastring
  glClearColor(0.5,0.5,0.5, 0.0)
  glClear(GL_COLOR_BUFFER_BIT)
  Button("Exit", 1, 310, 10, 80, 19)
  glRasterPos2i(10, 100)
  Text("Calculator")
  datastring= String("Enter : ", 2, 10, 70, 380, 19, datastring.val, 70)
  glRasterPos2i(20, 50)
  Text("Result : "+str(eval(datastring.val)))

def event(evt, val):
  if (evt== QKEY and not val): Exit()
  Blender.Redraw()

def bevent(evt):
  if   (evt ==  1): Exit()
  Blender.Redraw()

Register(gui,event,bevent)
Zoo-3D.Blender, Ze French-Speaking Community SKB My french book about Blender.

ilac
Posts: 131
Joined: Mon Oct 14, 2002 8:24 am

Post by ilac » Sun Nov 28, 2004 11:42 am

jms wrote:

Code: Select all

import Blender
from Blender.Draw import *
from Blender.BGL import *
from math import *

datastring=Create('0+0')

def gui():
  global datastring
  glClearColor(0.5,0.5,0.5, 0.0)
  glClear(GL_COLOR_BUFFER_BIT)
  Button("Exit", 1, 310, 10, 80, 19)
  glRasterPos2i(10, 100)
  Text("Calculator")
  datastring= String("Enter : ", 2, 10, 70, 380, 19, datastring.val, 70)
  glRasterPos2i(20, 50)
  Text("Result : "+str(eval(datastring.val)))

def event(evt, val):
  if (evt== QKEY and not val): Exit()
  Blender.Redraw()

def bevent(evt):
  if   (evt ==  1): Exit()
  Blender.Redraw()

Register(gui,event,bevent)
Nice! :shock:
Thanks! :D

BILL
Posts: 0
Joined: Thu Oct 17, 2002 10:40 pm

Post by BILL » Sun Nov 28, 2004 2:30 pm

jms wrote:

Code: Select all

import Blender
from Blender.Draw import *
from Blender.BGL import *
from math import *

datastring=Create('0+0')

def gui():
  global datastring
  glClearColor(0.5,0.5,0.5, 0.0)
  glClear(GL_COLOR_BUFFER_BIT)
  Button("Exit", 1, 310, 10, 80, 19)
  glRasterPos2i(10, 100)
  Text("Calculator")
  datastring= String("Enter : ", 2, 10, 70, 380, 19, datastring.val, 70)
  glRasterPos2i(20, 50)
  Text("Result : "+str(eval(datastring.val)))

def event(evt, val):
  if (evt== QKEY and not val): Exit()
  Blender.Redraw()

def bevent(evt):
  if   (evt ==  1): Exit()
  Blender.Redraw()

Register(gui,event,bevent)
good

jms
Posts: 33
Joined: Sat Oct 19, 2002 3:04 pm

Post by jms » Sun Nov 28, 2004 2:49 pm

Nicer : with exception error handle :
http://jmsoler.free.fr/didacticiel/blen ... ulator.htm
Zoo-3D.Blender, Ze French-Speaking Community SKB My french book about Blender.

Post Reply