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 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: References: <20160102091556 DOT BBC6D809D79B AT turkos DOT aspodata DOT se> <20160103192006 DOT 1FBFE809D79B AT turkos DOT aspodata DOT se> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII 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 Precedence: bulk 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() ... 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 title-A.sym False