Thank you for your reply!
I tried the second way already but nevertheless I couldn’t find a way to work with the correct dimensions.
Atm I first store the Fit-Type and associated Value of the Modifier, reset the modifier to fit_type ‘FIXED_COUNT’ and a count of “1” (I also tried deleting it), then get the dimensions, then calculate the children-offset with that dimension-values, than set the children offset, then restore the Type from the first step and then set the corresponding children fit_type and value.
My previous attempts to fix this were more a digging into quicksand. :spin: I tried to dump the dimension values by pickle and as textfile too, to see their values and have them stored uninfluenced by further manipulations, but it always uses and writes the “original” dimension-values. If I leave the Restorement-Part at the end out, it fails too. It correctly resets the modifier (but the written dimensions are still the ones from before the reset). I don’t get it and I suspect myself to make a fundamental mistake, which will turn out to be pretty dull in the end.
Maybe it helps to see the Code - Beforehand: I am a beginner in Python (but getting more and more excited about it), so I am sure there are much more elegant and cleaner ways to write this (and without writing extrafiles). But what I first want to fix is the problem with my class calling the wrong values. So here is the corresponding part of my code:
(Fun-Fact: When I delete the children arrays and then use Fit-Type “Fit_Length”, the first synch works (cause I deleted the part for reseting the children-dimensions for better overview it is only the first) for a certain offset-realm, although the written txt-File contains the wrong dimensions, but for FIXED_COUNT and counts > 1, it always calculates wrong offsets.)
def invoke(self, context, event) :
#
a = bpy.context.scene.objects.active
asynch = a.modifiers["ArraySynch"]
# test fit_type
if asynch.fit_type == 'FIXED_COUNT':
atest = "1 0 0"
acount = asynch.count
#
a_sval = open("E:/a_sval.pkl","wb")
pickle.dump(acount, a_sval, -1)
a_sval.close()
#
elif asynch.fit_type == 'FIT_LENGTH':
atest = "0 1 0"
else:
atest = "0 0 1"
#Store atest in file
atester = open("E:/atest.pkl", "wb")
pickle.dump(atest, atester, -1)
atester.close()
#
#
if asynch.fit_type != 'FIXED_COUNT':
asynch.fit_type = 'FIXED_COUNT'
else:
pass
asynch.count = 1
#
#Dimensions
ax = str(a.dimensions[0]) +"
"
ay = str(a.dimensions[1]) +"
"
az = str(a.dimensions[2]) +"
"
#
# store a dimensions in adims.pkl
adimdat = open("E:/adims.txt","w")
adimdat.write(ax)
adimdat.write(ay)
adimdat.write(az)
#pickle.dump(adim, adimdat, -1)
adimdat.close()
#
#
childlist = a.children
for ob in childlist:
# test for ArraySynch-Array
rtest = False
for mod in ob.modifiers:
if mod.name == "ArraySynch" and mod.type == 'ARRAY':
rtest = True
else:
pass
#new ArraySynch if rtest=false
if rtest == False:
ob.modifiers.new("ArraySynch", type='ARRAY')
ob.modifiers["ArraySynch"].relative_offset_displace = (1,0,0)
else:
pass
#
#reset rsynch.count
rsynch = ob.modifiers["ArraySynch"]
rsynch.fit_type = 'FIXED_COUNT'
rsynch.count = 1
#
# load adims from Store_adim
adimdat = open("E:/adims.txt","r")
pckld_adimx = adimdat.readline(1)
pckld_adimy = adimdat.readline(2)
pckld_adimz = adimdat.readline(3)
#pckld_adim = pickle.load(adimdat)
adimdat.close()
#
adx = float(pckld_adimx)
ady = float(pckld_adimy)
adz = float(pckld_adimz)
#
# get r.dimensions
rxyz = ob.dimensions
rx = rxyz[0]
ry = rxyz[1]
rz = rxyz[2]
#
#
aoffsx = asynch.relative_offset_displace[0]
aoffsy = asynch.relative_offset_displace[1]
aoffsz = asynch.relative_offset_displace[2]
##
roffsx = (adx*aoffsx)/rx
roffsy = (ady*aoffsy)/ry
roffsz = (adz*aoffsz)/rz
#
rsynch.relative_offset_displace[0] = roffsx
rsynch.relative_offset_displace[1] = roffsy
rsynch.relative_offset_displace[2] = roffsz
#
#
#
#
# atester = open("E:/atest.pkl","rb")
# pckld_atest = pickle.load(atester)
# atester.close()
#
# a_sval = open("E:/a_sval.pkl","rb")
# pckld_count = pickle.load(a_sval)
# a_sval.close()
#
#
# if pckld_atest == "1 0 0":
# asynch.fit_type = 'FIXED_COUNT'
# asynch.count = pckld_count
# elif pckld_atest == "0 1 0":
# asynch.fit_type = 'FIT_LENGTH'
# alength = asynch.fit_length
# else:
# asynch.fit_type = 'FIT_CURVE'
# acurve = asynch.curve
#
#
#
#childlist = a.children
# for ob in childlist:
# rtest = False
# for mod in ob.modifiers:
# if mod.name == "ArraySynch" and mod.type =='ARRAY':
# rtest = True
# else:
# rtest = False
# if rtest == True:
# pass
# else:
# ob.modifiers.new("ArraySynch", type='ARRAY')
# ob.modifiers["ArraySynch"].relative_offset_displace = (1,0,0)
#
# rsynch = ob.modifiers["ArraySynch"]
# rsynch.fit_type = asynch.fit_type
# if asynch.fit_type == 'FIXED_COUNT':
# rsynch.count = asynch.count
# elif asynch.fit_type == 'FIT_LENGTH':
# rsynch.fit_length = asynch.fit_length
# else:
# rsynch.curve = asynch.curve
return{'FINISHED'}