Two small bugs with Edit > Copy As JavaScript

Version:

macOS OG 7.4 (v179.8 r291433)

Problems:

  1. Order of elements in group reversed
  2. automationAction strings unquoted ( leading to error message in lieu of execution )

Reversed order of Group elements

If we use Edit > Copy As JavaScript on a group like,

execution of the generated code does regenerate a group, but with an unexpectedly reversed element order
(and, incidentally, lost horizontal text alignment):

Code chokes on unquoted Plugin ID and Action ID

Edit > Copy As JavaScript JS code currently generates an error rather than a set of graphics if any of the copied elements have automation actions. This is simply because the Plugin ID and Action ID strings are not yet getting quoted in the generated JS, and are therefore misinterpreted by the JS interpreter as unresolvable name bindings. (undeclared variables)

    g3.automationAction = [com.complexpoint.OmniGraffle, toggle]

Thanks for the bug reports, working on them now!

1 Like

Thanks ! If you are looking at that, I wonder if it is also a good moment to look at the Quantum Uncertainty bug in which using Edit > Copy As JavaScript immediately mutates the geometry of certain shapes.

It turns out that the same bug changes the position and size of some shapes if we seek any knowledge of their .shapeVertices or .shapeControlPoints through the omniJS interface. (Seen in both macOS and iOS in current builds).

Perhaps this sheds some light on what is happening when Copy As JS mutates shape geometry ?

To reproduce:

First, create one of the polygonal shapes like a Pentagon, and start with a known size:

So far so good.

Now enquire after the .shapeVertices of the Pentagon, and re-check its geometry:

g.geometry
g.shapeVertices
g.geometry

Bug … simply enquiring after the .shapeVertices has shrunk our shape by over 6% in width, and over 10% in height … (the shape has also moved a couple of points …)
(look at the second request for g.geometry below)

Reading the .shapeControlPoints property may have an even more dramatic effect, at least on the AdjustableStar shape. (25% - 28% shrinkage):

