How to precisely rotate 3D view using shortcut

Hi, I’m an orthopedic trauma surgeon learning to use slicer for preoperative planning

I’m trying to use 3d slicer for preoperatively measure the angle for optimal c-arm imaging

I have learned about the code snippet that will show the rotation of 3D view from anther thread and I know the numpad 2 4 6 8 can rotate the 3d image by 15 degrees
I want a more fine-tune control of the rotation and I want to change the rotation one axis at a time using the numpad, read somewhere that the key binding function is hard-coded to the program

Is there any way I can change the binding of numpad to rotate the 3d view by 1 degree instead of 15 degrees?

Continuing the discussion from How to precisely rotate 3D view using shortcut:

After some searching around the forum, I found a way to do it making a shortcut key i j k l for pitch up down and yaw left and right with increment 1 degree for each button press by using this code snippet in the .slicerrc.py file

Will leave this here for future reference and anybody who have the same problem

layoutManager = slicer.app.layoutManager()
threeDView = layoutManager.threeDWidget(0).threeDView()
threeDView.setPitchRollYawIncrement(1)

def step_direction(direction = 'left'):
	if direction == 'left':
		threeDView.yawDirection = threeDView.YawLeft
		threeDView.yaw()
	if direction == 'right':
		threeDView.yawDirection = threeDView.YawRight
		threeDView.yaw()
	if direction == 'up':
		threeDView.pitchDirection = threeDView.PitchUp
		threeDView.pitch()
	if direction == 'down':
		threeDView.pitchDirection = threeDView.PitchDown
		threeDView.pitch()

shortcuts = [
	("j", lambda: step_direction('left')),
	("l", lambda: step_direction('right')),
	("i", lambda: step_direction('up')),
	("k", lambda: step_direction('down'))
	]

for (shortcutKey, callback) in shortcuts:
	shortcut = qt.QShortcut(slicer.util.mainWindow())
	shortcut.setKey(qt.QKeySequence(shortcutKey))
	shortcut.connect( "activated()", callback)
2 Likes