So I was trying to use change the value of the thickness through a modal operation where the mouse movement along the x changes the thickness of the modifier. It works fine when I execute it from my custom panel but it doesn't work when I try to execute it through the pop-up menu. There are no error messages shown, nothing happens when i press the button in the pop-up.

Sorry the codes breaking up in the post, I'm new to stackexchange.

import bpy

from bpy.props import IntProperty, FloatProperty

class FattenerModal(bpy.types.Operator): bl_idname = "fattener.f_operator" bl_label = "Fattener Modal"

bpy.ops.object.modifier_remove(modifier="Solidify")#Clears previous solidify modifier
bpy.ops.object.modifier_add(type='SOLIDIFY')#Adds a new solidify modifier

first_mouse_x = IntProperty()
first_value = FloatProperty()

def modal(self, context, event):
    if event.type == 'MOUSEMOVE':
        delta = self.first_mouse_x - event.mouse_x
        context.object.modifiers["Solidify"].thickness = self.first_value + delta * 0.01

    elif event.type == 'LEFTMOUSE':
        bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Solidify")#Applies the solidify modifier
        return {'FINISHED'}

    elif event.type in {'RIGHTMOUSE', 'ESC'}:
        context.object.modifiers["Solidify"].thickness = self.first_value
        return {'CANCELLED'}

    return {'RUNNING_MODAL'}

def invoke(self, context, event):
    if context.object:
        self.first_mouse_x = event.mouse_x
        self.first_value = context.object.modifiers["Solidify"].thickness

        return {'RUNNING_MODAL'}
        self.report({'WARNING'}, "No active object, could not finish")
        return {'CANCELLED'}  

class FattenerPopup(bpy.types.Menu): bl_label = "FatternerPopup Menu" bl_idname = "FattenerPop"

def draw(self, context):
    layout = self.layout
    layout.operator("fattener.f_operator", text="FattenerF", icon='MOD_WARP')

def register(): bpy.utils.register_class(FattenerModal) bpy.utils.register_class(FattenerPopup)

km_list = ['3D View']
for i in km_list:
    sm = bpy.context.window_manager
    km = sm.keyconfigs.default.keymaps[i]
    kmi = km.keymap_items.new('wm.call_menu', 'Q', 'PRESS', ctrl=False, shift=True)
    kmi.properties.name = "FattenerPop"    

def unregister(): bpy.utils.unregister_class(FattenerModal)
bpy.utils.unregister_class(FattenerPopup) km_list = ['3D View'] for i in km_list: sm = bpy.context.window_manager km = sm.keyconfigs.default.keymaps[i] for kmi in (kmi for kmi in km.keymap_items \ if (kmi.idname == "FattenerPop")): km.keymap_items.remove(kmi)

if name == "main": register()



You must log in to answer this question.

Browse other questions tagged .