But, as you will see, there is not a clean way to run a dia python script from command line (or i dont know how).
I made a little test script, it is linux oriented.
import dia
# this line, in interactive mode, generates
# WARNING **: Can't find list for recent-files when adding /tmp/mydiagram.dia
# but seems to work
dia.load("/tmp/mydiagram.dia")
# open a file for some output
tmpfile = open("/tmp/mytmpfile", "a")
tmpfile.write("hello world from dia\n")
# this line doesn't work and breaks the script
#tmpfile.write("found diagrams " + len(dia.diagrams()) + "\n")
# notice that diagram file passed in command line is not loaded
# when this code is executed
tmpfile.write("loaded diagram " + str(dia.diagrams()[0].filename) + "\n")
# this line doesn't work too and breaks the script
#tmpfile.write("num layers " + len(dia.diagrams()[0].data.layers) + "\n")
tmpfile.write("first layer name " + str(dia.diagrams()[0].data.layers[0].name))
tmpfile.close()
After that, there is a more dirty way to answer Martin's question.
You can run the script non interactively with this dirty command line
$ dia -e /tmp/filetodelete.dia -t dia emptydiagram.dia
"emptydiagram.dia" can be any valid dia file, it will not be used by example.py script (not visible in script when it is executed).
"/tmp/filetodelete.dia" can be removed when command ends, it is necessary for executing dia in export mode from command line without GUI.
"-t dia" again this parameter is just for not executing Dia wit GUI.
When dia is launched (with or without GUI) the script example.py is executed and with dia python class other diagram files can be loaded.
In my script i just check the name of first layer in diagram file containing data to be processed, dont know if accessing shapes in diagram works but it can be easily tested.
Notice that when script example.py is executed, any diagram file passed as parameter is not still loaded or accessible by dia python class (or at least in my test).
Here comes the need to load the diagram with your data directly in example.py script (this can be parametrized with some little python coding and environment variables or temporary files or what your hackitude can imagine)
I know the code is dirty and the solution is quite a trick.
A cleaner solution but not using Dia program or dia python plugin is a good xml parser and XPath. Martin, If you really need something like that, i made a php lib for accessing dia files: it is on launchpad, it is open source but 1/3 of the documentation is not in english (workin on it). Send me an email for more info, i dont think this is the place to advertise my work.
Hope to be useful and sorry for bad english
Carlo