On 18/04/2016 at 11:33, xxxxxxxx wrote:
Hi Tanzola,
I just want to double check, we are talking about the Python Generator here, right?
The following explanations apply, if the answer is yes.
In general the Python Generator is very much like an ObjectData plugin with the Python script running in GetVirtualObjects(). So, as mentioned before in this thread, all the constraints that apply to GVO are also true for the Python Generator. Most important, you are not allowed to do any changes to the scene. Instead you are generating an object (this may also be an object hierarchy), optionally based on (user data) parameters of your Python Generator, and this object will be returned in the end of your Python script. Cinema will take care of the insertion into the scene, so you neither have to, nor should you do this on your own (remember, no changes to the scene).
Let's quickly walk through your code:
try: doc.SearchObject("Spline").Remove()
except: pass
You are not allowed to do this, nor is there a need to do so. Cinema takes care of this, actually you are rebuilding the same object in your Python Generator script.
spline = c4d.SplineObject(2, c4d.SPLINETYPE_LINEAR)
pts = [c4d.Vector(), c4d.Vector(0, 200, 0)]
spline.SetAllPoints(pts)
Almost all fine and dandy, in the end you will return this spline.
Be aware of the note on SetAllPoints() it needs to be followed by a MSG_UPDATE, like so:
spline.Message(c4d.MSG_UPDATE)
doc.InsertObject(spline)
c4d.EventAdd()
Again, you are not allowed to do this. Neither the object insertion, nor the EventAdd(). And you don't need it, either, as Cinema will take care of inserting your spline into the scene, when you are returning it at the end of your script.
bs = doc.SearchObject("Spline").GetPointS()
print bs.GetAll(2)
No need to search for the spline, you just created it, so simply use it. You want to select a point, do it like this:
bs = spline.GetPointS()
bc.Select(1) # to select the second point in your spline
And then in the end:
return spline
So your script should actually look like this:
import c4d
def main() :
spline = c4d.SplineObject(3, c4d.SPLINETYPE_LINEAR)
pts = [c4d.Vector(), c4d.Vector(0, 200, 0), c4d.Vector(200, 200, 0)]
spline.SetAllPoints(pts)
spline.Message(c4d.MSG_UPDATE)
bs = spline.GetPointS()
bs.Select(1) # select the second point
return spline
As said in the beginning, you can also generate object hierarchies and you can also add tags to the generated objects.
I hope this helps a bit.