Fill creates weird formats

hello. I have a simple set of points ins a object (vertices added by a script):

if I fill it, I get a really weird pattern:

but I expected something like this (in which most vertices connect to the nearest points):

is there any way to fix it? if it can also be done via script command, even better.
thanks in advance

What you need to be doing is adding edges as well as vertices in the first script. Then Fill will work correctly.

I don’t know scripting, but there is probably a way to get a list of vertices hopefully in the order they were added. I assume the script added them in a clockwise or CCW fashion. With that list you can make edges between each two vertices.

yeah, maybe that would be the only way…
the script actually adds them in no particular order, its random. i think i’ll have to organize the vertices order, then.