sidebar features
sidebar content

Go Back   Blender Artists Forums > General Forums > Python & Plugins

Reply
 
Thread Tools
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
For months I have been frustrated by my SonyVAIO inability to allow a USB numpad to coexist with a full QWERTY keyboard map. Then along came Ray Badstibner (AKA raymaxbad) who inspited me with his BpKeyboard.py script. I adapted his work to create the Laptop Numpad Script.

Save it as LapTopNumPad.py
Thanks,
Trevor Noble

#!BPY

"""
Name: 'LapTopNumPad'
Blender: 241
Group: 'System'
Tooltip: 'Virtual Laptop Numpad'
"""

__author__ = "Trevor Noble"
__version__ = "0.0.1"

__bpydoc__ = """\
LapTopNumPad.py 0.0.1

This script allows easy blending on laptops that do not support a USB numpad to co-exist with a fully QWERTY keybord such (e.g. Sony VAIO).

Use SHIFT and CTRL keys modifiers as with a normal Num Pad.

Thanks to Ray Badstibner (AKA raymaxbad) for creating the BpKeyboard.py script which I canabalised.

"""

#--------import modules--------
import Blender
from Blender import Window, Text, Draw, BGL
from Blender.Window import *
from Blender.Text import *
from Blender.Draw import *
from Blender.BGL import *


#--------do it--------
def go_short():
QHandle(id)
Window.RedrawAll()

#--------get 3d window--------
try: # get 3d area
area = Window.GetScreenInfo(Window.Types.VIEW3D, rect='total')
id = area[0]['id'] # get the first view id

except: # get text area
area = Window.GetScreenInfo(Window.Types.TEXT)
id = area[1]['id'] # get the second text id

#--------create buttons--------
def draw():
global PushButton15, PushButton16, PushButton17, PushButton18, PushButton19, PushButton20, PushButton21, PushButton22, PushButton24, PushButton25, PushButton26
glClearColor(0.000, 0.000, 0.000, 0.0)
glClear(GL_COLOR_BUFFER_BIT)

PushButton('Top', 21, 2, 250, 60, 20, '+SHIFT Bottom View')
PushButton('Front', 15, 2, 225, 60, 20, '+SHIFT Back View')
PushButton('Right', 17, 2, 200, 60, 20, '+SHIFT Left View')
PushButton('8', 22, 23, 171, 20, 20, 'Tilt Up')
PushButton('4', 18, 2, 150, 20, 20, 'Pan <')
PushButton('5', 19, 23, 150, 20, 20, 'Ortho / Persp')
PushButton('6', 20, 44, 150, 20, 20, 'Pan >')
PushButton('2', 16, 23, 130, 20, 20, 'Tilt Down')
PushButton('0', 24, 2, 100, 20, 20, 'Camera')
PushButton('-', 25, 23, 100, 20, 20, 'Plus')
PushButton('+', 26, 44, 100, 20, 20, 'Minus')

#--------exit function--------
def event(evt, val):
if (evt== QKEY and not val):
SetKeyQualifiers(0)
Exit()

#--------button events--------
def bevent(evt):
global letter
if evt == 69: #DelKey
QAdd(id, DELKEY, 1)
QAdd(id, DELKEY, 0)
go_short()


elif evt == 10: #EscPushButton
Exit()

elif evt == 15: #1PushButton
QAdd(id, PAD1, 1)
QAdd(id, PAD1, 0)
go_short()

elif evt == 16: #2PushButton
QAdd(id, PAD2, 1)
QAdd(id, PAD2, 0)
go_short()

elif evt == 17: #3PushButton
QAdd(id, PAD3, 1)
QAdd(id, PAD3, 0)
go_short()

elif evt == 18: #4PushButton
QAdd(id, PAD4, 1)
QAdd(id, PAD4, 0)
go_short()

elif evt == 19: #5PushButton
QAdd(id, PAD5, 1)
QAdd(id, PAD5, 0)
go_short()

elif evt == 20: #6PushButton
QAdd(id, PAD6, 1)
QAdd(id, PAD6, 0)
go_short()

elif evt == 21: #7PushButton
QAdd(id, PAD7, 1)
QAdd(id, PAD7, 0)
go_short()

elif evt == 22: #8PushButton
QAdd(id, PAD8, 1)
QAdd(id, PAD8, 0)
go_short()

elif evt == 23: #9PushButton
QAdd(id, PAD9, 1)
QAdd(id, PAD9, 0)
go_short()

elif evt == 24: #0PushButton
QAdd(id, PAD0, 1)
QAdd(id, PAD0, 0)
go_short()

