Geert is correct (he always is)

about there being no access to legends within the API.
However I have successfully created a script that creates a Legend (or Legends) on a selected diagram. Honestly, its a horrible task. The legend info is held as a rather nasty ; delimited string in t_xref, and the colour for the element / connector is
not held as an RGB value, rather it appears to be some unique number that EA has obtained from the RGB. It looks like a simple Integer value for an RGB, but using the "standard" RGB to Integer method does not appear to yield the correct colour!
To get the correct legend info I had to create a legend manually, then examine t_xref, to get the info settings which I then put into my script which adds the entry into t_xref using a SQL INSERT statement.
The above is not a trivial task, but it can be done with a great deal of effort. Updating an existing entry in t_xref with a new info would involve working out the magic EA integer for the new RGB value, creating the legend info string and the using a SQL UPDATE to update t_xref.
Not for the faint hearted.
Best of luck
Phil