Mail Archives: geda-user/2016/01/04/13:33:59
On Sun, 3 Jan 2016, karl AT aspodata DOT se wrote:
> how do I rean in an existing file so I can scan it for components ?
The Xorn analogy to the "gaf shell" command-line tool is running a Python
interpreter. In order to import the necessary Xorn modules, you can
either install gEDA/gaf, or you can explicitly add the subdirectory
"xorn/built-packages" of the gEDA build directory to your PYTHONPATH:
$ PYTHONPATH=/path/to/geda-gaf/xorn/built-packages/ python2.7
Python 2.7.9 (default, Mar 1 2015, 18:22:53)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xorn.geda.read
>>> sch = xorn.geda.read.read('logo_1.sch')
After loading a schematic file, you could, for example, print all objects:
>>> for ob in sch.toplevel_objects():
... print ob.data()
...
<xorn.storage.Component object at ...>
<xorn.storage.Net object at ...>
<xorn.storage.Net object at ...>
<xorn.storage.Net object at ...>
<xorn.storage.Text object at ...>
<xorn.storage.Component object at ...>
If you want to load non-embedded symbols, too, you first have to add each
symbol library directory. I'm planning to make this easier in the future,
but for now, you'll have to do something like this:
>>> import os, xorn.geda.clib
>>> for dirpath, dirnames, filenames in os.walk('/path/to/symbols'):
... for dirname in dirnames:
... xorn.geda.clib.add_source(
... xorn.geda.clib.DirectorySource(os.path.join(dirpath, dirname)),
... xorn.geda.clib.uniquify_source_name(dirname))
...
You can now load a schematic including the symbols and access the symbol's
contents:
>>> sch = xorn.geda.read.read('logo_1.sch', load_symbols = True)
>>> for ob in sch.toplevel_objects():
... data = ob.data()
... if isinstance(data, xorn.storage.Component):
... print '%s\t%s\t%s' % (data.symbol.basename,
... data.symbol.embedded,
... data.symbol.prim_objs)
...
7408-1.sym False <xorn.storage.Revision object at ...>
title-A.sym False <xorn.storage.Revision object at ...>
- Raw text -