Help with code & combining idea
-
Hi,
I've this code to export some labels I need to print.
min_val = listFontVariations('Juicyv2')['wdth']['minValue'] max_val = listFontVariations('Juicyv2')['wdth']['maxValue'] #print(min_val, max_val) steps = 30 step_size = (max_val - min_val) / (steps-1) # loop over a range of 100 for i in range(steps): # for each loop create a new path newPage(595.27559055, 96.377952756) # draw a rect with the size of the page rect(0, 0, width(), height()) fill(255, 255, 255) #rect(0, 73.7007874011, width(), 8.5039370079) bp = BezierPath() curr_value = min_val + i * step_size fontVariations(wdth= curr_value) fstr = FormattedString("JUICY.ttf", font='Juicylixo', tracking=-1, fontSize=93, fontVariations = {'wdth' : curr_value}) fill(1) bp.text(fstr, (14, 15.3)) drawPath(bp) font("Staff-Regular") fontSize(6.7) text('%f' % curr_value, (540, 15.3)) for contour in bp: for segment in contour: fill(1, 0, 0) baselineShift(-0.25) fontSize(3) text('🍎', segment[-1], align = "center") saveImage("Label.pdf")
But then I was manually importing them to InDesign to an A3 page and placing 10 each page to print. It gets boring and InDesign takes a lot of time to export pdf A3 pages with so many imported pdf labels.
I'm curious if this is something easier to do 100% inside DrawBot. Any help?
I just want to keep the same concept: Decide how many Labels and to have always a different position on the font design space.
-
you could new make an A3 page with
newPage('A3')
and then draw several of the textboxes on that page. basically take thenewPage
out of the loop and instead change the position of each new label.PW, PH = 842, 1190 # A3 page width and height page_margin = 40 # the margin for the whole page amount = 50 # how many labels to draw in total per_page = 10 # how many labels per page gap = 10 # the gap between the labels # the next line calculates the heigth for the label label_h = (PH - ((per_page-1)*gap) - 2 * page_margin ) / per_page for i in range(amount): if i % per_page == 0: newPage(PW, PH) y = PH - page_margin - cell_h rect(page_margin, y, width() - 2*page_margin, label_h) y -= label_h + gap
-
thanks! It seems there's a way.
what do you mean with cell_h. It is not defined.
-
aah, untested last minute changes. I changed the variable names to something more reasonable but forgot one instance.
cell_h
should belabel_h
.PW, PH = 842, 1190 # A3 page width and height page_margin = 40 # the margin for the whole page amount = 50 # how many labels to draw in total per_page = 10 # how many labels per page gap = 10 # the gap between the labels # the next line calculates the heigth for the label label_h = (PH - ((per_page-1)*gap) - 2 * page_margin ) / per_page for i in range(amount): if i % per_page == 0: newPage(PW, PH) y = PH - page_margin - label_h rect(page_margin, y, width() - 2*page_margin, label_h) y -= label_h + gap
-
use the callback
width()
andheight()
to retrieve the dimentions of the current page.(the drawBot forum is almost closed, I keep it as read only, to much spam, sorry, move to drawBot channel in the RoboFont discord)
-
@frederik
Sad that the forum will be discontinued, so thanks a lot for keeping it up for so long and leaving it in read only mode.I will still try to post one more question, since I am frequently wondering how to do that in a clever way.
Like in the example above I usually try to have all the settings (like the definition of the page dimensions) in one place and before doing any drawing.
But I can only get the width if there is already a page (or it will be the default 1000).
How could I get the dimenations of eg an A3 page without callingnewPage('A3')
?Again thanks for drawbot and the forum. See you on discord!
-
sad it is...
you can use
w, h = sizes("A3")
see https://drawbot.com/content/canvas/pages.html#drawBot.sizes
-
@frederik ah, that is super helpful!
How did I miss this great feature?
Thanks again