Hey folks,
I could need your help on building a Python Generator version of the Chamfer Tool. It's based on the Py-Parametric tools build by Andreas back in days. There were very helpful for setting up the generator. But here comes the issue:
Using GetAndCheckHierarchyClone does not work well with the MCOMMAND_CURRENTSTATETOOBJECT (at least this is what I think). When I test the plugin and use a Cloner with Splines under a Connect Object, it only affects the first clone. When I make the Connect Object editable, it works on all objects. See images.
When I bypass the dirty check and add replace "clone" by "op" in line 63 in the "GetVirtualObjects" method, than it works, but very badly.
I would appreciate any kind of help :)
import os
import c4d
from c4d import plugins, utils, bitmaps
###############################################################################################################
#Based on the Py-Parametric Tools by Andreas Block
###############################################################################################################
class ModelingCommandGeneratorModifier(plugins.ObjectData):
_toolId = -1
_doSelection = False
_selectId = -1
def InitCommon(self, toolId, doSelection, selectId):
self._toolId = toolId
self._doSelection = doSelection
self._selectId = selectId
def ExecModelingCommand(self, doc, opCtrl, op, parent):
if op is None:
return
splineObjects = []
if op.GetDown().CheckType(c4d.Ospline) is False:
splineObjects = utils.SendModelingCommand(command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
list = [op.GetDown()],
mode = c4d.MODELINGCOMMANDMODE_ALL,
bc = c4d.BaseContainer(),
doc = doc)
else:
splineObjects.append(op.GetDown())
if not splineObjects:
return
if splineObjects[0].CheckType(c4d.Ospline) is True:
res = utils.SendModelingCommand(command = self._toolId,
list = splineObjects,
mode = c4d.MODELINGCOMMANDMODE_ALL,
bc = opCtrl.GetDataInstance(), # settings,
doc = doc)
if res is True:
splineObjects[0].InsertUnderLast(parent)
def GetVirtualObjects(self, op, hh):
doc = op.GetDocument()
objInput = op.GetDown()
if objInput is None:
return None
objRet = c4d.BaseObject(c4d.Onull)
if doc is None or objRet is None:
return None
hierarchyClone = op.GetAndCheckHierarchyClone(hh, objInput, c4d.HIERARCHYCLONEFLAGS_NONE, True)
if hierarchyClone["dirty"] is False:
return hierarchyClone["clone"]
clone = hierarchyClone["clone"]
if clone is None:
return objRet
#When I replace "clone" to "op" and bypass the dirty checks, than it works but very sluggish
self.ExecModelingCommand(doc, op, clone, objRet)
return objRet
class ChamferGen(ModelingCommandGeneratorModifier):
def Init(self, op):
ModelingCommandGeneratorModifier.InitCommon(self, c4d.ID_MODELING_SPLINE_CHAMFER_TOOL, False, -1)
InitChamferDesc(self, op)
return True
def InitChamferDesc(inst, op):
inst.InitAttr(op, bool, [c4d.MDATA_SPLINE_CHAMFERFLAT])
inst.InitAttr(op, float, [c4d.MDATA_SPLINE_CHAMFERRADIUS])
op[c4d.MDATA_SPLINE_CHAMFERRADIUS] = 5.0
###############################################################################################################
# Plugin Registration
###############################################################################################################
PLUGIN_ID_GENERATOR = 9036026
def RegisterObjectData(id, name, bmpPath, objData, desc, flags):
bmp = bitmaps.BaseBitmap()
bmp.InitWith(os.path.join(bmpPath, "res", "icon.tif"))
plugins.RegisterObjectPlugin(id=id, str=name,
g=objData,
description=desc, icon=bmp,
info=flags)
if __name__ == "__main__":
path, fn = os.path.split(__file__)
RegisterObjectData(PLUGIN_ID_GENERATOR, "ChamferGen", path, ChamferGen, "ochamfergen", c4d.OBJECT_GENERATOR | c4d.OBJECT_INPUT)
print "ChamferGen 1.0 successfully initialized"