Although the question is not very clear, it seems that you need something like GraphViz [1]. This is basically a block diagram layout automation program that is completely isomorphic to your problem. There is a Python interface PyGraphViz [2], which may be useful to you.
If you want to create your own layout engine (comparable to GraphViz), make sure that you check the multidimensional scaling algorithm [3], which is used by the neato component of GraphViz.
[1] http://www.graphviz.org/
[2] http://networkx.lanl.gov/pygraphviz/
[3] http://en.wikipedia.org/wiki/Multidimensional_scaling
I can give more focused help if you provide more detailed information about the problem. An approximate drawing (sketch) of what you want to get will be good.
source share