python c4d animating

On 07/08/2018 at 10:52, xxxxxxxx wrote:

Dear Andreas, sorry for bothering your again.

Following your advice I'm making first steps for python object data plugin creation in c4d.  
The problem I'm facing at the moment is how to work with the plugin in debugging mode (or may be there exists a tutorial how to set this debugging mode up). There is a pyp file and the correct dir-structure. So far I understand this. I can copy the working files from examples and start modifying them. But how would I work with the plugin to see the results in console (like it is implemented in c4d  script manager)?
Is it possible at all?

On 08/08/2018 at 02:33, xxxxxxxx wrote:


I'm actually not quite sure what you mean. For Python there is no special debug mode. You can use print in a plugin in the same way you do in Script Manager and the output should appear in the Console.

On 12/08/2018 at 03:03, xxxxxxxx wrote:

Dear Andreas, I figured everything out.
Finally I got the sample doublecircle plugin working under my own plugin_id and ready to modify it.
Oh, the modification comes at a price )).
First of all I decided to include additional real control parameter (apart from radius of a double circle).
Here is what I added (in bold) :

import math
import sys
import os
import c4d
from c4d import bitmaps, gui, plugins, utils
PLUGIN_ID = 1041524
class DoubleCircleData(plugins.ObjectData) :
    """CircleObject Generator"""
    def Init(self, node) :
        data = node.GetDataInstance()
        **data.SetReal(c4d.PYCIRCLEOBJECT_TIME, 10.0)**
        data.SetReal(c4d.PYCIRCLEOBJECT_RAD, 200.0)
        data.SetLong(c4d.SPLINEOBJECT_SUB, 8)
        data.SetReal(c4d.SPLINEOBJECT_ANGLE, utils.Rad(5.0))
        return True
####        rad = data.GetReal(c4d.PYCIRCLEOBJECT_RAD)
    def GenerateCircle(self, rad) :
        sub = 4
        sn = 0
        TANG = 0.415
        op = c4d.SplineObject(sub*2, c4d.SPLINETYPE_BEZIER)
        if not op: return None
        op.MakeVariableTag(c4d.Tsegment, 2)
        op[c4d.SPLINEOBJECT_CLOSED] = True
        segc = op.GetSegmentCount()
        if segc>0:
            op.SetSegment(id=0, cnt=4, closed=True)
            op.SetSegment(id=1, cnt=4, closed=True)
        for i in xrange(sub) :
            sn, cs = utils.SinCos(2.0*math.pi*i/float(sub));
            op.SetPoint(i, c4d.Vector(cs*(rad),sn*rad,0.0))
            vl = c4d.Vector(sn*rad*TANG,-cs*(rad)*TANG,100.0)
            vr = -vl
            op.SetTangent(i, vl, vr)
            op.SetPoint(i+sub, c4d.Vector(cs*(rad),sn*rad,0.0)*0.5)
            vl = c4d.Vector(sn*rad*TANG,-cs*rad*TANG,100.0)*0.5
            vr = -vl
            op.SetTangent(i+sub, vl, vr)
	print segc
        return op
    def GetContour(self, op, doc, lod, bt) :
        bc = op.GetDataInstance()
        bp = self.GenerateCircle(bc.GetReal(c4d.PYCIRCLEOBJECT_RAD)) 
	print len(bc)
        if not bp: return None
        bb = bp.GetDataInstance()
        return bp
if __name__ == "__main__":
    path, file = os.path.split(__file__)
    bmp = bitmaps.BaseBitmap()
    bmp.InitWith(os.path.join(path, "res", "circle.tif"))
    plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="anyfont",
                                description="Oanyfont", icon=bmp,

Of course, I added the corresponding line into .str file:

	Oanyfont "Double Circle";

.res file:

	NAME Oanyfont;

and .h file:

#ifndef _Oanyfont_H_
#define _Oanyfont_H_
	 **PYCIRCLEOBJECT_TIME     = 1002**

and it doesn't work, The console gives:

File "'anyfont.pyp'", line 17, in Init
AttributeError: 'module' object has no attribute 'PYCIRCLEOBJECT_TIME'

Do you understand the reason for this?

