Unfortunately, the source is not refined to be
implemented on the fly.

You should have a look at the algorythm of the editor, to see how it
creates the node-gid.

Dont forget to connect the nodes with the "lines",
This must be done for each node seperately.