occult center and gold section guides for indesign applescript

Update 20080612: This script hasn't worked since InDesign CS1. There may be an easy way to fix it so that it does, and there may be something in here that someone can use. I probably won't be working on it much since I don't use InDesign much these days but I may at some point.

this applescript will make guides on your first master spread corresponding to golden sections and occult points. it has been tested on macos 10.2.4 and indesign 2.0.2-- i can't promise much beyond that, although i suspect it'll work under different systems. to use it copy the text below and paste it into your script editor. from there, drop it into your scripts folder in the indesign application folder and it should be accessible via the scripts menu within indesign.

gold sections have been used for thousands of years for a number of things including architecture, book design, painting, and sculpture to create divisions that are inherently pleasing to the eye. a number of biological phenomena follow the golden section (the nautilus being the most famous), and it contains a number of unique mathematical properties. for more information you may visit this site, which deals mainly with its architectural properties.

occult centers are the intersections of the diagonals of any non-square rectangle and the line which crosses through the adjacent corner at a right angle to the diagonal. in the following diagram, the golden sections are yellow and the occult centers are red.

the astute reader will notice that in this particular diagram, the vertical gold sections create squares within the rectangle-- that's because this rectangle is in the golden section proportion, which replicates itself.

i would love to hear any suggestions or additions to this script, even if you're not sure how to implement them-- i'm fairly hopeless with applescript myself. if anyone makes a visual basic version and would like me to post it here, i'd be happy to do that as well.

if you'd like to check out a more general application of gold sections, you can grab an SVG (importable into illustrator and cross-plaform) file from here.

as an aside, and for anyone who arrives here via a google search, the formula for determining occult centers (which i had a beast of a time figuring out) is as follows:

given a rectangle with sides x and y,
y'' (y double prime, or the height of the first occult center) is equal to
x(sin Φ)^2/tan Φ (where Φ is the arctangent (or inverse tangent) of y/x)
and x'' is equal to x (sin Φ)^2/(tan Φ)^2

update 20030406: the text appears to have gotten munged somehow-- i think it was the greater than and lesser than signs. if anyone tried to use the script copied and pasted from here i apologize. i'll fix the script text below, but i'm not sure if it'll copy and paste right, so here's a disc image instead.
mini-update-- it seems to copy and paste fine.

the script follows:

--guidebot
--makes guides at gold sections and other helpful places
--suggestions and improvements welcome at http://tfisf.com



tell application "InDesign 2.0.2"
    tell document 1
        --gold sections
        set xval to page width of document preferences of document 1
        set yval to page height of document preferences of document 1
        set gseca to 0.61803
        set gsecb to 0.38197
        set gsecxa1 to xval * gseca
        set gsecxb1 to xval * gsecb
        set gsecya1 to yval * gseca
        set gsecyb1 to yval * gsecb
        set gsecya2 to (xval * gseca) + xval
        set gsecyb2 to (xval * gsecb) + xval
        --rebate! rebate! ok!
        if yval > xval then set rebat to yval - xval
        if yval < xval then set rebat to xval - yval
        if yval < xval then set rebatb to (xval - yval) + xval
        if yval < xval then set rebatc to xval + yval
        --medieval pages
        set medxa to 2 * (xval / 9)
        set medya to yval / 9
        set medxb to xval - (medxa / 2)
        set medxc to xval + (medxa / 2)
        set medxd to (2 * xval) - medxa
        set medyb to yval - (medya * 2)
        --chewy occult centers- this was the rough part
        set tana to yval / xval
        set anglea to my inverse_tangent_of(tana)
        set asin to my sine_of(anglea)
        set sinsq to asin * asin
        set tansq to tana * tana
        set xdpa to (xval * sinsq) / tansq
        set xdpb to xval - xdpa
        set xdpc to xval + xdpa
        set xdpd to (2 * xval) - xdpa
        set ydpa to (xval * sinsq) / tana
        set ydpb to yval - ydpa
        -- guides
        set mspread to master spread 1
        tell mspread
            --gold sections
            make new guide at mspread with properties {location:gsecxa1, guide color:{255, 255, 102}, orientation:vertical}
            make new guide at mspread with properties {location:gsecxb1, guide color:{255, 255, 102}, orientation:vertical}
            make new guide at mspread with properties {location:gsecya1, guide color:{255, 255, 102}, orientation:horizontal}
            make new guide at mspread with properties {location:gsecyb1, guide color:{255, 255, 102}, orientation:horizontal}
            make new guide at mspread with properties {location:gsecya2, guide color:{255, 255, 102}, orientation:vertical}
            make new guide at mspread with properties {location:gsecyb2, guide color:{255, 255, 102}, orientation:vertical}
            --rebatements
            if yval > xval then make new guide at mspread with properties {location:xval, guide color:{102, 255, 102}, orientation:horizontal}
            if yval > xval then make new guide at mspread with properties {location:rebat, guide color:{102, 255, 102}, orientation:horizontal}
            if yval < xval then make new guide at mspread with properties {location:yval, guide color:{102, 255, 102}, orientation:vertical}
            if yval < xval then make new guide at mspread with properties {location:rebat, guide color:{102, 255, 102}, orientation:vertical}
            if yval < xval then make new guide at mspread with properties {location:rebatb, guide color:{102, 255, 102}, orientation:vertical}
            if yval < xval then make new guide at mspread with properties {location:rebatc, guide color:{102, 255, 102}, orientation:vertical}
            --occult centers
            make new guide at mspread with properties {location:xdpa, guide color:{255, 102, 255}, orientation:vertical}
            make new guide at mspread with properties {location:xdpb, guide color:{255, 102, 255}, orientation:vertical}
            make new guide at mspread with properties {location:xdpc, guide color:{255, 102, 255}, orientation:vertical}
            make new guide at mspread with properties {location:xdpd, guide color:{255, 102, 255}, orientation:vertical}
            make new guide at mspread with properties {location:ydpa, guide color:{255, 102, 255}, orientation:horizontal}
            make new guide at mspread with properties {location:ydpb, guide color:{255, 102, 255}, orientation:horizontal}
            --medieval pages
            make new guide at mspread with properties {location:medxa, guide color:{102, 102, 102}, orientation:vertical}
            make new guide at mspread with properties {location:medxb, guide color:{102, 102, 102}, orientation:vertical}
            make new guide at mspread with properties {location:medxc, guide color:{102, 102, 102}, orientation:vertical}
            make new guide at mspread with properties {location:medxd, guide color:{102, 102, 102}, orientation:vertical}
            make new guide at mspread with properties {location:medya, guide color:{102, 102, 102}, orientation:horizontal}
            make new guide at mspread with properties {location:medyb, guide color:{102, 102, 102}, orientation:horizontal}
        end tell
    end tell
    
