How to create and link elements by code?

Hi all,

In Modeler, we can create elements and link them by drag. However, I want to implement those operations by code.

For example, it will create and display a rectangle(rect1) when I first click a button. Then when I click the button again, it will create and display another rectangle(rect2) and link the two rectangles (rec1->rect2).

Is there any methods to implement the operation. Can someone help, Thanks!!!

This question has been asked many times: Best practice for creating process programmatically

Please make sure to search for existing topics before opening a new one.