And another rquestion I have is how to extract the value of this 'PYCIRCLEOBJECT_TIME' parameter.
As I see from code the author of the plugin extracts the radius of the circle with the line

bc = op.GetDataInstance()

Now my GetDataInstance() should contain the information about two real variables:

how do I extract each of those (both are controlled by the user)?

Thanks for all your help!

Edit: Added code tags

On 13/08/2018 at 09:38, xxxxxxxx wrote:

Hi Yaroslav,

I think, you ran into a known issue, when adding additional parameters at a later point in time.
Please try the following:
Start Cinema and open the preferences (menu: Edit -> Preferences...).
Click the button at the bottom to Open Preferences Folder.
Go into the prefs subfolder and delete the symbolcache file.
Restart Cinema 4D.

Accessing the additional parameter works exactly the same as for the first one:

bc = op.GetDataInstance()
radius = bc.GetReal(c4d.PYCIRCLEOBJECT_RAD)
time = bc.GetReal(c4d.PYCIRCLEOBJECT_TIME)

Please check the BBcodes again to see how to add code tags.

On 13/08/2018 at 09:53, xxxxxxxx wrote:

Dear Andrias, 
thank you so much!!
What a relieve!


worked like charm! )

On 19/08/2018 at 01:12, xxxxxxxx wrote:

Dear Andrias, the principal part of my plan succeeded (thanks to you!) and now I'm able to produce dynamic splines for the future plugin.
Take a look at c4d generated letter:

Now my question. I need to produce several splines one by one as user changes his time function.
Obviously, the user will want to write whole words. And producing several letters as one spline (though it is possible) doesn't seem to be right.

Obviously, what I'm doing is very close to MoText c4d plugin, albeit it is dynamic
As we know if we make Motext editable it will give several objects (one for each letter).
I want to implement a similar thing.

So how would I implement several splines? I tried to put several splines into GetContour method. But it seems it can produce only a single spline. Several GetContour functions doesn't seem to work.
Could you give me a piece of advice?

On 19/08/2018 at 16:39, xxxxxxxx wrote:

Oh, it seems that I partially solved the problem. At least now I can create letters as a list of splines (and then make a flowless extrude from it). Hopefully, the words will be decomposed in an equally elegant manner.

On 24/08/2018 at 06:11, xxxxxxxx wrote:

The MoText isn't actually a spline generator (OBJECT_ISSPLINE). If you make it editable, you see the structure it generates (as an OBJECT_GENERATOR), basically a bunch of extrudes with child splines. The point is, it doesn't behave as a spline, e.g. as input to a Loft.
I thought you were looking into creating a spline generator. A spline generator can only produce one single spline in GetContour(), however this spline may have multiple segments.

On 30/08/2018 at 13:01, xxxxxxxx wrote:

Dear Andrias, my plugin is almost ready. :slightly_smiling_face:
While polishing it I encountered the following problem.
I can't control the initial placement of my text from the python plugin.


class DoubleCircleData(plugins.ObjectData) :
       data = node.GetDataInstance()
       return True

This thing places it right at (0,0,0) !
No matter what I put in c4d.Vector !
Later or I try to control these coordinates with my final function

    def GetVirtualObjects(self,op, hierarchyhelp) :
        dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
        if dirty is False: return op.GetCache(hierarchyhelp)
        link = self.GetQuill(op)
        bc = op.GetDataInstance()
        xcoord = bc.GetVector(c4d.ID_BASEOBJECT_REL_POSITION)[0]
        ycoord = bc.GetVector(c4d.ID_BASEOBJECT_REL_POSITION)[2] 
        return bp

Naturally, xcoord and ycoord don't change when I try to move the object in a portview (and at some point it becomes crucial!)
What do I do wrong?
Could you please help me with some advice?

On 31/08/2018 at 08:35, xxxxxxxx wrote:

Hi Yaroslav,

I think, it's about time to open a separate thread for questions not really (or only loosely) related to the original post.

ID_BASEOBJECT_REL_POSITION actually relates to the Freeze Transformation, so that's not what you want.

You actually need to set the global matrix of your generated object (bp), either by SetMg() directly or with SetAbsPos().