"""
HB_CenterCut V1.0

Last Modified: 6/25/2015
Works with CINEMA 4D R16.050 and up.
Copyright: Holger Biebrach, www.c4dstuff.com

Name-US: HB_CenterCut
Description-US: Activates Edge-mode and sets up Knife-Tool to do loopcuts with Midpointsnapping

Activates Edge-mode and sets up Knife-Tool to do loopcuts. Also Midpoint-Snapping will be activated.
This way you can make cuts at the center of Edges easily.

Video Tutorial:
https://youtu.be/Ki6I9sRdeUU?t=13m12s

Name-DE: HB_CenterCut
Description-DE: Aktiviert Kanten Mode und Knifetool mit Loop Modus und Snapping

ChangeLog:
6/11/2015 Release Version

"""

import c4d
from c4d.modules import snap
from c4d import documents, plugins

def tool():
    return c4d.plugins.GetToolData(doc, doc.GetAction())

def main():
    
    
    
    #Knifetool Setup
    c4d.CallCommand(16351) # Edges
    c4d.CallCommand(1016030) # Knife
    tool()[c4d.MDATA_KNIFE_MODE]=2
    tool()[c4d.MDATA_KNIFE_RESTRICT]=False
    tool()[c4d.MDATA_KNIFE_SELECTCUTS]=True
    
    
    
    #Snapping
    if not (c4d.IsCommandChecked(440000121)):
        c4d.CallCommand(440000121) # Snapping on
    
    c4d.CallCommand(c4d.SNAP_SETTINGS_3D)
    
    snap.EnableSnap(False, doc, c4d.SNAPMODE_POINT)
    snap.EnableSnap(True, doc, c4d.SNAPMODE_EDGE)
    snap.EnableSnap(False, doc, c4d.SNAPMODE_POLYGON)
    snap.EnableSnap(False, doc, c4d.SNAPMODE_SPLINE)
    snap.EnableSnap(False, doc, c4d.SNAPMODE_AXIS)
    snap.EnableSnap(False, doc, c4d.SNAPMODE_INTERSECTION)
    snap.EnableSnap(True, doc, c4d.SNAPMODE_MIDPOINT)
    snap.EnableSnap(False, doc, c4d.SNAPMODE_WORKPLANE)
    snap.EnableSnap(False, doc, c4d.SNAPMODE_GUIDE)
    
    
    
    
    c4d.EventAdd()

if __name__=='__main__':
    main()
