On 31/12/2016 at 16:07, xxxxxxxx wrote:
I am trying to develop a python script that will allow me to make a single knife cut across an individual polygon surface.
I am able to do this manually using the knife tool set to Line mode with "Restrict to Selection" enabled.
I am able to make a knife cut across the surface using a Python script, however I am unable to select any of the specific knife parameters that would allow me to restrict the cut to a single polygon surface (for example the knife mode and restrict to selection option).
The code below makes a cut across a cube. This is adapted from the very helpful code example provided by Yannick Puech
import c4d
from c4d import utils
def SplineCutter(doc, op, bd, x1, y1, x2, y2, bSelect) :
p1 = c4d.Vector(-50,200,-100)
v1 = c4d.Vector(-50,200,-400)
p2 = c4d.Vector(-50,-200,-100)
v2 = c4d.Vector(-50,-200,-400)
bc = c4d.BaseContainer()
bc.SetVector(c4d.MDATA_KNIFE_P1, p1)
bc.SetVector(c4d.MDATA_KNIFE_P2, p2)
bc.SetVector(c4d.MDATA_KNIFE_V1, v1)
bc.SetVector(c4d.MDATA_KNIFE_V2, v2)
bc.SetBool(c4d.MDATA_KNIFE_RESTRICT,True)
bc.SetBool(c4d.MDATA_KNIFE_NGONS, True)
bc.SetLong(c4d.MDATA_KNIFE_MODE, c4d.MDATA_KNIFE_MODE_LOOP)
if op is not None :
utils.SendModelingCommand(command = c4d.MCOMMAND_KNIFE,
list = [op],
mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
bc = bc,
doc = doc,
flags = c4d.MODELINGCOMMANDFLAGS_CREATEUNDO)
c4d.EventAdd()
def main() :
frame = doc.GetTime().GetFrame(doc.GetFps())
if frame == 10:
bd = doc.GetActiveBaseDraw()
frame = bd.GetFrame()
middleX = (frame['cr']-frame['cl'])/2
spline = op.GetObject()
SplineCutter(doc, spline, bd, middleX, frame['ct'], middleX, frame['cb'], True)
if __name__=='__main__':
main()
However the below lines of code don't actually seem to have any effect:
bc.SetBool(c4d.MDATA_KNIFE_RESTRICT,True)
bc.SetBool(c4d.MDATA_KNIFE_NGONS, True)
bc.SetLong(c4d.MDATA_KNIFE_MODE, c4d.MDATA_KNIFE_MODE_LOOP)
There is no effect when I change MDATA_KNIFE_RESTRICT from True to False. Either way the cut is not restricted to the polygon surface.
There is no effect when I set c4d.MDATA_KNIFE_MODE to c4d.MDATA_KNIFE_MODE_SINGLE or c4d.MDATA_KNIFE_MODE_PATH or c4d.MDATA_KNIFE_MODE_LOOP. The cut mode always remains the same.
As a separate, but related question, setting "command = c4d.ID_MODELING_KNIFE_TOOL" instead of "command=c4d.MCOMMAND_KNIFE" (a format that works with other modeling commands such as c4d.ID_MODELING_EXTRUDE_TOOL) makes the knife cut stop working all together.
I am using c4D R2017
Any ideas about how to actually set KNIFE_RESTRICT to True and actually set MDATA_KNIFE_MODE to Single would be helpful!