Sometimes is useful to break out things like colours into a tabular field and then populate these as a set of frames, one for each colour. The frames might contain a Swatch and a swatch name.
The example below iterates though the Colour tabular field, duplicating the frame given the Script LabelĀ group. It then populates it with the data for each cell. If the group is anchored in a text frame it will be duplicated immediately after in the text flow.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | -- Get the frame by its Script Label frame = formattingrule:getframe("group"); -- Store the original frame original_frame = frame; -- Get the tabular field called "Colour" mytable = SELECTION.root():getfield('Colour'):content(); -- Loop for each row in the tabular field for i = 1, mytable:rowcount() do -- duplicate the frame and populate it with data from the given cell frame = frame:duplicate(mytable:cell(i,1)); end -- Delete the original frame original_frame:delete() |