Adding graphic to existing group

So in OmniGraffle 6, I used to be able to do this with AppleScript:

move marker to beginning of (graphics of unit)

to add a graphic object marker to the existing group unit. This doesn’t seem to work anymore in OG7, as Script Debugger gives me an NSUnknownKeyScriptError on this line.

Is there any way to do this in OmniJS? According to the help docs, Group.graphics is read-only, so my initial guess that it’d be something like this just won’t work:

unit.graphics.unshift( marker )

It fails silently.

I tried this too and it didn’t do anything:

marker.orderAbove( unit.graphics[0] )

A couple of times it failed silently and I also got an application crash once or twice.

Ungrouping unit and then regrouping with marker included isn’t an acceptable option, since unit has a name and user data assigned that would have to be saved off first and then restored. Trying to avoid that.

So… little help?

I’m not sure what the answer to this is either – I am probably missing something in the code below, but the order of shapes in the supplied array appears not to determine the order of shapes in the group:

    // groupExpandedAtIndex :: Group -> Int -> Shape -> Group
    const groupExpandedAtIndex = (group, index, shape) => {
      const props = {
          name: group.name,
          userData: group.userData
        },
        xs = group.graphics.slice(0),
        lng = xs.length;

      return (
        group.ungroup(),
        Object.assign(
          new Group(
            index > lng ? (
              xs.concat(shape)
            ) : index < 1 ? (
              [shape].concat(xs)
           ) : xs.slice(0, index).concat(shape).concat(xs.slice(index))
          ),
          props
        )
      )
    };

    return groupExpandedAtIndex(unit, 5, marker)
           .graphics.map(x => x.text);

But if the ordering of the group’s graphic array is not an issue, then I would personally (pace your acceptabiilty criteria :-) do something like this:

    // groupWithAddedShape :: Group -> Shape -> Group
    const groupWithAddedShape = (group, shape) => {
      const
        props = [
          'name',
          'userData',
          'magnets',
          'connectToGroupOnly'
        ].reduce((a, k) => Object.assign(a, {
          [k]: group[k]
        }), {}),
        xs = group.graphics;

      return (
        group.ungroup(),
        Object.assign(
          new Group([shape].concat(xs)),
          props
        )
      );
    };

    const expandedGroup = groupWithAddedShape(unit, marker);

Hmm, that might work, actually. I’ll give it a go. Thanks!

Still, any Omni folks reading this: Seems like something that should be possible out of the box.

1 Like