How do I get geometry information with JXA?

Hello, members.

OG6 and JavaScript for Automation(JXA) question.
Is it possible to get geometry(x,y,width,height) information for objects?

I want to get the following attributes.

  • position(x,y) milli meter
  • width: milli meter
  • height: milli meter
  • text value (done)
  • align

I wrote the following code, but I don’t know how to get geometry information.
Could you tell me how to get it?

Best regards.

(function() {
	'use strict';
	var og = Application('OmniGraffle');
	var w = og.windows[0];
	var g = w.canvas.graphics;

	for ( var i = 0 ; i < g.length ; i++ ){
		var a = g[i].properties();
		console.log(a.text)
//		var b = g.origin();
//		console.log(b);
	}

})();


Hiroyuki Sato

Here is one approach to getting the millimeter values in a JSON format (for the selected objects).

On Sierra you can use ES6 or ES5 JS, but before Sierra it needs to be ES5:

(function () {
    'use strict';

    var ws = Application('OmniGraffle').windows,
        w = ws.length ? ws[0] : undefined,
        xs = w ? w.selection() : [];

    // 1 point = 0.3528 mm
    // mm :: Num -> Num
    var mm = function mm(x) {
        return 0.3528 * x;
    };

    // show :: a -> String
    var show = function show(x) {
        return JSON.stringify(x, null, 2);
    };

    return show(xs.map(function (x) {

        var lstPosn = x.origin().map(mm),
            lstSize = x.size().map(mm);

        return {
            position: lstPosn,
            width: lstSize[0],
            height: lstSize[1],
            text: x.text(), // if you don't need formatting
            alignment: x.textPlacement()
        };
    }));
})();

( Tested with OG 6.61 )

Hello draft8

Thanks!. I’ll try it.