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 line
bc = op.GetDataInstance()
bc.GetReal(c4d.PYCIRCLEOBJECT_RAD)
Now my GetDataInstance() should contain the information about two real variables:
PYCIRCLEOBJECT_RAD and PYCIRCLEOBJECT_TIME
how do I extract each of those (both are controlled by the user)?
Thanks for all your help!
Yaroslav.
Edit: Added code tags