Jump to/Highlight an Object question

Hi there.

I’m having trouble figuring out how to make a custom plugin action. Does anyone know how to jump to an object by Name or a key value via Object Data? I’m imagining a plugin action that takes the value of target on the clickable object and then highlighting the object with that value’s name or some key value.

For example:

  • Object One Data: target: someObject
  • Object Two Data: id: someObject
  • Where clicking Object One with the Action Browse Tool highlights Object Two.
  • First object with matching id that’s found would be fine. It’s up to the user to create unique id values.

If I use Action > Jump to... > Highlight an Object the action link frequently breaks (linking to the wrong object). I’m not sure if this is due to something I’m doing of if it’s a bug, but it wouldn’t matter if I could use this custom action. I will keep trying to figure it out myself—and if I do I’ll post the answer here—but I’m not an expert at this.


With trial and error I got most of the behavior I want with this script:

var target = document.windows[0].selection.graphics[0].userData['target']
var anchor = document.windows[0].selection.canvas.graphicWithUserDataForKey(target, 'anchor')
document.windows[0].centerVisiblePoint = anchor.geometry.center

But it doesn’t work if the object with the target key isn’t selected. How can I make this work with the Action Browse Tool?? Still trying to find that in the documentation.

I’d also like to figure out how to search all canvases and jump to the object on any canvas.

Ok. This looks through each canvas for the matching object and centers the view on that object.

var target = document.windows[0].selection.graphics[0].userData['target']
    if (cnvs.graphicWithUserDataForKey(target, 'anchor')) {
    document.windows[0].selection.view.canvas = cnvs
    document.windows[0].centerVisiblePoint = document.windows[0].selection.canvas.graphicWithUserDataForKey(target, 'anchor').geometry.center

If there are duplicates it centers each canvas on the object but jumps to the last canvas containing the object. Not perfect but it works for me, for now. If anyone knows how to stop after the first object that matches and jump/center on that, it would be helpful.

Also, still looking for how to use this with the Action Browse Tool so the action-object doesn’t need to be selected to work.

Ok this code adds all the canvases that contain the anchor into an array and picks the first (at index 0):

var doc = document.windows[0]
var target = doc.selection.graphics[0].userData['target']
var anchors = []
    if (cnvs.graphicWithUserDataForKey(target, 'anchor')) {
doc.selection.view.canvas = anchors[0]
doc.centerVisiblePoint = doc.selection.canvas.graphicWithUserDataForKey(target, 'anchor').geometry.center

Still need to find out how to do this without having the object with the action selected.

Ok well I feel dumb. I was missing this detail all along when making a plugin:

var action = new PlugIn.Action(function(selection, sender){...}

I made a new omnijs file using omni-automation’s Action Template Generator and noticed the selection argument, so I took out the document.windows[0] reference on the selection.graphics[0] and it’s working with the Action Browse Tool now. Here’s the full Plugin.Action:

var action = new PlugIn.Action(function(selection, sender){
    var doc = document.windows[0]
	var target = selection.graphics[0].userData['target']
	var anchorCanvases = []
		if (cnvs.graphicWithUserDataForKey(target, 'anchor')) {
	doc.selection.view.canvas = anchorCanvases[0]
	var anchor = doc.selection.canvas.graphicWithUserDataForKey(target, 'anchor')
	doc.centerVisiblePoint = anchor.geometry.center
	doc.selection.view.select([anchor], false)

There may still be a better way to do this, but since the built in methods aren’t working for me this will work for now. Hope all the talking to myself comes in handy to somebody else someday…

1 Like