Grid properties


#1

Is there a way to get/set a document’s grid properties?


#2

At least for AppleScript, the scripting dictionary shows the following properties for the grid of a canvas - therefore there is a way…
grid n [inh. [item]] : The grid of a canvas
properties
draws in front (boolean) : Does the grid draw in front of all shapes?
major (boolean) : Does the grid have ‘major’ lines?
major spacing (integer) : The number of minor grid lines for each major line
script grid color ([color]) : Color of the grid
script major grid color ([color]) : Color of major lines
snaps (boolean) : Do points snap to the grid?
spacing (real) : Number of pixels between minor grid lines
visible (boolean) : Is the grid visible?


#3

Reading them through the omniJS interface, you could paste and enter something like this in the automation console:

(() => {
    'use strict';

    const
        grid = canvases[0].grid,
        ks = Object.getOwnPropertyNames(grid.constructor.prototype)
        .filter(k => 'constructor' !== k)

    return ks.reduce((a, k) => {
        const v = grid[k];
        return a + k + '\t' + (
            'object' !== typeof v ? (
                v + '\n'
            ) : 'RGB: (' + [v.red, v.green, v.blue]
            .map(x => 255 * x)
            .join(', ') + ')\n'
        );
    }, '');
})();

to obtain a result analogous to:

drawsInFront    true
majorSpacing    5
majorColor    RGB: (47.93519541621208, 47.936570942401886, 47.935833781957626)
minorColor    RGB: (143.72830599546432, 152.28140383958817, 193.3756971359253)
spacing    4
snaps    false
visible    true

#4

And, of course, you can update (and re-check) properties by reversing this process:

(() => {
    'use strict';

    const
        grid = canvases[0].grid,
        ks = ['drawsInFront', 'majorSpacing', 'majorColor', 'minorColor',
            'spacing', 'snaps', 'visible'
        ];

    return (
        // Effects
        grid.drawsInFront = true,
        grid.majorSpacing = 25,
        grid.majorColor = Color.blue,
        grid.minorColor = Color.gray,
        grid.spacing = 5,
        grid.snaps = true,
        grid.visible = true,

        // Values
        ks.reduce((a, k) => {
            const v = grid[k];
            return a + k + '\t' + (
                'object' !== typeof v ? (
                    v + '\n'
                ) : 'RGB: (' + [v.red, v.green, v.blue]
                .map(x => 255 * x)
                .join(', ') + ')\n'
            );
        }, '')
    );
})();

returning the list of updated grid properties:

drawsInFront    true
majorSpacing    25
majorColor    RGB: (0, 0, 255)
minorColor    RGB: (127.5, 127.5, 127.5)
spacing    5
snaps    true
visible    true

#5

Documentation concerning grids are also found at the Omni Automation website:

https://omni-automation.com/omnigraffle/grid-00.html

Cheers!

P.S. Try the toothpick examples!


#6

@Sal thanks! Is this page new? I totally missed it. Anyway, I see the Grid is a read only property, any ETA on when it can be set also?

Thx

BTW, whats in the pipe line for omni-automation? I’d be rather interested to hear what you guys plan to cook up in the near future. Tell us what you can please!


#7

@draft8 Thanks, need to give that a go…


#8

The Grid object is a read-only reference, but all of its properties are RW

(you can test the setting of grid properties with the code above in
https://discourse.omnigroup.com/t/grid-properties/44324/4?u=draft8)


#9

Greetings! That page has been up for a while. I updated it last year with the toothpick examples in the hope it would make it a bit more fun and interesting. Making the grid writable is on the wish list for sure!

As to what is coming up for Omni Automation, I”ll leave announcements to Ken ;-)

HINT: very very very cool stuff!