I was staring at the below code last night for some minutes, wondering why it was failing in the most obvious way, and finally laughed when I figured it out. Thought this might help someone else.
So, annotationNodes
is a perfectly fine array of nodes (all console.log
'ed and confirmed), but as soon as I assigned it to selection.items
, the latter would be entirely empty, and of course the commands.group()
would fail.
Seemed plain as the nose on your face that something was completely crazy.
Those moments of disbelief were quite memorable. I started to doubt whether I had the “real” selection
or the real commands
or something pretty basic. Then I started to doubt my sanity.
Then I Read The Fine Documentation for .group()
one last time in desperation, and noticed a small note that grouping wouldn’t accept locked nodes (same as the UI). So then the light went on, and, sure enough, all the nodes in annotationNodes
were locked (I had created them that way for a reason). Easy fix.
// Group all the annotations and associate it with the board.
if (annotationNodes.length > 0) {
selection.items = annotationNodes
commands.group()
let group = selection.items[0]
group.locked = true
group.name = `{{d2d annotation group}}`
boardSetTextDecorationGuid(board, group.guid)
}
}