I notice that Copy as JavaScript is dropping them, and I haven’t yet found syntax for successfully setting them.
(This works in AppleScript/JXA with a list of [x, y] pairs, and I have tried in OmniJS both with that data format and with an array of {x:1, y:0} etc dictionaries, but so far either I haven’t yet found the trick, or magnets are not yet scriptable.
(It looks as if they are read-only in OmniJS, at least for the moment,
// Error: The property "magnets" is read-only. undefined:21
but I am finding it hard to read them too)
Context
Scripting magnets is the first thing that one needs in order to rotate a vertical tree into a horizontal tree.
Also, a script-created tree whose nodes lack magnets is a little too drunken and disorderly for easy legibility - especially with orthogonal links:
For refce, in JavaScript for Automation:
// Setting magnets in JavaScript for Automation
(() => {
'use strict';
const
og = Application("OmniGraffle"),
ds = og.documents,
d = ds.length > 0 ? ds[0] : undefined;
if (d) {
const
cnvs = d.canvases(),
cnv = cnvs.length ? cnvs[0] : undefined,
shps = cnv ? cnv.shapes : [];
// WRITE
shps().forEach(function(x) { // Give North South magnets to all shapes
x.magnets = [[0, 1], [0, -1]]
})
}
})();
There was a bug in the JavaScript magnet implementation, which is fixed as of revision 283343, so setting/getting/copy as Javascript should all work correctly with magnets as soon as a new build goes out.
In other news, we seem to be able, at present, to reliably crash OG7 with an omniJS script if the list of graphic properties specified when a Graphic is created includes magnet settings like:
magnets: [[0,1], [0,-1]]
Which seems to be suggested by the omniJS documents description of them as Array of Array
A console test seems, however, to suggest a different type – an Array of some other objects:
Any idea what a correct magnet-setting syntax might look like at the moment ?
Thanks for this! I passed it along and one of our other engineers fixed these issues today. The API Reference should show “Array of Points” and if you pass the wrong thing it won’t crash any more, just return a JS error as of r290358.