Closed carter2422 closed 11 years ago
@patmo141 I've created the menu with no problem, but I'm getting an error when I try to call the operator from the menu. But the operator works just fine from the toolbar and search.
Traceback (most recent call last):
File "/Users/jonathanwilliamson/Dropbox/resources/repositories/cgCookie/script-bakery/scripts/addons/contour_tools/__init__.py", line 1402, in execute
for line in self.cut_lines:
File "/Users/jonathanwilliamson/Blender-Builds/blender-build/cmake/bin/blender.app/Contents/MacOS/2.68/scripts/modules/bpy_types.py", line 573, in __getattribute__
return super().__getattribute__(attr)
AttributeError: 'CGCOOKIE_OT_retopo_contour' object has no attribute 'cut_lines'
location: <unknown location>:-1
Any thoughts?
you need to call it with invoke instead of execute :-)
I'm doing it with draw:
class CGCOOKIE_OT_retopo_contour_menu(bpy.types.Menu):
bl_label = "Retopology"
bl_space_type = 'VIEW_3D'
bl_idname = "object.retopology_menu"
def draw(self, context):
layout = self.layout
layout.operator("cgcookie.retop_contour")
Draw is required for menus. How would I do the invoke? That's not something I'm too familiar with.
Oh, I'm silly, I think I need to add it. Also, where did my previous comment go or did I just make it in my mind?
OK, reposting my last comment.
The menu.layout.operator calls operators with 'EXEC_DEFAULT' context while panel.layout.operator (eg a button) calls with "INVOKE_DEFAULT.' try adding this to your menu def draw() method
self.layout.operator_context = 'INVOKE_DEFAULT'
Ah that did the trick! Thanks.
or you may be able to just say operator_context = 'INVOKE_DEFAULT' before the def draw so it doesn't set it every time it's drawing? Dunno if it matters
Closed in 228f9a7c9a03d0fc07be6b04a42c09be65a77e2f
To make workflow more user friendly, without the need to constantly have the toolbar open, we need to add a Retopology Menu.