Array modifier has two offsets options. You can choose “Relative”, Constant or even both.
So if you want to jump from one to another you need to do some math.
It’s will be great if we have the option to convert Relative to Constant and back. Or if two checkboxes of offsets are turned on, to convert them into one of the options.
So it’s simple stuff, but I just start learning the Python.
I start to write some code, but I stuck and I need some help. The “Relative” option is working together with the object “Dimension”. Which you can get from Sidebar–>View–>Transform with the selected object. But, “in array modifier code”, relative offset gets Dimension size without modifier turn on.
So what I need for my code to tun it’s to get object Dimensions, without modifiers value.
import bpy
active = bpy.context.active_object
array=active.modifiers["Array"]
relative_x= array.relative_offset_displace[0]
constant_x= array.constant_offset_displace[0]
dimentions_x =active.dimensions[0]
relative_y = array.relative_offset_displace[1]
constant_y = array.constant_offset_displace[1]
dimentions_y =active.dimensions[1]
relative_z = array.relative_offset_displace[2]
constant_z = array.constant_offset_displace[2]
dimentions_z =active.dimensions[2]
array.show_viewport = False
if array.use_relative_offset == True and array.use_constant_offset == False:
array.use_relative_offset = False
array.constant_offset_displace[0] =relative_x*dimentions_x
array.constant_offset_displace[1] =relative_y*dimentions_y
array.constant_offset_displace[2] =relative_z*dimentions_z
array.use_constant_offset = True
elif array.use_relative_offset == False and array.use_constant_offset == True:
array.use_constant_offset = False
array.relative_offset_displace[0] =constant_x/dimentions_x
array.relative_offset_displace[1] =constant_y/dimentions_y
array.relative_offset_displace[2] =constant_z/dimentions_z
array.use_relative_offset = True
elif array.use_relative_offset == True and array.use_constant_offset == True:
array.use_relative_offset = False
array.use_constant_offset = False
array.constant_offset_displace[0] =constant_x+relative_x*dimentions_x
array.constant_offset_displace[1] =constant_y+relative_y*dimentions_y
array.constant_offset_displace[2] =constant_z+relative_z*dimentions_z
array.use_constant_offset = True
array.show_viewport = True