Development question

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Development question

Post by Money_YaY! »

I was reading on and on about how Python is a nice friendly app lang that is very much easier to code in without a weak water down of power.

So my question then is, is python capable to code parts of blender as hard code instead of just scripts ? Like making particles and other advansed stuff ?

Of course I can not code yet, stilll stacking it down, but Python reading was some much eaiser for me when I stare at it, and plusses it is OOPs method, so I hear that is a very good method for structre and code preformance.

ideasman
Posts: 0
Joined: Tue Feb 25, 2003 2:37 pm

Post by ideasman »

You can code tools that are included in menu's accessable from the python UI. as well as write programs that use a window to display their GUI, but you cant realy intergrte python code into blender... it just dosent work that way.

kitsu
Posts: 0
Joined: Sun Jun 06, 2004 8:08 am

Post by kitsu »

If you can write a partical system then you can write a partical system in python. The python API provides access to most of Blender's existing functionality, and is also a complete programming language besides.

The main limit is that you can't change Blenders existing behavior. For instance you cannot write a new shader to go with blinn and phong etc. You can't re-write the way armatures work. In theory though you could create a new armature system implimented in python, but it might be a bit clumsy.

I would encourage you to try writing some scripts in Python. The Blender-Python-API documentation is getting better all the time, plus trying things in python will give you a better idea of how blender organizes data. Besides Python is fun, easy, and useful even outside of Blender.

ideasman
Posts: 0
Joined: Tue Feb 25, 2003 2:37 pm

Post by ideasman »

Its worth noting that it inst hard to add bpython features, often they only need to be hooks to existing functions.

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! »

Ok discourging words ,. Can python draw a vertice at the very least ?
I was hopeing that I could use it to make a few large things.

Ugh, back to learning C then.

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

Re: Development question

Post by theeth »

Money_YaY! wrote:So my question then is, is python capable to code parts of blender as hard code instead of just scripts ? Like making particles and other advansed stuff ?
I still don't understand what you see as a problem between "hard code" and "just script" (which kinda sound pejorative), but http://www.centralsource.com/blender/dynamica/

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

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Re: Development question

Post by Money_YaY! »

theeth wrote:
Money_YaY! wrote:So my question then is, is python capable to code parts of blender as hard code instead of just scripts ? Like making particles and other advansed stuff ?
I still don't understand what you see as a problem between "hard code" and "just script" (which kinda sound pejorative), but http://www.centralsource.com/blender/dynamica/

Martin
Aw I have not seen this one in a while. Why did you stop it ? Was there a great deal of complications to it ? Was it all just hacks and stuff ? Or did you just simply lose intrest ?

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

Post by theeth »

I didn't loose interest, I just don't have time for a long term project like this anymore. It's still something that interests me, which is why I try to help Leon with his particles code as much as possible (currently, that`s pretty much just reviewing the code though). Not much tecnical problems either. There was some, but most would not be a problem with the current API.

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

kitsu
Posts: 0
Joined: Sun Jun 06, 2004 8:08 am

Post by kitsu »

Quote:

> Ok discourging words ,. Can python draw a vertice at the very least ?
> I was hopeing that I could use it to make a few large things.

Like I said the API doc is very useful. Look under Blender.org -> documentation -> Blender 2.33 Python API reference -> NMesh

This is the module used to control mesh objects i.e. vertices and faces. Bpython also gives you access to meta-balls, curves, cameras, materials etc.

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! »

Ok then questions some more. It can make or at least edit the particles, this is good.

I have seen a good deal of Opengl works from it, though not grand , And I have yet to see a modeling program from it.

Ok second question, why can the scripts not update the 3d view in real time ? Like when making the grass from a fiber script why can the sliders not show a live preview when pshing a slider ?

Or the displacment paint script same deal. And if it is a script problem is it reverseable ?

kitsu
Posts: 0
Joined: Sun Jun 06, 2004 8:08 am

Post by kitsu »

My guess would be its is just the way they wrote their scripts. I always Redraw() when I finish changing geometry. I would bet with these scripts no geometry is generated until you hit create/whatever. Try this:

Make a scene with a cube in it named 'Cube' (I'm too lazy to write a cube, and 'Cube' should be the default name for a new mesh>cube).

Code: Select all

from Blender import *

cube = Object.Get('cube')
cube.setLocation(0,0,20)
Redraw()

done = 0
while not done:
    cube.LocZ -= -.05
    Redraw()
    if cube.LocZ <= 0:
        done = 1
This animation cannot be rendered as it is realtime, but you could set some Ipo curves and make it renderable. You can do this kind of realtime transformation with anything python has access to, from objects to vertices and curves. I'm not sure why more scripts don't dynamicaly display there output except for speed concerns...

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! »

Sadly all that does is puts blender into a non working blender. Is there a way to make it stop with ESCAPE ?

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! »

I did try this

Code: Select all

from Blender import *

cube = Object.Get('cube')
cube.setLocation(0,0,20)

done = 0
while not done:
	cube.LocZ -= -.05
	Redraw()
	if cube.LocZ <= 0:
		done = 1
		
def event(evt, val): 
	if (evt== QKEY and not val):
		Exit()

def bevent(evt):
	if   (evt== 1):
		Exit()
	elif (evt== 3):
		main()
		Redraw()
But no go.

kitsu
Posts: 0
Joined: Sun Jun 06, 2004 8:08 am

Post by kitsu »

How you say "DOH!"?

In the while loop I am decrimenting a negitive number...

1 - (-1) = 2

This creates an infinite lop hence the freeze....

To fix either change

cube.LocZ -= -.05 to
cube.LocZ += -.05

or -.05 to .05...

Also if a script freezes Blender on you I think you can alt-tab over to the console and hit ctrl-c, that should kill the script without stopping blender... oops :roll:

z3r0_d
Posts: 289
Joined: Wed Oct 16, 2002 2:38 am
Contact:

Post by z3r0_d »

kitsu wrote:Also if a script freezes Blender on you I think you can alt-tab over to the console and hit ctrl-c, that should kill the script without stopping blender... oops :roll:
and to quit a script with a ui the shortcut [in the blender window] is control+alt+shift+q

Post Reply