X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f X-Recipient: geda-user AT delorie DOT com Date: Fri, 10 Jul 2015 23:34:22 +0200 (CEST) From: Roland Lutz To: "Vladimir Zhbanov (vzhbanov AT gmail DOT com) [via geda-user AT delorie DOT com]" Subject: Re: [geda-user] why I parse sch: gnetlist, writing backends (Back annotation) In-Reply-To: Message-ID: References: <559E86A4 DOT 3040109 AT ecosensory DOT com> <201507091843 DOT t69IhGF6028321 AT envy DOT delorie DOT com> <6392CE1A-AFA0-4D62-979C-3F35786422BD AT noqsi DOT com> <201507092127 DOT t69LRHRC001744 AT envy DOT delorie DOT com> <559EFE69 DOT 1040601 AT zoot DOT drehmel DOT com> <201507092332 DOT t69NWUEN006109 AT envy DOT delorie DOT com> <20150710132650 DOT GA15876 AT localhost DOT localdomain> <20150710152308 DOT GA17023 AT localhost DOT localdomain> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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 Fri, 10 Jul 2015, gedau AT igor2 DOT repo DOT hu wrote: > So next time I have something similar to solve, I will first ask you for the > scheme code and only if that fails I do the dirty sch-parsing awk fewliner. You could use Xorn. Since this uses the actual gEDA parsing code, the result is exactly what gEDA would see when reading the file. Taking the "outputting coords of line segments" task as an example, this would be: import xorn.storage from xorn.geda.read import read sch = read('some-schematic.sch') for ob in sch.toplevel_objects(): data = ob.data() if isinstance(data, xorn.storage.Line): print 'X1: %d Y1: %d X2: %d Y2: %d' % ( data.x, data.y, data.x + data.width, data.y + data.height) You don't have to install Xorn in order import its modules; just add the directory "built-packages" in the build directory to PYTHONPATH. Roland