elif evt == 25: #-PushButton
QAdd(id, PADMINUS, 1)
QAdd(id, PADMINUS, 0)
go_short()

elif evt == 26: #=PushButton
QAdd(id, PADPLUSKEY, 1)
QAdd(id, PADPLUSKEY, 0)
go_short()


elif evt == 62: #.PushButton
QAdd(id, PADPERIOD, 1)
QAdd(id, PADPERIOD, 0)
go_short()


elif evt == 63: #/PushButton
QAdd(id, PADSLASHKEY, 1)
QAdd(id, PADSLASHKEY, 0)
go_short()


#--------redraw the window--------
Window.RedrawAll()

#--------register the 3 events--------
Register(draw, event, bevent)
#1   Old 02-Jul-06, 21:07   
Reply With Quote


RobertT's Avatar
RobertT RobertT is offline
Member
 
Join Date: Apr 2003
Posts: 3,042
Cool idea

I experimented with your script and modified it a bit to contain all the numpad keys, to approximate numpad key layout a little more, and to preserve indentations so the script can be copied and pasted without any problems.

Some small changes are in there as well, such as adding ESCKEY detection and a clickable Exit button for the script.

Since 1, 3, and 7 keys are back in there, the Top, Front, Right (Side) buttons can optionally come out of the GUI by placing a # character in front of each of those three lines below.

I hope these modifications can be helpful


Code:
import Blender from Blender import Window, Text, Draw, BGL from Blender.Window import * from Blender.Text import * from Blender.Draw import * from Blender.BGL import * #--------do it-------- def go_short(): QHandle(id) Window.RedrawAll() #--------get 3d window-------- try: # get 3d area area = Window.GetScreenInfo(Window.Types.VIEW3D, rect='total') id = area[0]['id'] # get the first view id except: # get text area area = Window.GetScreenInfo(Window.Types.TEXT) id = area[1]['id'] # get the second text id #--------create buttons-------- def draw(): global PushButton15, PushButton16, PushButton17, PushButton18, PushButton19, PushButton20, PushButton21, PushButton22, PushButton24, PushButton25, PushButton26 glClearColor(0.000, 0.000, 0.000, 0.0) glClear(GL_COLOR_BUFFER_BIT) PushButton('Top', 21, 2, 251, 83, 20, '+SHIFT Bottom View') PushButton('Front', 15, 2, 231, 83, 20, '+SHIFT Back View') PushButton('Right', 17, 2, 211, 83, 20, '+SHIFT Left View') PushButton('/', 63, 2, 191, 42, 20, 'Enter / Leave Local View') PushButton('*', 27, 44, 191, 20, 20, 'Rotate View to Object Orientation') PushButton('-', 25, 64, 171, 20, 40, 'Zoom Out') PushButton('+', 26, 64, 111, 20, 60, 'Zoom In') PushButton('7', 21, 2, 171, 20, 20, 'Top View | Click while pressing SHIFT for Bottom View') PushButton('8', 22, 23, 171, 20, 20, 'Tilt Up') PushButton('9', 23, 44, 171, 20, 20, 'Force Redraw/Recalculation') PushButton('4', 18, 2, 151, 20, 20, 'Pan <') PushButton('5', 19, 23, 151, 20, 20, 'Toggle Orthogonal / Perspective View') PushButton('6', 20, 44, 151, 20, 20, 'Pan >') PushButton('1', 15, 2, 131, 20, 20, 'Front View | Click while pressing SHIFT for Back View') PushButton('2', 16, 23, 131, 20, 20, 'Tilt Down') PushButton('3', 17, 44, 131, 20, 20, 'Side View: Right | Click while pressing SHIFT for Side View: Left') PushButton('0', 24, 2, 111, 42, 20, 'View from Active Camera | Hold CTRL to Set Active Camera') PushButton('.', 62, 44, 111, 20, 20, 'Center View Around Selection') PushButton('EXIT', 10, 2, 91, 83, 20, 'Q or ESC KEY to Exit') #--------exit function-------- def event(evt, val): if (evt== QKEY and not val) or evt == ESCKEY: SetKeyQualifiers(0) Exit() #--------button events-------- def bevent(evt): global letter if evt == 69: #DelKey QAdd(id, DELKEY, 1) QAdd(id, DELKEY, 0) go_short() elif evt == 100: #EXIT Exit() elif evt == 10: #EscPushButton Exit() elif evt == 15: #1PushButton QAdd(id, PAD1, 1) QAdd(id, PAD1, 0) go_short() elif evt == 16: #2PushButton QAdd(id, PAD2, 1) QAdd(id, PAD2, 0) go_short() elif evt == 17: #3PushButton QAdd(id, PAD3, 1) QAdd(id, PAD3, 0) go_short() elif evt == 18: #4PushButton QAdd(id, PAD4, 1) QAdd(id, PAD4, 0) go_short() elif evt == 19: #5PushButton QAdd(id, PAD5, 1) QAdd(id, PAD5, 0) go_short() elif evt == 20: #6PushButton QAdd(id, PAD6, 1) QAdd(id, PAD6, 0) go_short() elif evt == 21: #7PushButton QAdd(id, PAD7, 1) QAdd(id, PAD7, 0) go_short() elif evt == 22: #8PushButton QAdd(id, PAD8, 1) QAdd(id, PAD8, 0) go_short() elif evt == 23: #9PushButton QAdd(id, PAD9, 1) QAdd(id, PAD9, 0) go_short() elif evt == 24: #0PushButton QAdd(id, PAD0, 1) QAdd(id, PAD0, 0) go_short() elif evt == 25: #-PushButton QAdd(id, PADMINUS, 1) QAdd(id, PADMINUS, 0) go_short() elif evt == 26: #=PushButton QAdd(id, PADPLUSKEY, 1) QAdd(id, PADPLUSKEY, 0) go_short() elif evt == 27: #=PushButton QAdd(id, PADASTERKEY, 1) QAdd(id, PADASTERKEY, 0) go_short() elif evt == 62: #.PushButton QAdd(id, PADPERIOD, 1) QAdd(id, PADPERIOD, 0) go_short() elif evt == 63: #/PushButton QAdd(id, PADSLASHKEY, 1) QAdd(id, PADSLASHKEY, 0) go_short() #--------redraw the window-------- Window.RedrawAll() #--------register the 3 events-------- Register(draw, event, bevent)
RobertT
#2   Old 02-Jul-06, 22:38   
Reply With Quote
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
Just realised I lost all the indents just pasting the script!! This means it will throw an error tantrum if you try to run it!