Code and response from Console
g = document.windows[0].selection.graphics[0]
[object Shape]
g.shape
AdjustableStar
g.geometry
[object Rect: (226.429650353308, 219.837279773695, 47.1398939107245, 42.5969600262851)]
g.geometry = new Rect(200, 200, 100, 100)
[object Rect: (200.0, 200.0, 100.0, 100.0)]
g.geometry
[object Rect: (200.0, 200.0, 100.0, 100.0)]
g.shapeControlPoints
[object Point: (254.755282609718, 214.635255912781)],[object Point: (254.755282609718, 214.635255912781)],[object Point: (260.103129010611, 231.094235763816)],[object Point: (260.103129010611, 231.094235763816)],[object Point: (260.772500380058, 233.154349135948)],[object Point: (262.692280336141, 234.549150918455)],[object Point: (264.858411711722, 234.549150878861)],[object Point: (264.858411711722, 234.549150878861)],[object Point: (282.164407171801, 234.549150562531)],[object Point: (282.164407171801, 234.549150562531)],[object Point: (284.925830920955, 234.549150512056)],[object Point: (287.164407212719, 236.787726721984)],[object Point: (287.164407263194, 239.549150471138)],[object Point: (287.16440729245, 241.149675596113)],[object Point: (286.398185493943, 242.65347054741)],[object Point: (285.103333450718, 243.594235588126)],[object Point: (285.103333450718, 243.594235588126)],[object Point: (271.102488833004, 253.766444239885)],[object Point: (271.102488833004, 253.766444239885)],[object Point: (269.350051714838, 255.039664284947)],[object Point: (268.616761022535, 257.296500976612)],[object Point: (269.286132467295, 259.356614324274)],[object Point: (269.286132467295, 259.356614324274)],[object Point: (274.633979469882, 275.815593979806)],[object Point: (274.633979469882, 275.815593979806)],[object Point: (275.487306385046, 278.441864015093)],[object Point: (274.05005201073, 281.262634676671)],[object Point: (271.423781975443, 282.115961591834)],[object Point: (269.901592134882, 282.610551083199)],[object Point: (268.23462259008, 282.346529044808)],[object Point: (266.939770581247, 281.405763956756)],[object Point: (266.939770581247, 281.405763956756)],[object Point: (252.938926335401, 271.233554793165)],[object Point: (252.938926335401, 271.233554793165)],[object Point: (251.18648926378, 269.960334684038)],[object Point: (248.81351073622, 269.960334684038)],[object Point: (247.061073664599, 271.233554793165)],[object Point: (247.061073664599, 271.233554793165)],[object Point: (233.060229418753, 281.405763956756)],[object Point: (233.060229418753, 281.405763956756)],[object Point: (230.826190706685, 283.028888152674)],[object Point: (227.699342361115, 282.533644086069)],[object Point: (226.076218165197, 280.299605374001)],[object Point: (225.135453077145, 279.004753365169)],[object Point: (224.871431038753, 277.337783820367)],[object Point: (225.366020530118, 275.815593979806)],[object Point: (225.366020530118, 275.815593979806)],[object Point: (230.713867532705, 259.356614324274)],[object Point: (230.713867532705, 259.356614324274)],[object Point: (231.383238977465, 257.296500976612)],[object Point: (230.649948285162, 255.039664284947)],[object Point: (228.897511166996, 253.766444239885)],[object Point: (228.897511166996, 253.766444239885)],[object Point: (214.896666549282, 243.594235588126)],[object Point: (214.896666549282, 243.594235588126)],[object Point: (212.662627777877, 241.971111473878)],[object Point: (212.167383596964, 238.844263146412)],[object Point: (213.790507711211, 236.610224375008)],[object Point: (214.731272751927, 235.315372331783)],[object Point: (216.235067703224, 234.549150533276)],[object Point: (217.835592828199, 234.549150562531)],[object Point: (217.835592828199, 234.549150562531)],[object Point: (235.141588288278, 234.549150878861)],[object Point: (235.141588288278, 234.549150878861)],[object Point: (237.307719663859, 234.549150918455)],[object Point: (239.227499619942, 233.154349135948)],[object Point: (239.896870989389, 231.094235763816)],[object Point: (239.896870989389, 231.094235763816)],[object Point: (245.244717390282, 214.635255912781)],[object Point: (245.244717390282, 214.635255912781)],[object Point: (246.098044209437, 212.008985846299)],[object Point: (248.918814818472, 210.571731368864)],[object Point: (251.545084884955, 211.425058188018)],[object Point: (253.067274743596, 211.919647623736)],[object Point: (254.260693174, 213.11306605414)],[object Point: (254.755282609718, 214.635255912781)],[object Point: (254.755282609718, 214.635255912781)],[object Point: (254.755282609718, 214.635255912781)]
g.geometry
[object Rect: (212.83523804277, 211.178990801344, 74.3291692204249, 71.1820429311419)]

All three of these issues should be fixed in r291897 and later. Thanks for the reports!

1 Like

Brilliant. Thank you !

I realise, of course, this morning, that the z-order reversal was not, in fact, peculiar to groups - it’s just a more general side-effect of using the original (copy-time) z-order (without inversion), as the shape-creation sequence.

But I guess your fix has probably already addressed that :-)

Yep, it was a general z-order reversal, and is fixed overall.

1 Like

Many thanks !

One more minor issue which I’ve just noticed - if a user applies Edit > Copy As JavaScript to a shape which has a multiline note, the generated code won’t immediately compile for lack of ‘\n’ or ‘\r’ stringification of the line endings.

For example, given a shape with a note like this:

We are currently getting an ‘unexpected EOF’ JS interpreter error from generated code like:

