Say that I have an unknown (n) number of elements (iconTextButtons for example) of varying sizes that are generated via a loop which creates these objects automagicly.
And say that these elements are inside a formLayout and that said elements are of varying sizes. (for example, one type of button has the dimensions 60x60 px, and a second type has 30x30 px)
Then how can you position these elements inside the formLayout effectivly, especially considering that you do not know the names of these objects?
This could be more or less complex depending on what you want to do; but basically you want to create two long lists of arguments, one for attatchForm and one for attachControl.
I usually do this using itertools.tee to create a list of a-b pairs between all the anonymous elements (WARNING ! Doing this from memory, not tested!!!)
import itertools
buttons = []
with pm.formLayout('form') as myform:
for n in range(99):
buttons.add(pm.button('button_%i' % n)
# to create the n, n+1 list of buttons:
m1, m2 = itertools.tee(buttons)
mg = 10 # margin
first_button = mg.next()
pm.formLayout(myform, e = True, af = [(first_button , 'top', mg), (first_button, 'left', mg), (first_button, 'right', mg)])
aflist = []
aclist = []
for t, b in itertools.izip(m1, m2):
aflist.append( ( ( b, 'left', mg), (b, 'right', mg) ) ) # left and right form attach
aclist.append( ( b, 'top', mg, t) ) # attach bottom to top
pm.formLayout(myform, e=True, af= aflist))
pm.formLayout(myform, e=True, ac= aclist))