Hi All,
I am trying to do something simple with python.
I want to write a script that creates a circle, a lamp, changes the circle’s type to path, append a constraint to the lamp and make the path be the circle I just created.
The net result is I run the script and a lamp moves in a circle when the time changes.
Here is what I have:
This code works for me and makes a lamp with a constrint, but how do I tell the constraint what path to follow?
I assume something like this is needed:
tempFollowPath.setName ("Curve")
After reading the DOCs I can find no way to set the path of a followpath constraint. Is this possible in version 2.42?
I am working on it, and I’ll post it here.
But I need to know how to create a circle now?
Something like this…
curveObject = Blender.Curve.New('NewCurve')
I know that code is wrong, I wish Blender had the feature like 3DSMax and Maya where you could perform operations in the IDE and see the resulting python code in the console. That helps a lot when learning a new language. I would consider that an excellent feature to add to Blender. Some kind of checkbox called “echo to console”…:rolleyes:
I agree, that would be a fabulous feature, especially since Blender’s python documentation is very weak compared to Max’s / Maya’s. I’ve been slowing experimenting and learing MEL, and there is an EXAMPLE for almost every command.
That would be a very interesting programming exercise.
Well this example code is in the Curve Module docs … but it appears to be incomplete or have errors in it.
“bezList2Curve” is never referenced after it’s defined
“bezier_vecs” isn’t defined anywhere.
So I can’t figure out how to run it.
Mike
from Blender import *
def bezList2Curve(bezier_vecs):
'''
Take a list of vector triples and converts them into a bezier curve object
'''
def bezFromVecs(vecs):
'''
Bezier triple from 3 vecs, shortcut functon
'''
bt= BezTriple.New(vecs[0].x, vecs[0].y, vecs[0].z,vecs[1].x, vecs[1].y, vecs[1].z, vecs[2].x, vecs[2].y, vecs[2].z)
bt.handleTypes= (BezTriple.HandleTypes.FREE, BezTriple.HandleTypes.FREE)
return bt
# Create the curve data with one point
cu= Curve.New()
cu.appendNurb(bezFromVecs(bezier_vecs[0])) # We must add with a point to start with
cu_nurb= cu[0] # Get the first curve just added in the CurveData
i= 1 # skip first vec triple because it was used to init the curve
while i<len(bezier_vecs):
bt_vec_triple= bezier_vecs[i]
bt= bezFromVecs(bt_vec_triple)
cu_nurb.append(bt)
i+=1
# Add the Curve into the scene
ob= Object.New('Curve')
ob.link(cu)
scn= Scene.GetCurrent()
scn.link(ob)
ob.Layers= scn.Layers
return ob
Did you forget to put a smiley on that end of that message? :rolleyes:
You’re probably the most qualified person, and I imagine you could write something in about 3 minutes that would take the rest of of a week to figure out … if at all
Hey Mike_S, A problem is that there are around 2-4 people activly working on the C/Python API and its documentation.
Its at a point where any of us could make 1 change, example, whatever fairly easily but theres so many examples and areas for improvement that what with fixing unmaintained python scripts, keeping up with changes in blender and fixing bugs in the API its self, we dont get time to do the finer details.
So in short, having others contribute examples would be a great start and may also lead to others making larger contributions and being involved with the community.
Atom, dont be. The python API generaly isnt that high level (exception of Mesh). that kinda things best added in as a generic function, write once, use everywhere.
I was hoping for a little more than “write it”?
So write it in what language?
Can I write a python script and it can get embedded in Blender?
Do I need C? Is there an SDK that shows how to do this?
Is there an example somewhere that shows how to create a new function for the API?
Is there some deffinition of what the patch tracker is? Where is it located? How do I use it or download it or integrate with it?
Hi atom, can you start a new thread from the questions above maybe “Extending Blender/Python API” or whatever, this is not anything todo with this thread really…
your questions are valid and should be answered but the people who may benefit from the answer wont find them if its discussed here.
For examples, AFAIK, blender uses the same “python-embed” process as any other C based program, so the generic “extending API” instructions found in the Python help and elsewhere on the web would probably work … but I’m not positive.
Reading the commit logs, and looking for another instance where an API function was added is probably the real only source of documentation you’ll find. Joining the IRC #blendercoders channel and asking other programmers questions is your best source of info.
There is no “manual / roadmap” to coding / extending Blender. It’s actually pretty amazing that people other than Ton are able to code and extend the program, as the internals are basically not documented. The source code is the documentation
I think you face a daunting, but not totally impossible task