Setting The Target Of A Follow Constraint

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:


import Blender
object = Blender.Object.New('Lamp','sLamp')
l = Blender.Lamp.New('Spot','sSpot')
l.setMode ('Square','Shadows')
object.link(l)
tempFollowPath = object.constraints.append(4) #2=TrackTo, 3=IKSolver, 4=FollowPath
scene = Blender.Scene.GetCurrent()
scene.link(object)
Blender.Redraw()

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?

Hmm…no answer.

Ok, so does anyone know how to extend Blenders python support to allow the addition of a new property for the follow constraint?

http://members.optusnet.com.au/cjbarton/BPY_API/Constraint-module.html#Type

Under the Settings heading for the doc page that IdeasMan42 provided, is the TARGET item.

So :



obCurve = Object.Get('Curve')    # substitute 'Curve' for  whatever your path is called

obLamp = Object.Get('sLamp')

const = obLamp.constraints[0]

const[Constraint.Settings.TARGET] = obCurve


Or :


Object.Get('sLamp').constraints[0][Constraint.Settings.TARGET] = Object.Get('Curve')

Mike

Thanks,

I’m going to give that a try.:slight_smile:

Could sombody make a nice test script based on the code above and we can include in the Example docs?

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.

Mike

Well this example code is in the Curve Module docs … but it appears to be incomplete or have errors in it.

  1. “bezList2Curve” is never referenced after it’s defined

  2. “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 :smiley:

Mike

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.

Just take a look at the changelog since 2.42
http://projects.blender.org/pipermail/bf-committers/2007-January/017100.html

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.

Of course I didnt mean to be pushy :wink:

I’m suprised there is not a single line python command to create a bezier circle?

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.

Ok,
So how would I go about getting a function put in the API?

wright it and submit it to the patch tracker.

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.

You’d have to write it in C.

AFAIK you can’t embed python scripts in Blender.

There is no SDK.

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 :frowning:

I think you face a daunting, but not totally impossible task :smiley:

The commit logs are here :
http://projects.blender.org/pipermail/bf-blender-cvs/

The patch / bug tracker / to trackers are here :

http://projects.blender.org/tracker/index.php?func=detail&aid=4514&group_id=9

There are links to some “getting started” info for developing on the main Wiki page.

Mike

its not that hard to get your feet wet, but if your new and have no/little C experience then Python is the way to go.

If you write some functions that are usefull, I we include them with blender as default.

If your looking for an example, look in your scripts/bpymodules dir. Python scripts that do generic stuff can be added there