"""
HB_Rotate V1.0

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

Name-US: HB_Rotate
Description-US: Rotate Tool [SHIFT-CLICK: Enable Quantize Snapping]

This Script does following things:
- Enables the Rotate Tool
- Show Axis if hidden
- Disable Quantize Snapping if enabled 

- Shift-Click: Enable Quantize Snapping and set it to 45 Degree for Rotation

Video Tutorial:
https://youtu.be/eEcAttV56kE?t=21m


Name-DE: HB_Rotate
Description-DE: Rotieren Tool [SHIFT-CLICK: Aktiviere Quantize Snapping]

ChangeLog:
6/11/2015 Release Version

"""

import c4d, math, c4d.utils
from c4d.modules import snap

def main():
    
    bc = c4d.BaseContainer()
    if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.BFM_INPUT_CHANNEL,bc):
        
        if bc[c4d.BFM_INPUT_QUALIFIER] ==0 :
            
            c4d.CallCommand(200000090) # Rotate
            
            if (snap.IsQuantizeEnabled(doc)):
                c4d.CallCommand(c4d.QUANTIZE_ENABLED)
            
            snap.SetQuantizeStep(doc, None, c4d.QUANTIZE_ROTATE,c4d.utils.Rad(10))
            if not (c4d.IsCommandChecked(1016176)):
                c4d.CallCommand(1016176) # Show Axis
                
        if bc[c4d.BFM_INPUT_QUALIFIER] ==1 : # Shift-Click
            
            c4d.CallCommand(200000090) # Rotate
            
            if not (snap.IsQuantizeEnabled(doc)):
                # Enable quantizing if not activated
                c4d.CallCommand(c4d.QUANTIZE_ENABLED)
            
            if not (c4d.IsCommandChecked(1016176)):
                c4d.CallCommand(1016176) # Show Axis
       
            snap.SetQuantizeStep(doc, None, c4d.QUANTIZE_ROTATE,c4d.utils.Rad(45))

            
if __name__=='__main__':
    main()
    c4d.EventAdd()
