i working on a script to change a global value if extruder move region happen so if the extruder happen the global value will change to 1 if extruder not happen now the global var will set to 0
but the problem is only one def “def model” model who work and “def modeltwo()” not give any resulat at all so how to fixing that ?
import bpy
globvar = 0
def set_globvar_to_one():
global globvar # Needed to modify global copy of globvar
globvar = 1
def set_globvar_to_zero():
global globvar # Needed to modify global copy of globvar
globvar = 0
def print_globvar():
print(globvar) # No need for global declaration to read value of globvar
class ModalOperator(bpy.types.Operator):
bl_idname = "object.modal_operator"
bl_label = "Simple Modal Operator"
#save_op = None
def execute(self, context):
print("This is the modal operator")
return {'FINISHED'}
def modal(self, context, event):
active_op = context.active_operator
idname = getattr(active_op, "bl_idname")
if idname == "MESH_OT_extrude_region_move" and globvar == 0:
print("extruded")
#self.save_op = active_op
set_globvar_to_one()
print("the active op",active_op)
print("the globvar op",globvar)
# set some var here to run once and check equality
# self.save_op = active_op
return {'PASS_THROUGH'}
def modaltwo(self, context, event):
print("modaltwoffffff")
active_op = context.active_operator
idname = getattr(active_op, "bl_idname")
print("tesssst")
if idname != "MESH_OT_extrude_region_move" and globvar == 1:
set_globvar_to_zero()
print("set_globvar_to_zero",globvar)
return {'PASS_THROUGH'}
def invoke(self, context, event):
print("This is the invoker")
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
bpy.utils.register_class(ModalOperator)
bpy.ops.object.modal_operator('INVOKE_DEFAULT')