python c4d animating
-
On 03/08/2018 at 09:32, xxxxxxxx wrote:
Hi Yaroslav,
if I understand your request correctly (not completely sure, though), then a script is probably not your best choice. With a script you'd be able to set up a spline, also add maybe a user data parameter for your independent time, but you'd also need to add some kind of business logic to make the spline react to that user data parameter. Perhaps by adding an Xpresso tag with the script. But this all in all seems unnecessarily complicated to me.
The Python generator is also not well suited for generating splines, it's made for objects.
Instead I'd suggest to implement an ObjectData plugin as spline generator (OBJECT_GENERATOR and OBJECT_ISSPLINE). With this you can add parameters as needed and during spline generation in GetContour() you can react to these parameters accordingly.
Take a look at the Py-DoubleCircle example to get a better idea.
-
On 04/08/2018 at 14:29, xxxxxxxx wrote:
Oh, Andreas, thanks a lot, I'll look though objectData plugin then and this spline generator! Hopefully it will help me. I'll get back to you once I either succeed (fingers crossed) or I have more intelligent question.
-
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?
Yaroslav. -
On 08/08/2018 at 02:33, xxxxxxxx wrote:
Hi,
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) op.Message(c4d.MSG_UPDATE) 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", g=DoubleCircleData, description="Oanyfont", icon=bmp, info=c4d.OBJECT_GENERATOR|c4d.OBJECT_ISSPLINE)
Of course, I added the corresponding line into .str file:
STRINGTABLE Oanyfont { Oanyfont "Double Circle"; PYCIRCLEOBJECT_RAD "Radius"; **PYCIRCLEOBJECT_TIME "Time";** }
.res file:
CONTAINER Oanyfont { NAME Oanyfont; INCLUDE Obase; GROUP ID_OBJECTPROPERTIES { REAL PYCIRCLEOBJECT_RAD { UNIT METER; MIN 0.0; } **REAL PYCIRCLEOBJECT_TIME { UNIT METER; MIN 0.0; }** } }
and .h file:
#ifndef _Oanyfont_H_ #define _Oanyfont_H_ enum { PYCIRCLEOBJECT_RAD = 1001, **PYCIRCLEOBJECT_TIME = 1002** }; #endif
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 linebc = op.GetDataInstance() bc.GetReal(c4d.PYCIRCLEOBJECT_RAD)
Now my GetDataInstance() should contain the information about two real variables:
PYCIRCLEOBJECT_RAD and PYCIRCLEOBJECT_TIMEhow do I extract each of those (both are controlled by the user)?
Thanks for all your help!
Yaroslav.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
[URL-REMOVED] again to see how to add code tags.
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 13/08/2018 at 09:53, xxxxxxxx wrote:
Dear Andrias,
thank you so much!!
What a relieve!
Andbc.GetReal(c4d.PYCIRCLEOBJECT_TIME)
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?
Yaroslav. -
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.
While polishing it I encountered the following problem.
I can't control the initial placement of my text from the python plugin.like:
class DoubleCircleData(plugins.ObjectData) : data = node.GetDataInstance() data.SetVector(c4d.ID_BASEOBJECT_REL_POSITION,c4d.Vector(10,20,30)) 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 functiondef 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) b0=c4d.BaseObject(c4d.Onull) bc = op.GetDataInstance() xcoord = bc.GetVector(c4d.ID_BASEOBJECT_REL_POSITION)[0] ycoord = bc.GetVector(c4d.ID_BASEOBJECT_REL_POSITION)[2] bp=self.MyObject(xcoord,ycoord) 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?
Yaroslav. -
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().