You can get it here instead. Feel free to improve it.

http://homepage.eircom.net/~3d4free/download/LapTopNumPad.py

hope it is useful

Regds
Trevor
#3   Old 02-Jul-06, 22:50   
Reply With Quote
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
Hi RobertT
Geewhizz you are fast. Thanks for the additional code. Your modifications expand the virtual numpad to its full glory. I will update the link I just posted with your full key version.

Appreciate the help

Regds
Trevor
#4   Old 02-Jul-06, 23:12   
Reply With Quote
RobertT's Avatar
RobertT RobertT is offline
Member
 
Join Date: Apr 2003
Posts: 3,042
Haha, thanks I was browsing the forum while waiting for several hundred frames to render in Blender, so I had some free time and noticed your cool script. I'm glad the changes worked out.

RobertT
#5   Old 02-Jul-06, 23:30   
Reply With Quote
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
New improved Laptop Numpad Script.

http://homepage.eircom.net/~3d4free/download/Laptop_NumPad.py

right-click on the link and choose Save As.
Copy it to your scripts folder.
It will be available as a System menu item.

regds
Trevor
#6   Old 02-Jul-06, 23:50   
Reply With Quote
Smitje Smitje is offline
Member
 
Join Date: Jun 2005
Posts: 51
hi mugwah

I was realy looking forward to trying your script. (as I have frequent misagreements, with my laptop about the interpretation of what I am typing)

but It doesn't appear in the menu when I refresh.

what version of blender do you use?
I have 241 with full python allso installed


cheers Smitje
#7   Old 03-Jul-06, 21:47   
Reply With Quote
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
Hi Smitje
Sometimes blender does not register the scripts properly in the menu system (on my PC anyway). You can run any script manually this way:

Open a text window and load the script manually with File> Open. Then from the menu, File> Run Python Script, to get it to work.

Hope you find it useful

Regds
T
#8   Old 03-Jul-06, 22:09   
Reply With Quote
Smitje Smitje is offline
Member
 
Join Date: Jun 2005
Posts: 51
Thanks that works like a charm

that makes life a lot easier when working on a laptop.

good job! Cheers
Smitje
#9   Old 05-Jul-06, 22:06   
Reply With Quote
Snosoe's Avatar
Snosoe Snosoe is offline
Member
 
Join Date: Jul 2006
Location: Minnesota, USA
Posts: 58
When I run the script I get the following error:

I'm using Blender 2.41 w/ Python 2.4 on Windows

Traceback (mose recent call last):
File "C:\Editing\Blender\.blender\scripts\Laptop_NumPad .py", line 46, in ?
id = area[1]['id'] # get the second text id
IndexError: list index out of range
#10   Old 07-Jul-06, 17:12   
Reply With Quote
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
Hi Snosoe,
The script needs an open 3D viewport to be available. Split your 3D viewport in two and run the script in the right hand window.

This version should be ok
http://homepage.eircom.net/~3d4free/...Top_Num_Pad.py

cheers
T

Last edited by mugwah; 07-Jul-06 at 21:31.
#11   Old 07-Jul-06, 18:35   
Reply With Quote
Snosoe's Avatar
Snosoe Snosoe is offline
Member
 
Join Date: Jul 2006
Location: Minnesota, USA
Posts: 58
Thanks mugwah,
Works great now, thanks for the help and the great script.

Snosoe
#12   Old 08-Jul-06, 03:49   
Reply With Quote
Smitje Smitje is offline
Member
 
Join Date: Jun 2005
Posts: 51
Hi mugwah

Still love your script.

Yesterday I was using it on the train and I had 2 3d views open, but could controll only one. Do you think it would be possible to switch what window the script controlls?

cheers
Smitje
#13   Old 10-Jul-06, 11:49   
Reply With Quote
pildanovak's Avatar
pildanovak pildanovak is offline
Member
 
Join Date: May 2004
Posts: 958
Thanks very much. still it would be great if there would be a way to redirect blender shortcuts, since this is still about clicking, but really usable for some things(view selected and local view mode). I think that there are still more and more laptopers and the more important shortcuts should be moved to the main keyboard.
#14   Old 10-Jul-06, 12:01   
Reply With Quote
CG_Tiger CG_Tiger is offline
Member
 
Join Date: May 2005
Posts: 189
Why don't they instead of emulating the numpad, but remap the numbers.
1 - Top view
2 - Front view
3 - Side view
Shift - 1/2/3 for opposite view

4 - Perspective/Othoganal view
5 - View Selected
6 - Isolated view
7 -
8 -
9 -
0 - camera view

I don't even use the
rotate keys 2,4,6, & 8.

What are your views on the emulated numpad option?
#15   Old 10-Jul-06, 13:56   
Reply With Quote
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
Hi smitje.
AFAIK scripts can only affect one dominant 3d window as the mouse pointer has to be over the script window to operate it.

Hi CGTiger,
You are quite correct. You lose the direct layer keys but you always have the M KEY!! The script is just another way of doing it.

What CGtiger is refering to is the 'Emulate Numpad' button in the System & OpenGL part of the Preferences pulldown. That remaps the 1-0 keys for navigation,
#16   Old 10-Jul-06, 22:59   
Reply With Quote
raceimaztion raceimaztion is offline
Member
 
Join Date: Jul 2006
Posts: 2
I figured out what the problem is with the script not showing up in the Scripts menu:
There's an extra newline at the beginning of the file before the #BSP declaration that prevents Blender from finding it.

Simple problem, simple fix.
#17   Old 12-Jul-06, 20:05   
Reply With Quote
mugwah mugwah is offline
Member
 
Join Date: Nov 2003
Posts: 36
Thanks raceomazion
Why that script did not show in the scripts menu was was bugging me. Thanks for pointing out the problem! Fixed.
#18   Old 12-Jul-06, 22:56   
Reply With Quote
xchak xchak is offline
Member
 
Join Date: Oct 2009
Posts: 1
edit


thnx

Last edited by xchak; 15-Oct-09 at 02:20.
#19   Old 14-Oct-09, 22:23   
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VirtualUndo Script - Anyone want to Help? mthoenes Python & Plugins 26 12-Nov-06 17:09
NEW: Aligner/Displacer/Randomizer Script RobertT Python & Plugins 19 07-Nov-06 16:24
Terragen script generator mfoxdogg Python & Plugins 3 01-Jun-06 00:59
New Script List theeth Python & Plugins 28 07-Mar-06 00:56
auto UV mapping python script -> speeds up level texturin lizard809 Game Engine Support and Discussion 7 25-Mar-03 01:38


All times are GMT. The time now is 18:56.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Logo and website design copyright © 2006 by froodee design bureau. All rights reserved.
Other Blender Sites
new icon Blender Homepage »
The official Blender homepage
new icon BlenderNation »
Fresh Blender News, Every Day
new icon Blenderart Magazine »
Blender articles, tutorials and images.
Blender Headlines
Featured Artwork
Short animation: Barrel by Phlopper
Woolly mammoth by sebastian_k
Photorealistic classic furniture by eMirage
Social BlenderArtists