User Tools

Site Tools


geda:guile_scripting

This is an old revision of the document!


Translations of this page are also available in the following languages: Русский.

Guile scripting

gEDA/gaf uses Guile Scheme to provide Scheme scripting capabilities, and all of the features of Guile are available to use. The Guile Reference Manual is available as an Info manual (info guile on most systems), or on the Guile website.

A collection of modules is provided for accessing and modifying gEDA objects and pages, called the gEDA Scheme API. The gEDA Scheme Reference Manual is also available as an Info manual (info geda-scheme).

Tutorials

Reference documents

Scripting examples

You can download each script example and load it in gschem:

  • just hit : and enter
    (load "filename.scm")
  • then hit Enter

Removing objects with specific properties

For instance, let's remove all objects which are circles or arcs with zero radius:

remove-objects.scm
(use-modules (geda page))
 
; Checks if the OBJECT is a circle or an arc with zero radius
(define (zero-radius-object? object)
  (or
    (and (circle? object) (= (circle-radius object) 0))
    (and (arc?    object) (= (arc-radius    object) 0))))
 
(apply page-remove! (active-page)
       (filter
         zero-radius-object?
         (page-contents (active-page))))

Let's suppose we have a component with a known attribute to remove, then we have to detach and remove all its attributes, too. The function below does exactly this.

remove-components-with-attribs.scm
(use-modules (geda page))
(use-modules (geda object))
(use-modules (geda attrib))
 
; Removes all components having the attrib NAME=VALUE from PAGE
(define (delete-components-by-attrib! page name value)
  (for-each
    (lambda (obj)
      (if (component? obj)
        (for-each
          (lambda (attr)
            (and
              (string=? (attrib-name attr) name)
              (string=? (attrib-value attr) value)
              (let ((attached-attribs (object-attribs obj)))
                (apply detach-attribs! obj attached-attribs)
                (apply page-remove! page obj attached-attribs))))
          (object-attribs obj))))
    (page-contents page)))

After loading the file, hit : and enter, for example,

(delete-components-by-attrib! (active-page) "refdes" "R1")
geda/guile_scripting.1441992877.txt.gz · Last modified: 2015/09/11 13:34 by vzh