Graphic IDs and scripting

In OmniGraffle 7.8 we have made the ID attribute on Graphics far less prone to be changed when the graphic itself is manipulated, plus the ID should be consistent now when opening and closing documents. If you use the ID attribute in your scripts we would really like some feedback on how things are working in the Public Test version of OmniGraffle 7.8.

The latest 7.8 build also has scripting related crash fixes!

Details about what has changed in version 7.8 are here: Help test OmniGraffle 7.8 for Mac

You can download the latest 7.8 build here: https://omnistaging.omnigroup.com/omnigraffle/

Thank you for your help!
Dan

1 Like

Here’s a handy Omni Automation plugin for viewing the ID of the selected graphic. Copy to a text editor and save as a file with the “omnijs” file extension. Put in PlugIns folder (Automation menu)

// COPY & PASTE into text editor app. EDIT & SAVE with “.omnijs” file extension.
/*{
	"type": "action",
	"targets": ["omnigraffle"],
	"author": "Otto Automator",
	"description": "Shows the ID of the selected graphic.",
	"label": "ID of Selected Graphic",
	"paletteLabel": "Graphic ID"
}*/
var _ = function(){
	var action = new PlugIn.Action(function(selection, sender){
		// action code
		// selection options: canvas, document, graphics, lines, solids, view
		graphic = selection.graphics[0]
		new Alert('Graphic ID',graphic.id.toString()).show(function(result){})
	});

	action.validate = function(selection, sender){
		// validation code
		// selection options: canvas, document, graphics, lines, solids, view
		if(selection.graphics.length === 1){return true} else {return false}
	};
	
	return action;
}();
_;
1 Like

Just an FYI:

Graphic IDs should remain persistent except in the following instances:

  1. Graphic is Cut/Paste
  2. Graphic is moved to another canvas
  3. Graphic is moved to a shared layer
  4. Graphic is moved to another document

Cheers. – SAL

1 Like

Or, for a light (macOS) (Script Editor etc) version:

(() => {
    
    const showId = () => {
        const
            gs = document.windows[0]
            .selection
            .graphics;
        return (
            new Alert(
                'Graphic ID',
                gs.length > 0 ? (
                    `${gs[0].id}`
                ) : 'No graphic selected'
            )
            .show(() => true)
        );
    };

    const og = Application('OmniGraffle');
    return (
        og.activate(),
        og.evaluateJavascript(
            '(' + showId + ')()'
        )
    );
})();

Translated back to the cross-platform plugin equivalent
(which also needs a graphic file for the button image, and a manifest.json entry):

var _ = (() => {
    const
        action = new PlugIn.Action(
            selection => new Alert(
                'Graphic ID',
                `${selection.graphics[0].id}`
            )
            .show(() => true)
        );
    return (
        action.validate = selection =>
        0 < selection.graphics.length,
        action
    );
})();
_;

Thanks, this was just the thing i was looking for. Really appreciate it.