end tell
on inverse_tangent_of(tana)
    set complimentFlag to false
    if tana > 1 or tana < -1 then
        set tana to 1 / tana
        set complimentFlag to true
    else if tana = 1 then
        return 45.0
    end if
    
    set answer to 0
    set numerator to tana
    set denominator to 1
    set ratio to tana
    set factor to -(tana ^ 2)
    
    repeat while abs(ratio) > 1.0E-4
        set answer to answer + ratio
        set numerator to numerator * factor
        set denominator to denominator + 2
        set ratio to numerator / denominator
    end repeat
    
    --convert from radians to degrees
    set answer to answer * 360 / (2 * pi)
    
    if complimentFlag is true then
        set answer to 90 - answer
    end if
    
    return answer
end inverse_tangent_of

on sine_of(anglea)
    repeat until anglea ≥ 0 and anglea < 360
        if anglea ≤ 360 then
            set anglea to anglea - 360
        end if
        if anglea < 0 then
            set anglea to anglea + 360
        end if
    end repeat
    
    --convert from degrees to radians
    set anglea to anglea * (2 * pi) / 360
    
    set answer_sin to 0
    set numerator to anglea
    set denominator to 1
    set factor to -(anglea ^ 2)
    
    repeat with i from 3 to 40 by 2
        set answer_sin to answer_sin + numerator / denominator
        set numerator to numerator * factor
        set denominator to denominator * i * (i - 1)
    end repeat
    
    return answer_sin
end sine_of

on abs(numericVariable)
    if numericVariable < 0 then
        return -numericVariable
    else
        return numericVariable
    end if
end abs

what's next

i am trying to figure out what the measurements of points a,b,c,d, and e are in the following diagram. i mistakenly identified point a to be an occult point, but as the illustrations shows, this is clearly not the case. the diagram was reconstructed from robert bringhurst's the elements of typographic style, where it is given as one example of a common medieval page structure. he, in turn, borrowed it from jan tschishold's the form of the book. tschichold appears to have used material from villard de honnecourt in some way, but i don't have the tschichold's book, so i can't be sure. it appears from bringhurst's description that point b is 1/9 (one ninth) the width of the page and 1/9 the height, but that seems too easy. if it turns out that this is the case, it'd be trivial to add it to the script, and if i can verify that this is the case, i'll throw it in.

20100223: update- guidebot wasn't working under CS(1) on MacOS X 10.6.2 and now it does. your mileage may vary of course. "improvements" include sets of guides on their own layers, better colors for layers, sensible names for layers.

toothfish industries
glish
contact paul yoon (that's me)
gold sections in pyramids
user to user forums at adobe