got this old addon
but not working anymore
import bpy
class VIEW3D_POPUP_hello_world(bpy.types.Menu):
bl_label = "Hello World popup window test"
def draw(self, context):
layout = self.layout
layout.operator_context = "INVOKE_REGION_WIN"
def register():
km = bpy.context.window_manager.keyconfigs.default.keymaps['3D View']
kmi = km.items.new('wm.call_menu', 'J', 'PRESS')
kmi.properties.name = "VIEW3D_POPUP_hello_world"
def unregister():
pass
if __name__ == "__main__":
register()
can someone help to get it going again
thanks
happy bl
FreeAccess
(A picture is worth 1000 words)
April 1, 2018, 12:23pm
2
Hi,
I’m not expert :no: . . . but, may be !!!
At home it’s OK . . .
** ==> Do not forget register Class
** ==> Add bl_idname
import bpy
class VIEW3D_POPUP_hello_world(bpy.types.Menu):
bl_idname = "hello_world"
bl_label = "Hello World popup window test"
def draw(self, context):
layout = self.layout
layout.operator_context = "INVOKE_REGION_WIN"
def register():
bpy.utils.register_class(VIEW3D_POPUP_hello_world) ## ==> Register Class
#km = bpy.context.window_manager.keyconfigs.default.keymaps['3D View']
#kmi = km.items.new ('wm.call_menu', 'J', 'PRESS')
#kmi.properties.name = "VIEW3D_POPUP_hello_world"
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
kmi = km.keymap_items.new('wm.call_menu', 'J', 'PRESS')
kmi.properties.name = "hello_world"
def unregister():
bpy.utils.register_class(VIEW3D_POPUP_hello_world)
if __name__ == "__main__":
register()
Spirou4D
(Spirou4D)
April 1, 2018, 2:20pm
3
bl_info = { "name": "Hello World",
"description": "World menu",
"author": "See documentation Credits",
"version": (0, 1, 0),
"blender": (2, 79, 0),
"location": "'J' shortcut",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"
}
import bpy
class VIEW3D_POPUP_hello_world(bpy.types.Menu):
bl_label = "Hello World popup window test"
bl_idname = "VIEW3D_MT_world_menu"
def draw(self, context):
layout = self.layout
layout.operator_context = "INVOKE_REGION_WIN"
addon_keymaps = []
def register():
bpy.utils.register_class(VIEW3D_POPUP_hello_world)
wm = bpy.context.window_manager
if wm.keyconfigs.addon:
km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type="VIEW_3D")
kmi = km.keymap_items.new('wm.call_menu', 'J', 'PRESS')
kmi.properties.name = "VIEW3D_MT_world_menu"
addon_keymaps.append((km, kmi))
def unregister():
bpy.utils.unregister_class(VIEW3D_POPUP_hello_world)
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
if __name__ == "__main__":
register()
working well
will use that in a special addon I’m working on
is there more examples to show how to work with more complex short cut keys
like Ctrl Alt J or else
or work with the special function keys or the keypad’s keys?
can this work with another menu like
bpy.types.INFO_MT_mesh_add.append(menu_func) ?
that menu seems to continue to work but the other one with short key does not seems
to call the function !
thanks for feedback
happy bl
Spirou4D
(Spirou4D)
April 2, 2018, 1:20am
5
is there more examples to show how to work with more complex short cut keys
like Ctrl Alt J or else
Take your code application and make a search with “keymaps” word and choose the addons folder as target and you will obtain all addons with shortcuts…
or work with the special function keys or the keypad’s keys?
idem or
You can analyze my addon: EZ_PAINT
can this work with another menu like
bpy.types.INFO_MT_mesh_add.append(menu_func) ?
YES search this “Kjartans Scripts” add-on:
http://www.kjartantysdal.com/scripts/
that menu seems to continue to work but the other one with shortkey does not seems
to call the function !
? explain what you mean, Friend! :rolleyes:
will look at the references given this night
and be back if not done
have you heard of a bug with Bmesh and class while doing a loop
when I try to extend edge on the second time it gives error that Bm is not there!
like it cannot re create a new version of BM on second loop
thanks for feedback
happy bl
Spirou4D
(Spirou4D)
April 2, 2018, 11:25am
7
>>have you heard of a bug with Bmesh and class while doing a loop
when I try to extend edge on the second time it gives error that Bm is not there!
No, I’m not aware of it!
Byebye Ricky.
pop up window might not be the best example!
my main menu is as follow
class INFO_MT_mesh_edgesquare1_add(bpy.types.Menu):
# Define the "Edge Square" menu
bl_idname = "INFO_MT_mesh_edgesquare1_add"
bl_label = "Edges Square"
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("mesh.primitive_edgesquare1_add",
text="edges square1")
that is working fine
but would like to add another method to call the same class operator but with a short key
like Ctrl- J or J key if possible
I think there is a way to add it but not certain how
note: uploaded file of you need to see the WIP script
it is a very simple an short extend edge with bmesh script operator with a bug while looping !
need that to do equal width line in top / front view for CAD drawings !
you select and edge and it will measure L
then extend it same amount to get a simple square
but when I tried to do it twice and crashes
BM seems to be gone in the class!
thanks man
happy bl
Attachments
Edge-square3.blend (107 KB)
found this example but still not right
def register():
wm = bpy.context.window_manager
bpy.types.INFO_MT_mesh_add.append(menu_func)
km = wm.keyconfigs.addon.keymaps.new(name='Window', space_type='EMPTY' ,region_type='WINDOW')
kmi = km.keymap_items.new(edgesquare1.bl_idname, 'F1', 'PRESS', oskey=True)
addon_keymaps.append(km)
bpy.utils.register_module(__name__)
not certain if this call with F1 key !
will test further
thanks
happy bl
this one seems to be working
def register():
wm = bpy.context.window_manager
bpy.types.INFO_MT_mesh_add.append(menu_func)
# handle the keymap
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type="VIEW_3D")
kmi = km.keymap_items.new( edgesquare1.bl_idname , 'NUMPAD_0', 'PRESS', ctrl=False, shift=False)
addon_keymaps.append(km)
bpy.utils.register_module(__name__)
got to see if I can try other keys on keyboard!
still having this bug with second time I do the class!
thanks
happy bl
Spirou4D
(Spirou4D)
April 5, 2018, 2:47am
11
def register(): wm = bpy.context.window_manager
bpy.types.INFO_MT_mesh_add.append(menu_func)
# handle the keymap
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type="VIEW_3D")
kmi = km.keymap_items.new( edgesquare1.bl_idname , 'NUMPAD_0', 'PRESS', ctrl=False, shift=False)
addon_keymaps.append(km)
bpy.utils.register_module(__name__)
Corrected code:
addon_keymaps = []
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_mesh_add.append(menu_func)
# handle the keymap
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type="VIEW_3D")
kmi = km.keymap_items.new( edgesquare1.bl_idname , 'NUMPAD_0', 'PRESS', ctrl=False, shift=False)
addon_keymaps.append(km)
Sorry bu I’m very busy, I can’t help you more… :no:
Byebye
Spirou4D