How to change the order of subsymbols in the hierarchy using scripting

Hi,

Is it possible to change the order of the subsymbols in the hierarchy using scripting? I am trying to create a book with a few pages. Each page is a subsymbol that allows the user to flip it back and forth. When a user flips a page, I want that page (subsymbol) to be moved to the bottom of the hierarchy so that it will not be blocked by other pages (subsymbols).

Thank you.

Hi @k.loke,

Awesome question, you’ll be happy to know the answer is yes!

Firstly you will need to get the parent node. If you want the whole Hierarchy, this will be the root node.

You can then remove the specific child (subsymbol) and push it back at the end of the parent node.

As an example -

If your script is a direct child of the root, you can replace symbol.nodes.root. with parent.

let subsymbolToMove = symbol.nodes.root.remove(symbol.nodes.subsymbol);

symbol.nodes.root.push(subsymbolToMove);

This article and the corresponding ones off it might help - https://docs.zap.works/studio/scripting/reference/group/

George

2 Likes

Thank you, George.

Your solution works well for me.

I have also tried pushing the subsymbol to the end of the parent node without removing it first, and it works too. In this case, am I duplicating the subsymbol to the end of the parent node if I didn’t remove it in the first place?

1 Like

No, you are not duplicating. You are creating a reference to the original node. Change the color of either of them, you will see that the “other” will change as well.

2 Likes

Thanks Marcus.

1 Like