How to change the user's current selection

I’m trying to set the user’s current selection to the parent node by doing the following:

selection.items = [selection.items[0].parent] 

Also tried this:
selection.items = selection.items[0].parent

I keep getting an error that it is out of its context. Don’t think that is the proper way to set the current selection so if anybody could help out that would be much appreciated.

1 Like

Hi @thatgalnatalie,

first of all: welcome to the forums :wave:.

It is only possible to select nodes that are inside the current edit context. This, unfortunately, doesn’t include the parent node.

Cf. Edit Context rules · Adobe XD Plugin Reference

The edit context is the scope within which your plugin is allowed to make edits or set the selection. It is a “neighborhood” of scenegraph nodes around the user’s current selection.

It is therefore, for now, not possible to achieve this.

Other topics that cover this:

I hope this helps (although it’s probably not the answer you were hoping for) :slightly_smiling_face:,
Happy coding,
Pablo

1 Like

@pklaschka Thanks for the quick reply. The thing I’m trying to accomplish is I have a parent node that is currently in a mask and I need to unmask and I know it’s by using commands.ungroup The problem is I can’t seem to figure out how to target the parent node instead of the current selection?

1 Like

:slightly_smiling_face:

Ok (that is one of the things that unfortunately sound simple enough yet are, at least for now, difficult and maybe impossible to achieve with plugins).

To my knowledge (someone from Adobe may be able to confirm this in a few days after their winter break), there is currently no way to ungroup without using commands.ungroup(). Since this command, however, gets applied to the current selection, we are basically stuck with this problem (I’m facing a similar problem at the moment…).

All in all, I believe that (while unfortunate) it is currently your best bet to let your plugin instruct the user to select the parent node and run the plugin again (unless someone has figured out a workaround, although that would have to be very hacky in this case :thinking:).

2 Likes

@pklaschka Thanks for the clarification. This was bugging me for days. I figured if it can be done in the UI, it can be done in the code but I guess not for now.

1 Like