CGCookie / script-bakery

A collection of scripts written by members of CG Cookie to improve their Blender workflow.
124 stars 65 forks source link

Retopology Menu #84

Closed carter2422 closed 11 years ago

carter2422 commented 11 years ago

To make workflow more user friendly, without the need to constantly have the toolbar open, we need to add a Retopology Menu.

carter2422 commented 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?

patmo141 commented 11 years ago

you need to call it with invoke instead of execute :-)

carter2422 commented 11 years ago

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")  
carter2422 commented 11 years ago

Draw is required for menus. How would I do the invoke? That's not something I'm too familiar with.

patmo141 commented 11 years ago

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?

patmo141 commented 11 years ago

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'

carter2422 commented 11 years ago

Ah that did the trick! Thanks.

patmo141 commented 11 years ago

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

carter2422 commented 11 years ago

Closed in 228f9a7c9a03d0fc07be6b04a42c09be65a77e2f