Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Typeface Oriented Grid Generator – open with Drawbot and launch!
####################################
# Typeface oriented grid generator #
####################################
"""
Usage:
- open .py file with Drawbot (drawbot.readthedocs.org) and launch
- use what the script prints out to set your InDesign document
"""
from drawBot import size, stroke, fill, translate, rect, line
FROM_MM_TO_PT = 2.834627813
### Functions
def modularCut(massimo, columns_number):
for layout_width in reversed(range(int(massimo))):
column = (layout_width - gutter*(columns_number-1)) / columns_number
if (column > 0) and (column % line_height == 0):
return column
### Variables
line_height = 12 # pt
gutter = 12 # pt
# Margins
margin_external = line_height * 6
margin_internal = line_height * 5
margin_superior = line_height * 5
margin_inferior = line_height * 5
# Starting sheet dimensions
sheet_width, sheet_height = 420*FROM_MM_TO_PT, 297*FROM_MM_TO_PT
# Single page columns number
columns_number = 3
### Instructions
size(2000, 2000)
stroke(0)
fill(255)
# Margins
translate(150, 150)
# Drawing sheet
rect(0, 0, sheet_width, sheet_height)
# calc modular layout and column
column_width = modularCut(sheet_width/2 - (margin_external+margin_internal), columns_number)
print(f'Column Width: {column_width}')
print(f'Lines of text per column: {column_width/line_height:.0f}')
layout_width = column_width * columns_number + gutter * (columns_number - 1)
layout_height = modularCut(sheet_height - (margin_superior+margin_inferior), 1)
# calc modular page dimensions
page_width = (layout_width + margin_external + margin_internal)*2
page_height = layout_height + margin_inferior + margin_superior
# bleed calc
bleed_external = (sheet_width - page_width)/2
bleed_vertical = (sheet_height - page_height)/2
# moving canvas origin point
translate(bleed_external, bleed_vertical)
# drawing page rect
rect(0, 0, page_width, page_height)
# drawing pages folding line
line((page_width/2, 0), (page_width/2, page_height))
# left layout
rect(margin_external, margin_inferior, layout_width, layout_height)
# right layout
rect(page_width/2 + margin_internal, margin_inferior, layout_width, layout_height)
# baseline grid
translate(0, margin_inferior)
for i in range(int((page_height-margin_inferior-margin_superior)/line_height)):
quota = i * line_height
line((margin_external, quota), (margin_external + layout_width, quota)) # left
line((page_width/2 + margin_internal, quota), (page_width/2 + margin_internal + layout_width, quota)) # right
print(f'Rows: {i}')
# left column
translate(margin_external, 0)
for index in range(columns_number):
ascissa = index * column_width + gutter * (index-1) + gutter
rect(ascissa, 0, column_width, layout_height)
# right column
translate(layout_width + margin_internal*2, 0)
for i in range(columns_number):
ascissa = i * column_width + gutter * (i-1) + gutter
rect(ascissa, 0, column_width, layout_height)
# mini-columns per column
for sub in range(int(column_width//line_height),
int(column_width),
int(column_width//line_height)):
line((ascissa+sub, 0), (ascissa+sub, 100))
# Printing output for indesign new document panel
print('-'*20)
print(f'Width: {page_width/2} pt')
print(f'Height: {page_height} pt')
print('-'*20)
print(f'Margin internal: {margin_internal} pt')
print(f'Margin external: {margin_external} pt')
print(f'Margin superior: {margin_superior} pt')
print(f'Margin inferior: {margin_inferior} pt')
print('-'*20)
print(f'Bleed internal: {0} pt')
print(f'Bleed external: {bleed_external:.2f} pt')
print(f'Bleed superior: {bleed_vertical:.2f} pt')
print(f'Bleed inferior: {bleed_vertical:.2f} pt')
print('-'*20)
print(f'Margin + Bleed internal: {margin_internal+0:.2f} pt')
print(f'Margin + Bleed external: {margin_external+bleed_external:.2f} pt')
print(f'Margin + Bleed superior: {margin_superior+bleed_vertical:.2f} pt')
print(f'Margin + Bleed inferior: {margin_inferior+bleed_vertical:.2f} pt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment