Help with code & combining idea



  • Hi,

    I've this code to export some labels I need to print.

    Screenshot 2024-07-10 at 00.45.19.png

    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.

    Screenshot 2024-07-10 at 00.47.05.png

    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 the newPage 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 be label_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
    

Log in to reply