I tried to make this simple operator to add array modifiers while keep in "Edit Mode"
the goal is, add array modifiers to the object while in edit mode and the array count can be adjusted via redo panel, But when i adjust the value on the redo panel is also add new Array modifiers instead only adjusting the "Count" value, however its work as expected while script running in “Object Mode”
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
)
class AddModPanel(bpy.types.Panel):
bl_idname = "PANEL_PT_Addon"
bl_label = "Panel"
bl_category = "modifier"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
row.operator('object.addarray', text="Add Array")
class AddArrayOperator(bpy.types.Operator):
bl_idname = "object.addarray"
bl_label = "AddArray"
bl_options = {'REGISTER', 'UNDO'}
array_count: IntProperty(name= 'ARRAYCOUNT', default= 1)
def execute(self, context):
C= bpy.context
for o in C.selected_objects:
mod = o.modifiers.new(type = 'ARRAY', name= 'Array')
mod.count= self.array_count
bpy.ops.object.mode_set(mode = 'EDIT') #Keep in edit mode but doesn't work as expected
#bpy.ops.object.mode_set(mode = 'OBJECT') #Work as expected but is not the goal
return {'FINISHED'}
def register():
bpy.utils.register_class(AddArrayOperator)
bpy.utils.register_class(AddModPanel)
def unregister():
bpy.utils.unregister_class(AddArrayOperator)
bpy.utils.unregister_class(AddModPanel)
if __name__ == "__main__":
register()
#Please try this script from both Edit and Object mode
Below is without any loop version intended for active object only, but the issue still same
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
)
class AddModPanel(bpy.types.Panel):
bl_idname = "PANEL_PT_Addon"
bl_label = "Panel"
bl_category = "modifier"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
row.operator('object.addarray', text="Add Array")
class AddArrayOperator(bpy.types.Operator):
bl_idname = "object.addarray"
bl_label = "AddArray"
bl_options = {'REGISTER', 'UNDO'}
array_count: IntProperty(name= 'ARRAYCOUNT', default= 1)
def execute(self, context):
C= bpy.context
o= C.active_object
mod = o.modifiers.new(type = 'ARRAY', name= 'Array')
mod.count= self.array_count
bpy.ops.object.mode_set(mode = 'EDIT') #Keep in edit mode but doesn't work as expected
#bpy.ops.object.mode_set(mode = 'OBJECT') #Work as expected but is not the goal
return {'FINISHED'}
def register():
bpy.utils.register_class(AddArrayOperator)
bpy.utils.register_class(AddModPanel)
def unregister():
bpy.utils.unregister_class(AddArrayOperator)
bpy.utils.unregister_class(AddModPanel)
if __name__ == "__main__":
register()
#Please try this script from both Edit and Object mode
In summary, I just want my script to be able to add array modifiers and adjust dynamically via the redo panel in "Edit Mode", please help. Is there something I am missing? thanks in advance
Note: It's also has same issue in another modifiers such as mirror while changing axis in edit mode via redo panel, the object will keep add new mirror modifier when any redo panel value has updated
PS; i think this is common problem in scripting, but i can't find any question such as this in this forum, hopefully this question is not duplicated
