delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2016/01/04/13:33:59

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
Date: Mon, 4 Jan 2016 19:33:25 +0100 (CET)
From: Roland Lutz <rlutz AT hedmen DOT org>
To: geda-user AT delorie DOT com
Subject: Re: [geda-user] Howto make a script in gaf (Was should we broaden
scope of libgeda)
In-Reply-To: <20160103192006.1FBFE809D79B@turkos.aspodata.se>
Message-ID: <alpine.DEB.2.11.1601032244500.1697@newt>
References: <20160102091556 DOT BBC6D809D79B AT turkos DOT aspodata DOT se> <CAMvDHVAoAnt3g6JBvgbnrR53LG6KpzWKBTmQgo1j+7ERvbESpg AT mail DOT gmail DOT com> <20160103192006 DOT 1FBFE809D79B AT turkos DOT aspodata DOT se>
User-Agent: Alpine 2.11 (DEB 23 2013-08-11)
MIME-Version: 1.0
Reply-To: geda-user AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: geda-user AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019