delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2024/05/01/12:19:16

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1714580224; x=1715185024; darn=delorie.com;
h=mime-version:message-id:in-reply-to:reply-to:date:subject:to:from
:user-agent:references:from:to:cc:subject:date:message-id:reply-to;
bh=hy6B+Xn0ERxSJpsVcFrQugDDf1GUhyxFnV7jdJXnrUw=;
b=IvA/9nccjPbmbd/mUaLUlL8k4iOfH5z4Lo087rDNnFJdfcc1q1xNKhkAZvL0RFX4Xt
REd6M0v+Iril+GiKMyYFGm2yT1Pw7w1VZZVR6Ox6NZmrjlYNtzyuY9CcPQogWd0cMtLk
FSTf5XpFtPJup7S+CnJpZNeNQbg6e2qCP9FZxCyvy2mTqBd66tIHsdHKg6XVfOcvT5HU
KMNNDIPDmyDjwprJ3+bOrOnsLZFmBRq3ywU5joPM0AR8MJu9qMEKhfeIeyWvMiPj2jXE
myePvgwgL/CfEJZ7nRl5AWINzGdXth/jcqHgR9AYDrPgbOrnxT2BrLa9AEbQV9iIcuax
KQqA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1714580224; x=1715185024;
h=mime-version:message-id:in-reply-to:reply-to:date:subject:to:from
:user-agent:references:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to;
bh=hy6B+Xn0ERxSJpsVcFrQugDDf1GUhyxFnV7jdJXnrUw=;
b=bANqLtSqCWnAaOKJC8KIh53bEDuJXN7EhX1Hc7SHXGFuj+GJ+CQ4qMNXC6/y7h4b/y
xJj9CnX6TdAbRT5BtIFVR+0xI4ulVRcJkP///D224ECGPSCKor7h9j8tQDxkcJDSCakL
g6AP/Ertby12sm1oUaElkQgYqKNyDbuPdH4ce5zJZhf/vLP8fqG6nv9mps/GUNjOj/H6
p1Cjg9XjFY/x8SXT46FHpbax/T0cTSTRbeq4QGpMwNO6uo87nvNRHX8Gmj3mg9AVuDdK
KutfiQMvcngZKS29wlLO3FQvVP8v3wiL4Ehbka/wZnnwV4V25l2Mjse2c4ZAI8Zzu23R
d93A==
X-Gm-Message-State: AOJu0YwITTjSL6aFDefLljQjc6UETyJh4HNSz20JxIswR+VuPhx9JI3Y
eQ80ifURXtucNhGCrqXI6QZE8f9P7kvfYqt4P8BUrtkuiygGUPzZva0z2A==
X-Google-Smtp-Source: AGHT+IEPVg6rFCGYTX9lXyZJsmG7coy/8WD3Z27F/X7PyLHJ7Sv3WwXVoDj50sBKSIUeEOKU8FwC5g==
X-Received: by 2002:a2e:9d4b:0:b0:2de:6f52:5c8d with SMTP id y11-20020a2e9d4b000000b002de6f525c8dmr25778ljj.21.1714580224042;
Wed, 01 May 2024 09:17:04 -0700 (PDT)
References: <37de350c-1e5f-422f-b13a-c5a9a1e132ac AT linetec DOT nl>
<20240429130455 DOT F01EF81AB8C5 AT turkos DOT aspodata DOT se>
<a49f9288-9af4-4bd7-b8bb-f1f6c41fd01f AT linetec DOT nl>
<20240430103043 DOT 32de22ff AT queeg DOT menasians DOT com>
<20240430211916 DOT A6DBC81AB8C5 AT turkos DOT aspodata DOT se>
<bec8e19d-0ad0-454b-a3cf-f220e466c433 AT linetec DOT nl>
<25416a96-c328-4b7e-8fa8-091c993205bd AT linetec DOT nl>
User-agent: mu4e 1.10.0; emacs 28.2
From: "Vladimir Zhbanov (vzhbanov AT gmail DOT com) [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com>
To: geda-user AT delorie DOT com
Subject: Re: [geda-user] Gschem refdes autonumber over multiple pages?
Date: Wed, 01 May 2024 19:12:10 +0300
In-reply-to: <25416a96-c328-4b7e-8fa8-091c993205bd@linetec.nl>
Message-ID: <87sez18q32.fsf@gmail.com>
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

--=-=-=
Content-Type: text/plain


"Richard Rasker (rasker AT linetec DOT nl) [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com> writes:

> Correction:
>
> Op 01-05-2024 om 13:40 schreef Richard Rasker:
>
>  ... it should be pretty easy to write a script that concatenates and sorts all gschem files listed in a project file, and then tries matching a
>  counter to RefDes numbers for each component type, and simply spits out the first counter value for which no RefDes is found, at which
>  point it can exit.

Hi Richard,

I've written a simple Scheme script for lepton-schematic just now
(attached).  It processes components of all open pages and outputs the
result as is defined at the bottom of the script.  You can load it from
GUI.  It can be easily modified and adjusted for your needs.  Even
output the info to the log window or a message dialog, if you wish.

HTH,
  Vladimir

--=-=-=
Content-Type: text/plain
Content-Disposition: attachment; filename=refdes-counter.scm
Content-Description: refdes-counter.scm

;;; This script can be loaded and run in lepton-schematic.
;;; For gEDA/gschem, replace (lepton page) with (geda page), etc.
;;; Hopefully it'll work :-)
(use-modules (srfi srfi-1)
             (lepton page)
             (lepton object)
             (lepton attrib))

;;; Components on all active pages
(define components
  (filter component? (append-map page-contents (active-pages))))

;;; Get the value of the refdes= ATTRIB if the attrib name is
;;; really "refdes", otherwise return #f.
(define (refdes-value attrib)
  (and (string= (attrib-name attrib) "refdes")
       (attrib-value attrib)))

;;; Transform the list of object ATTRIBS into the list of refdes
;;; attrib values.  Other attributes are filtered out.
(define (filter-refdes attribs)
  (filter-map refdes-value attribs))

;;; Get the refdes value of component object C, if any.  It is
;;; returned within a list, e.g. '("R1").
(define (component-refdes component)
  (filter-refdes (object-attribs component)))

;;; Gather refdeses of all components and sort them.
(define all-refdeses
  (sort (append-map component-refdes components)
        string<))

;;; Get REFDES with given PREFIX and transform it to a number, if
;;; possible.
(define (refdes-with-prefix->number refdes prefix)
  (and (string-prefix? prefix refdes)
       (string->number (string-drop refdes (string-length prefix)))))

;;; Filter all found refdeses by prefix and return their numbers.
(define (filter-all-components-by-prefix prefix)
  (filter-map (lambda (refdes) (refdes-with-prefix->number refdes prefix))
              all-refdeses))

;;; Look up for the first missing counter value in a list of numbers.
(define (lookup-counter ls)
  (let loop ((counter 1))
    (if (memq counter ls)
        (loop (1+ counter))
        counter)))

;;; Look up for the first missing counter value given the refdes prefix.
(define (lookup-counter-by-prefix prefix)
  (lookup-counter (filter-all-components-by-prefix prefix)))

;;; Now, display what you want to.
(display (lookup-counter-by-prefix "R")) (newline)
(display (lookup-counter-by-prefix "RA")) (newline)
(display (lookup-counter-by-prefix "L")) (newline)
(display (lookup-counter-by-prefix "Q")) (newline)

--=-=-=--

- Raw text -


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