( Applying JSON.stringify to the .notes value here yields:

      "notes": "From 90.0º\rTo 180.0º"

The notes issue was the same problem as quoting action/plugin ID strings, and got fixed along with it, so you should be good there with a new version. (All places with unquoted string property values in Copy As JavaScript generation should’ve been fixed by that change.)

1 Like

Thank you !

Is it possible to predict when the next build will be released ?

( The latest one here: https://omnistaging.omnigroup.com/omnigraffle/ seems to be Jun 29 )

Update has now arrived, but still seeing the group z-order reversal (and unquoted userData and automation action strings) in 7.4.1 test (v179.11 r292770)

Group on left is rendered by Edit > Copy As > JavaScript to code which creates group on right, losing z order and text horizontal alignment:

// Floating point values in this script may be rounded, resulting in minor visual differences from the original
var canvas = document.windows[0].selection.canvas
var g1 = canvas.newShape()
var g2 = canvas.newShape()
var g3 = canvas.newShape()
var g4 = canvas.newShape()
var g5 = new Group([g1, g2, g3, g4])
g1.textUnitRect = new Rect(0.10, 0.15, 0.80, 0.70)
g1.shape = "Circle"
g1.text = "A"
g1.cornerRadius = 5
g1.textVerticalPadding = 0
g1.autosizing = TextAutosizing.Clip
g1.textSize = 17
g1.geometry = new Rect(-1.42, 9.92, 68.03, 68.03)
g1.strokeColor = Color.RGB(0.639474272727966, 0.641759514808655, 0.753086268901825)
g1.magnets = [new Point(0.00, 1.00), new Point(0.00, -1.00)]
g1.strokeThickness = 0.5
g1.fontName = "Helvetica-Bold"
g2.textUnitRect = new Rect(0.10, 0.15, 0.80, 0.70)
g2.shape = "Circle"
g2.text = "B"
g2.cornerRadius = 5
g2.textVerticalPadding = 0
g2.autosizing = TextAutosizing.Clip
g2.textSize = 17
g2.geometry = new Rect(-39.69, -24.09, 68.03, 68.03)
g2.strokeColor = Color.RGB(0.639474272727966, 0.641759514808655, 0.753086268901825)
g2.magnets = [new Point(0.00, 1.00), new Point(0.00, -1.00)]
g2.strokeThickness = 0.5
g2.fontName = "Helvetica-Bold"
g3.textUnitRect = new Rect(0.10, 0.15, 0.80, 0.70)
g3.shape = "Circle"
g3.text = "C"
g3.cornerRadius = 5
g3.textVerticalPadding = 0
g3.autosizing = TextAutosizing.Clip
g3.textSize = 17
g3.geometry = new Rect(-76.54, -58.11, 68.03, 68.03)
g3.strokeColor = Color.RGB(0.639474272727966, 0.641759514808655, 0.753086268901825)
g3.magnets = [new Point(0.00, 1.00), new Point(0.00, -1.00)]
g3.strokeThickness = 0.5
g3.fontName = "Helvetica-Bold"
g4.textUnitRect = new Rect(0.10, 0.15, 0.80, 0.70)
g4.shape = "Circle"
g4.text = "D"
g4.cornerRadius = 5
g4.textVerticalPadding = 0
g4.autosizing = TextAutosizing.Clip
g4.textSize = 17
g4.geometry = new Rect(-113.39, -85.04, 68.03, 68.03)
g4.strokeColor = Color.RGB(0.639474272727966, 0.641759514808655, 0.753086268901825)
g4.magnets = [new Point(0.00, 1.00), new Point(0.00, -1.00)]
g4.strokeThickness = 0.5
g4.fontName = "Helvetica-Bold"
g5.geometry = new Rect(-113.39, -85.04, 180.00, 162.99)

In addition to rebuilding the group in the reverse order, the code also needs to explicitly specify the textHorizontalAlignment .

There is a model ⇄ display breakdown when this is left to the default. The code and inspector both think that the text is centered, but the GUI display is for some reason left-aligned.

One workaround is to avoid the expectation that the defaults mechanism will work in this case, and to generate a code line which explicitly specifies center-alignment.

I think Greg’s fixes for this are coming in v7.5, not in the 7.4.1 builds you’re seeing. We’ll try to get test builds of 7.5 available to you ASAP (i.e. this week, possibly tomorrow).

1 Like