Janet's Notes

Miscellaneous Articles Trying to be Useful


Project maintained by JanetRossini

Small Improvements

Here is a patch of code:

class RCG_OT_addarray(Operator):
    """ Add ARRAY Modifier """
    bl_idname = "rcg.addarray"
    bl_label = "Add ARRAY Modifier"
    bl_options = {"REGISTER", "UNDO"}

    @classmethod
    def poll(cls, context):
        return context.mode == "OBJECT"

    def execute(self, context):
        bpy.ops.object.modifier_add(type='ARRAY')
        bpy.context.object.modifiers["Array"].count = 20
        bpy.context.object.modifiers["Array"].use_merge_vertices = True
        bpy.context.object.modifiers["Array"].constant_offset_displace[0] = 1
        bpy.context.object.modifiers["Array"].relative_offset_displace[1] = 0
        bpy.context.object.modifiers["Array"].relative_offset_displace[2] = 0
        bpy.context.object.modifiers["Array"].fit_type = 'FIXED_COUNT'
        return {'FINISHED'}

I think this is better:

    def execute(self, context):
        bpy.ops.object.modifier_add(type='ARRAY')
        modifier = bpy.context.object.modifiers["Array"]
        modifier.count = 20
        modifier.use_merge_vertices = True
        modifier.constant_offset_displace = Vector((1.0, 0.0, 0.0))
        modifier.fit_type = 'FIXED_COUNT'
        return {'FINISHED'}

Tested and works. Committed. The original code was, like most of what we have here, originally found directly on the Internet or, even worse, suggested by ChatGPT. So it tends to be close, but rarely really very good code. The above … well, I prefer it.

Renamed some classes, using camel case. Changed some of the rcg strings to use camel case. Probably more than we need but may add a bit of readability. I am a fanatic.

That’s all for now.