# How to precisely rotate 3D view using shortcut

**URL:** <https://discourse.slicer.org/t/how-to-precisely-rotate-3d-view-using-shortcut/34552>\
**Category:** Support\
**Tags:** 3d-model\
**Created:** [February 26, 2024, 8:15pm UTC](https://discourse.slicer.org/t/how-to-precisely-rotate-3d-view-using-shortcut/34552 "2024-02-26T20:15:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdboss](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kdboss/32/69492_2.png) [@kdboss](https://discourse.slicer.org/u/kdboss)\
**Post date:** [February 26, 2024, 8:15pm UTC](https://discourse.slicer.org/t/how-to-precisely-rotate-3d-view-using-shortcut/34552/1 "2024-02-26T20:15:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kdboss](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kdboss/32/69492_2.png) [@kdboss](https://discourse.slicer.org/u/kdboss)\
**Post date:** [February 27, 2024, 4:41pm UTC](https://discourse.slicer.org/t/how-to-precisely-rotate-3d-view-using-shortcut/34552/2 "2024-02-27T16:41:08Z")

</div>

Continuing the discussion from [How to precisely rotate 3D view using shortcut](https://discourse.slicer.org/t/how-to-precisely-rotate-3d-view-using-shortcut/34552):

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

```auto
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)

```
