Interactive Python

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

markluffel
Posts: 13
Joined: Sun Oct 20, 2002 12:16 am
Location: Georgia Tech, Atlanta
Contact:

Interactive Python

Postby markluffel » Sun Oct 20, 2002 1:44 am

An interactive python mode for blender would be great.

I often start the python interpreter while testing a script to check a code stub without executing the entire thing. There is no direct way to do this in blender. Adding a 'terminal' window mode to blender seems like the obvious solution, but perhaps there is something more elegant.

Besides allowing testing of scripts this creates a command-line-interface for blender that would handle repetitive but single use actions like...

Code: Select all

for bone in skeleton:
  if bone.x > 0:
    bone.name = 'r'+bone.name
  else:
    bone.name = 'l'+bone.name

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

Postby theeth » Sun Oct 20, 2002 5:52 am

I usually use a dummy script to do that kind of things, but yes, a command line window could be very useful.

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

joonas
Posts: 2
Joined: Wed Oct 16, 2002 12:54 pm

Postby joonas » Tue Oct 22, 2002 12:17 pm

This code snippet creates a simple Python shell to the Blender console. It handles neither multi-line statements nor exceptions, but creating a fully compatible shell is not a problem. Anyway, I don't know if this solves your problem.

Code: Select all

while 1:
    try:
        try:
            s = raw_input('>>> ')
        except EOFError:
            print
            break
        if s and s[0] != '#':
            s = s + '\n'
            c = compile(s, '<stdin>', 'single')
            exec c
    except:
        raise


- Joonas

markluffel
Posts: 13
Joined: Sun Oct 20, 2002 12:16 am
Location: Georgia Tech, Atlanta
Contact:

Console vs Terminal

Postby markluffel » Thu Oct 24, 2002 6:06 am

To get a console window in MacOS X you must call Blender from the command line. Something like:
/Applications/BlenderPublisher.app/Contents/MacOS/blenderpublisher
You could also create a link to the executable and name it "blender" for easy access. Say:
ln /Application/...publisher ~/blender.
I also edited the script:

Code: Select all

import traceback
while 1:
  try:
    try:
      s = raw_input('>>> ')
    except EOFError:
      print traceback.print_exc()
      break
    if s == 'exit':
      break
    if s and s[0] != '#':
      s = s + '\n'
      exec compile(s, '<stdin>', 'single')
  except:
    print traceback.print_exc()

It would be elegant if there was a toggle button on the script window that executed a script after it was selected in the drop-down menu. This would make selecting GUI scripts (or this console hack) like selecting a window mode. I think it would be consistent with the rest of the interface.[/code]


Return to “Python”

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests