I want to create an Addon for a shelf planning tool. The slider should change the offset of the Array Modifier. I already have the slider in my panel, but when I tell the offset to be the slider I always get the message: offset is too short? Even when the slider is 2 for example. How can I change the code to make it work?
import bpy
from bpy.types import Panel, Operator
class RGL_PT_Panel(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_label = "Regalplannung"
bl_category = "Regalplannung"
def draw(self, context):
layout = self.layout
row = layout.row()
col = row.column()
col.operator("object.regalplannung", text = "Aufüllen")
col.prop(context.object, 'Offset_X', text = "Abstand X",
slider=True)
col.prop(context.object, 'Offset_Y', text = "Abstand Y",
slider=True)
class RGL_OT_regalplannung(Operator):
"""Vollständig gefüllt & Ausrichten"""
bl_idname = "object.regalplannung"
bl_label = "Regalplannung"
bl_description = "Regalplannung in Blender"
bpy.types.Object.Offset_X = bpy.props.FloatProperty(min = -5, max = 5)
bpy.types.Object.Offset_Y = bpy.props.FloatProperty(min = -5, max = 5)
def execute(self, context):
selection = bpy.context.selected_objects
for sel in selection:
parent = sel.parent
parent_0 = parent.dimensions [0]
parent_1 = parent.dimensions [1]
parent_2 = parent.dimensions [2]
mod_array = sel.modifiers.new("Vollständig gefüllt", 'ARRAY')
mod_array.fit_type = 'FIT_LENGTH'
mod_array.relative_offset_displace[0] = 0
if parent_0 < parent_1:
mod_array.fit_length = parent.dimensions[0] - sel.dimensions[0]
mod_array.relative_offset_displace[0] = bpy.types.Object.Offset_X
else:
mod_array.fit_length = parent.dimensions[1] - sel.dimensions[1]
mod_array.relative_offset_displace[1] = bpy.types.Object.Offset_Y
return {'FINISHED'}
bpy.utils.register_class(RGL_PT_Panel)
bpy.utils.register_class(RGL_OT_regalplannung)
```