What is the proper way of reordering the newly built elements?

This might be an easy thing to do, but I need to make sure that I am taking the right approach. When we create a new element through the API, how can we get the z-order of a specific element and place that newly built element right at the top of it?

Are you referring to elements on the canvas or within a dialog?

Hi Kerri! On the canvas.
To be more clear, for example, you create the element A through the API. Now there is an element on the artboard (element B) that you want the element A to be placed right at the top of it.

After importing the ‘commands’ package you can use its methods.
For example:

// import ‘commands’ package
const commands = require(“commands”);

// select B element
selection.items = [B];

// apply method

Yes, but doesn’t it send the element B all the way back? Which I do not intend to do.
Note that I do not intend to reorder the existing elements, but to place the newly built element right at the top of an existing one. Also, there might be many elements on the page, and sending the element B toBack will cause more ordering complications.

@peterflynn / @stevekwak Can you assist with the above?

What you want is parent.addChildAfter(newNode, nodeToPutItAbove)


Wow, exactly what I wanted, thank you!