1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./style.css" />
6 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./design.css" />
7 <link rel=
"stylesheet" media=
"print" type=
"text/css" href=
"./print.css" />
9 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
14 <em>Translations of this page are also available in the following languages:
</em> <a href=
"geda-guile_scripting.ru.html" class=
"wikilink1" title=
"geda-guile_scripting.ru.html">Русский
</a>.
17 <h2 id=
"guilescripting">Guile scripting
</h2>
21 gEDA/gaf uses Guile Scheme to provide Scheme scripting capabilities, and all of the features of Guile are available to use. The
<em>Guile Reference Manual
</em> is available as an Info manual (
<code>info guile
</code> on most systems), or on the Guile website.
25 A collection of modules is provided for accessing and modifying gEDA objects and pages, called the gEDA Scheme API. The
<em>gEDA Scheme Reference Manual
</em> is also available as an Info manual (
<code>info geda-scheme
</code>).
30 <h3 id=
"tutorials">Tutorials
</h3>
33 <li class=
"level1"><div class=
"li"> <a href=
"geda-gnetlistschemetutorial.html" class=
"wikilink2" title=
"geda-gnetlistschemetutorial.html">Scripting a gnetlist backend in scheme
</a> (John Doty)
</div>
38 See also the
<a href=
"geda-gschem_ug-extensions.html" class=
"wikilink1" title=
"geda-gschem_ug-extensions.html">Extending gschem
</a> section of the
<em><a href=
"geda-gschem_ug.html" class=
"wikilink1" title=
"geda-gschem_ug.html">gEDA gschem User Guide
</a></em>, and
<a href=
"geda-gnetlist_ug.html#scheme_backend_api" class=
"wikilink1" title=
"geda-gnetlist_ug.html">Scheme Backend API
</a> section of the
<em><a href=
"geda-gnetlist_ug.html" class=
"wikilink1" title=
"geda-gnetlist_ug.html">gEDA gnetlist User Guide
</a></em>.
43 <h3 id=
"referencedocuments">Reference documents
</h3>
46 <li class=
"level1"><div class=
"li"> <a href=
"geda-gnetlistschemeprimitives.html" class=
"wikilink2" title=
"geda-gnetlistschemeprimitives.html">gnetlist Scheme primitives
</a></div>
48 <li class=
"level1"><div class=
"li"> <a href=
"geda-gschemrepl.html" class=
"wikilink2" title=
"geda-gschemrepl.html">Using REPL in gschem
</a></div>
54 <h3 id=
"scriptingexamples">Scripting examples
</h3>
58 You can download each script example and load it in
<strong>gschem
</strong>:
61 <li class=
"level1"><div class=
"li"> just hit
<kbd>:
</kbd> and enter
<pre class=
"code lisp"><span class=
"br0">(</span>load
<span class=
"st0">"filename.scm
"</span><span class=
"br0">)</span></pre>
64 <li class=
"level1"><div class=
"li"> then hit
<kbd>Enter
</kbd></div>
69 You can install them as well if you don
't want to load them every time:
72 <li class=
"level1"><div class=
"li"> copy the script you want into your
<em><code>~/.gEDA
</code></em> directory
</div>
74 <li class=
"level1"><div class=
"li"> put the line
<pre class=
"code lisp"><span class=
"br0">(</span>load
<span class=
"st0">"filename.scm
"</span><span class=
"br0">)</span></pre>
77 into your
<em><code>~/.gEDA/gschemrc
</code></em> (replace
<em>filename.scm
</em> with the real name of the script)
85 <h4 id=
"removingobjectswithspecificproperties">Removing objects with specific properties
</h4>
89 For instance, let
's remove all objects which are circles or arcs
93 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=2" title=
"Download Snippet" class=
"mediafile mf_scm">remove-objects.scm
</a></dt>
94 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>geda page
<span class=
"br0">)</span><span class=
"br0">)</span>
96 <span class=
"co1">; Checks if the OBJECT is a circle or an arc with zero radius
</span>
97 <span class=
"br0">(</span>define
<span class=
"br0">(</span>zero-radius-object? object
<span class=
"br0">)</span>
98 <span class=
"br0">(</span><span class=
"kw1">or
</span>
99 <span class=
"br0">(</span><span class=
"kw1">and
</span> <span class=
"br0">(</span>circle? object
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"sy0">=
</span> <span class=
"br0">(</span>circle-radius object
<span class=
"br0">)</span> <span class=
"nu0">0</span><span class=
"br0">)</span><span class=
"br0">)</span>
100 <span class=
"br0">(</span><span class=
"kw1">and
</span> <span class=
"br0">(</span>arc? object
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"sy0">=
</span> <span class=
"br0">(</span>arc-radius object
<span class=
"br0">)</span> <span class=
"nu0">0</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
102 <span class=
"br0">(</span><span class=
"kw1">apply
</span> page-remove
<span class=
"sy0">!
</span> <span class=
"br0">(</span>active-page
<span class=
"br0">)</span>
103 <span class=
"br0">(</span>filter
105 <span class=
"br0">(</span>page-contents
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
109 Let
's suppose we have a component with a known attribute to
110 remove, then we have to detach and remove all its attributes, too.
111 The function below does exactly this.
114 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=3" title=
"Download Snippet" class=
"mediafile mf_scm">remove-components-with-attribs.scm
</a></dt>
115 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>geda page
<span class=
"br0">)</span><span class=
"br0">)</span>
116 <span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>geda object
<span class=
"br0">)</span><span class=
"br0">)</span>
117 <span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>geda attrib
<span class=
"br0">)</span><span class=
"br0">)</span>
119 <span class=
"co1">; Removes all components having the attrib NAME=VALUE from PAGE
</span>
120 <span class=
"br0">(</span>define
<span class=
"br0">(</span>delete-components-by-attrib
<span class=
"sy0">!
</span> page
<span class=
"kw1">name
</span> <span class=
"kw1">value
</span><span class=
"br0">)</span>
121 <span class=
"br0">(</span>for-each
122 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>obj
<span class=
"br0">)</span>
123 <span class=
"br0">(</span><span class=
"kw1">if
</span> <span class=
"br0">(</span>component? obj
<span class=
"br0">)</span>
124 <span class=
"br0">(</span>for-each
125 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>attr
<span class=
"br0">)</span>
126 <span class=
"br0">(</span><span class=
"kw1">and
</span>
127 <span class=
"br0">(</span>string
<span class=
"sy0">=
</span>?
<span class=
"br0">(</span>attrib-name attr
<span class=
"br0">)</span> <span class=
"kw1">name
</span><span class=
"br0">)</span>
128 <span class=
"br0">(</span>string
<span class=
"sy0">=
</span>?
<span class=
"br0">(</span>attrib-value attr
<span class=
"br0">)</span> <span class=
"kw1">value
</span><span class=
"br0">)</span>
129 <span class=
"br0">(</span><span class=
"kw1">let
</span> <span class=
"br0">(</span><span class=
"br0">(</span>attached-attribs
<span class=
"br0">(</span>object-attribs obj
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
130 <span class=
"br0">(</span><span class=
"kw1">apply
</span> detach-attribs
<span class=
"sy0">!
</span> obj attached-attribs
<span class=
"br0">)</span>
131 <span class=
"br0">(</span><span class=
"kw1">apply
</span> page-remove
<span class=
"sy0">!
</span> page obj attached-attribs
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
132 <span class=
"br0">(</span>object-attribs obj
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
133 <span class=
"br0">(</span>page-contents page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
137 After loading the file, hit
<kbd>:
</kbd> and enter, for example,
139 <pre class=
"code lisp"><span class=
"br0">(</span>delete-components-by-attrib
<span class=
"sy0">!
</span> <span class=
"br0">(</span>active-page
<span class=
"br0">)</span> <span class=
"st0">"refdes
"</span> <span class=
"st0">"R1
"</span><span class=
"br0">)</span></pre>
143 <h4 id=
"proceduresforinput-output">Procedures for input-output
</h4>
147 The following script defines two procedures that can be used in
148 <strong>gaf shell
</strong> batch scripts:
151 <li class=
"level1"><div class=
"li"> <code>schematic-file-
>page
</code></div>
153 <li class=
"level1"><div class=
"li"> <code>page-
>schematic-file
</code></div>
157 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=5" title=
"Download Snippet" class=
"mediafile mf_scm">geda-io.scm
</a></dt>
158 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>ice-
<span class=
"nu0">9</span> lineio
<span class=
"br0">)</span><span class=
"br0">)</span>
159 <span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>geda page
<span class=
"br0">)</span><span class=
"br0">)</span>
161 <span class=
"co1">; Input/output procedures
</span>
162 <span class=
"co1">; reads FILE and outputs string
</span>
163 <span class=
"br0">(</span>define
<span class=
"br0">(</span>file-
<span class=
"sy0">></span>string file
<span class=
"br0">)</span>
164 <span class=
"br0">(</span><span class=
"kw1">let
</span>*
<span class=
"br0">(</span><span class=
"br0">(</span>port
<span class=
"br0">(</span>make-line-buffering-input-port
<span class=
"br0">(</span>open-file file
<span class=
"st0">"r
"</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
165 <span class=
"br0">(</span><span class=
"kw1">do
</span> <span class=
"br0">(</span><span class=
"br0">(</span>line
<span class=
"st0">""</span> <span class=
"br0">(</span>read-string port
<span class=
"br0">)</span><span class=
"br0">)</span>
166 <span class=
"br0">(</span>s
<span class=
"st0">""</span> <span class=
"br0">(</span>string-append s line
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
167 <span class=
"br0">(</span><span class=
"br0">(</span>eof-object? line
<span class=
"br0">)</span> <span class=
"co1">; test
</span>
168 <span class=
"br0">(</span>close-port port
<span class=
"br0">)</span> <span class=
"co1">; expression(s) to evaluate in the end
</span>
169 s
<span class=
"br0">)</span> <span class=
"co1">; return value
</span>
170 <span class=
"co1">; empty body
</span>
171 <span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
173 <span class=
"co1">; reads schematic FILE and outputs PAGE object
</span>
174 <span class=
"br0">(</span>define
<span class=
"br0">(</span>schematic-file-
<span class=
"sy0">></span>page file
<span class=
"br0">)</span>
175 <span class=
"br0">(</span>string-
<span class=
"sy0">></span>page file
<span class=
"br0">(</span>file-
<span class=
"sy0">></span>string file
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
177 <span class=
"co1">; saves schematic PAGE to FILE
</span>
178 <span class=
"br0">(</span>define
<span class=
"br0">(</span>page-
<span class=
"sy0">></span>schematic-file page file
<span class=
"br0">)</span>
179 <span class=
"br0">(</span>with-output-to-file file
180 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span><span class=
"br0">)</span> <span class=
"br0">(</span>display
<span class=
"br0">(</span>page-
<span class=
"sy0">></span>string page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
185 <h4 id=
"copymoveandrotateobjects">Copy, move, and rotate objects
</h4>
188 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=6" title=
"Download Snippet" class=
"mediafile mf_scm">move-and-rotate.scm
</a></dt>
189 <dd><pre class=
"code file lisp"><span class=
"co1">; Scripting example by vzh per request of Kai-Martin Knaak :-)
</span>
190 <span class=
"co1">; Use at your own risk.
</span>
192 <span class=
"co1">; The main procedure here is
</span>
193 <span class=
"co1">; multiple-copy-move-and-rotate-selection which can be abbreviated
</span>
194 <span class=
"co1">; as mcmars.
</span>
195 <span class=
"co1">; Usage:
</span>
196 <span class=
"co1">; launch gschem so it can use this script, e.g.
</span>
197 <span class=
"co1">; gschem -s move-and-rotate.scm
</span>
198 <span class=
"co1">; select objects in gschem, then hit ':' (semicolon) and type
</span>
199 <span class=
"co1">; (mcmars '(
1000 .
500)
90 10)
</span>
200 <span class=
"co1">; hit
<Enter
></span>
201 <span class=
"co1">; Enjoy!
</span>
204 <span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
206 <span class=
"co1">; align coords by ALIGN
</span>
207 <span class=
"br0">(</span>define
<span class=
"br0">(</span>ceiling-coords vector align
<span class=
"br0">)</span>
208 <span class=
"br0">(</span><span class=
"kw1">cons
</span>
209 <span class=
"br0">(</span>*
<span class=
"br0">(</span>ceiling-quotient
<span class=
"br0">(</span><span class=
"kw1">car
</span> vector
<span class=
"br0">)</span> align
<span class=
"br0">)</span> align
<span class=
"br0">)</span>
210 <span class=
"br0">(</span>*
<span class=
"br0">(</span>ceiling-quotient
<span class=
"br0">(</span><span class=
"kw1">cdr
</span> vector
<span class=
"br0">)</span> align
<span class=
"br0">)</span> align
<span class=
"br0">)</span>
211 <span class=
"br0">)</span><span class=
"br0">)</span>
213 <span class=
"co1">; Get minimum X and minimum Y of two pairs of coords
</span>
214 <span class=
"br0">(</span>define
<span class=
"br0">(</span>min-coords coord1 coord2
<span class=
"br0">)</span>
215 <span class=
"br0">(</span><span class=
"kw1">let
</span> <span class=
"br0">(</span><span class=
"br0">(</span>x
<span class=
"br0">(</span><span class=
"kw1">min
</span> <span class=
"br0">(</span><span class=
"kw1">car
</span> coord1
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">car
</span> coord2
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
216 <span class=
"br0">(</span>y
<span class=
"br0">(</span><span class=
"kw1">min
</span> <span class=
"br0">(</span><span class=
"kw1">cdr
</span> coord1
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cdr
</span> coord2
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
217 <span class=
"co1">; return value
</span>
218 <span class=
"br0">(</span><span class=
"kw1">cons
</span> x y
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
220 <span class=
"co1">; Copy, move and rotate current selection. The selected objects
</span>
221 <span class=
"co1">; are first copied, then translated by VECTOR and finally rotated
</span>
222 <span class=
"co1">; by ANGLE about center which is calculated as rounded by
100</span>
223 <span class=
"co1">; lower left coordinate of all objects in selection.
</span>
224 <span class=
"co1">; If no objects are selected, opens gschem message dialog with
</span>
225 <span class=
"co1">; warning.
</span>
226 <span class=
"co1">; Returns the copied objects.
</span>
227 <span class=
"br0">(</span>define
<span class=
"br0">(</span>copy-move-and-rotate-selection vector angle
<span class=
"br0">)</span>
228 <span class=
"br0">(</span><span class=
"kw1">let
</span> <span class=
"br0">(</span><span class=
"br0">(</span>objects
<span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
229 <span class=
"br0">(</span><span class=
"kw1">if
</span> <span class=
"br0">(</span><span class=
"kw1">null
</span>? objects
<span class=
"br0">)</span>
230 <span class=
"br0">(</span>gschem-msg
<span class=
"st0">"Select something first!
"</span><span class=
"br0">)</span>
231 <span class=
"co1">; else
</span>
232 <span class=
"br0">(</span><span class=
"kw1">let
</span>*
<span class=
"br0">(</span><span class=
"br0">(</span>copied-objects
<span class=
"br0">(</span>map copy-object objects
<span class=
"br0">)</span><span class=
"br0">)</span>
233 <span class=
"br0">(</span>translated-objects
<span class=
"br0">(</span><span class=
"kw1">apply
</span> translate-objects
<span class=
"sy0">!
</span> vector copied-objects
<span class=
"br0">)</span><span class=
"br0">)</span>
234 <span class=
"br0">(</span>bounds
<span class=
"br0">(</span><span class=
"kw1">apply
</span> object-bounds translated-objects
<span class=
"br0">)</span><span class=
"br0">)</span>
235 <span class=
"br0">(</span>rotation-center
<span class=
"br0">(</span>ceiling-coords
<span class=
"br0">(</span>min-coords
<span class=
"br0">(</span><span class=
"kw1">car
</span> bounds
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cdr
</span> bounds
<span class=
"br0">)</span><span class=
"br0">)</span> <span class=
"nu0">100</span><span class=
"br0">)</span><span class=
"br0">)</span>
236 <span class=
"br0">(</span>rotated-objects
<span class=
"br0">(</span><span class=
"kw1">apply
</span> rotate-objects
<span class=
"sy0">!
</span> rotation-center angle translated-objects
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
237 <span class=
"br0">(</span><span class=
"kw1">apply
</span> page-append
<span class=
"sy0">!
</span> <span class=
"br0">(</span>active-page
<span class=
"br0">)</span> rotated-objects
<span class=
"br0">)</span>
238 rotated-objects
<span class=
"br0">)</span>
239 <span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
241 <span class=
"co1">; Multiply VECTOR which must be a pair by NUMBER
</span>
242 <span class=
"br0">(</span>define
<span class=
"br0">(</span>multiply-vector-by vector number
<span class=
"br0">)</span>
243 <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"br0">(</span>* number
<span class=
"br0">(</span><span class=
"kw1">car
</span> vector
<span class=
"br0">)</span><span class=
"br0">)</span> <span class=
"br0">(</span>* number
<span class=
"br0">(</span><span class=
"kw1">cdr
</span> vector
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
245 <span class=
"co1">; Copy, move and rotate current selection NUMBER times. Applies
</span>
246 <span class=
"co1">; the copy-move-and-rotate-selection procedure multiple times
</span>
247 <span class=
"co1">; increasing every time vector and angle by given values of VECTOR
</span>
248 <span class=
"co1">; and ANGLE.
</span>
249 <span class=
"co1">; If no objects are selected, opens gschem message dialog with
</span>
250 <span class=
"co1">; warning.
</span>
251 <span class=
"co1">; Return value is unspecified.
</span>
252 <span class=
"br0">(</span>define
<span class=
"br0">(</span>multiple-copy-move-and-rotate-selection vector angle num
<span class=
"br0">)</span>
253 <span class=
"br0">(</span><span class=
"kw1">if
</span> <span class=
"br0">(</span><span class=
"kw1">null
</span>?
<span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
254 <span class=
"br0">(</span>gschem-msg
<span class=
"st0">"Select something first!
"</span><span class=
"br0">)</span>
255 <span class=
"co1">; else
</span>
256 <span class=
"br0">(</span><span class=
"kw1">do
</span> <span class=
"br0">(</span><span class=
"br0">(</span>i num
<span class=
"br0">(</span><span class=
"nu0">1</span>- i
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
257 <span class=
"br0">(</span><span class=
"br0">(</span><span class=
"sy0">=
</span> i
<span class=
"nu0">0</span><span class=
"br0">)</span><span class=
"br0">)</span>
258 <span class=
"br0">(</span>copy-move-and-rotate-selection
259 <span class=
"br0">(</span>multiply-vector-by vector i
<span class=
"br0">)</span> <span class=
"br0">(</span>* angle i
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
260 <span class=
"br0">)</span><span class=
"br0">)</span>
262 <span class=
"co1">; Abbreviated name for the multiple-copy-move-and-rotate-selection
</span>
263 <span class=
"co1">; procedure
</span>
264 <span class=
"br0">(</span>define mcmars multiple-copy-move-and-rotate-selection
<span class=
"br0">)</span></pre>
269 <h4 id=
"groupattributeediting">Group attribute editing
</h4>
273 Let
's suppose you have selected several resistors
' refdeses and
274 want to rename them at once, e.g., if they were copy from another
278 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=7" title=
"Download Snippet" class=
"mediafile mf_">set-selected-attribs-value
</a></dt>
279 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
281 <span class=
"br0">(</span>define
<span class=
"br0">(</span>set-selected-attribs-value
<span class=
"sy0">!
</span> <span class=
"kw1">value
</span><span class=
"br0">)</span>
282 <span class=
"br0">(</span>for-each
283 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>attrib
<span class=
"br0">)</span>
284 <span class=
"br0">(</span>set-attrib-value
<span class=
"sy0">!
</span> attrib
<span class=
"kw1">value
</span><span class=
"br0">)</span><span class=
"br0">)</span>
285 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
289 Usage of the procedure in
<strong>gschem
</strong>:
291 <pre class=
"code lisp"><span class=
"br0">(</span>set-selected-attribs-value
<span class=
"sy0">!
</span> <span class=
"st0">"R100.?
"</span><span class=
"br0">)</span></pre>
294 Now, after renumbering them using
<kbd>T
</kbd> <kbd>U
</kbd>, you
295 copy them all and want to rename those copied resistors appending a suffix:
298 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=9" title=
"Download Snippet" class=
"mediafile mf_scm">append-selected-attribs-suffix.scm
</a></dt>
299 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
301 <span class=
"br0">(</span>define
<span class=
"br0">(</span>append-selected-attribs-suffix
<span class=
"sy0">!
</span> suffix
<span class=
"br0">)</span>
302 <span class=
"br0">(</span>for-each
303 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>attrib
<span class=
"br0">)</span>
304 <span class=
"br0">(</span>set-attrib-value
<span class=
"sy0">!
</span>
306 <span class=
"br0">(</span>string-append
<span class=
"br0">(</span>attrib-value attrib
<span class=
"br0">)</span> suffix
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
307 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
311 Usage of the procedure in
<strong>gschem
</strong>:
313 <pre class=
"code lisp"><span class=
"br0">(</span>append-selected-attribs-suffix
<span class=
"sy0">!
</span> <span class=
"st0">"-top
"</span><span class=
"br0">)</span></pre>
316 Now, let
's rename some other attributes by adding a prefix:
319 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=11" title=
"Download Snippet" class=
"mediafile mf_scm">append-selected-attribs-prefix.scm
</a></dt>
320 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
322 <span class=
"br0">(</span>define
<span class=
"br0">(</span>append-selected-attribs-prefix
<span class=
"sy0">!
</span> prefix
<span class=
"br0">)</span>
323 <span class=
"br0">(</span>for-each
324 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>object
<span class=
"br0">)</span>
325 <span class=
"br0">(</span><span class=
"kw1">and
</span> <span class=
"br0">(</span>attribute? object
<span class=
"br0">)</span>
326 <span class=
"br0">(</span>set-attrib-value
<span class=
"sy0">!
</span>
328 <span class=
"br0">(</span>string-append prefix
<span class=
"br0">(</span>attrib-value object
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
329 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
333 Usage of the procedure in
<strong>gschem
</strong>:
335 <pre class=
"code lisp"><span class=
"br0">(</span>append-selected-attribs-prefix
<span class=
"sy0">!
</span> <span class=
"st0">"A1.
"</span><span class=
"br0">)</span></pre>
338 Let
's replace first letters of selected attribs with prefix:
341 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=13" title=
"Download Snippet" class=
"mediafile mf_scm">append-selected-attribs-prefix.scm
</a></dt>
342 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
344 <span class=
"br0">(</span>define
<span class=
"br0">(</span>replace-selected-attribs-prefix
<span class=
"sy0">!
</span> prefix
<span class=
"br0">)</span>
345 <span class=
"br0">(</span>for-each
346 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>object
<span class=
"br0">)</span>
347 <span class=
"br0">(</span><span class=
"kw1">and
</span> <span class=
"br0">(</span>attribute? object
<span class=
"br0">)</span>
348 <span class=
"br0">(</span>set-attrib-value
<span class=
"sy0">!
</span>
350 <span class=
"br0">(</span>string-append
352 <span class=
"br0">(</span>string-copy
<span class=
"br0">(</span>attrib-value object
<span class=
"br0">)</span> <span class=
"nu0">1</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
353 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
357 Usage of the procedure in
<strong>gschem
</strong>:
359 <pre class=
"code lisp"><span class=
"br0">(</span>replace-selected-attribs-prefix
<span class=
"sy0">!
</span> <span class=
"st0">"C
"</span><span class=
"br0">)</span></pre>
362 Let
's rename selected
<code>netname=
</code> attributes increasing them by a
366 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=15" title=
"Download Snippet" class=
"mediafile mf_scm">add-selected-attribs-number.scm
</a></dt>
367 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
369 <span class=
"br0">(</span>define
<span class=
"br0">(</span>add-selected-attribs-number
<span class=
"sy0">!
</span> number
<span class=
"br0">)</span>
370 <span class=
"br0">(</span>for-each
371 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>object
<span class=
"br0">)</span>
372 <span class=
"br0">(</span><span class=
"kw1">and
</span> <span class=
"br0">(</span>attribute? object
<span class=
"br0">)</span>
373 <span class=
"br0">(</span>set-attrib-value
<span class=
"sy0">!
</span>
375 <span class=
"br0">(</span>number-
<span class=
"sy0">></span>string
376 <span class=
"br0">(</span>+
<span class=
"br0">(</span>string-
<span class=
"sy0">></span>number
<span class=
"br0">(</span>attrib-value object
<span class=
"br0">)</span><span class=
"br0">)</span> number
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
377 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
381 Usage of the procedure in
<strong>gschem
</strong>:
383 <pre class=
"code lisp"><span class=
"br0">(</span>add-selected-attribs-number
<span class=
"sy0">!
</span> <span class=
"nu0">100</span><span class=
"br0">)</span></pre>
386 We could set any function instead of
"+
" on the net number in this procedure.
390 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=17" title=
"Download Snippet" class=
"mediafile mf_scm">use-another-func.scm
</a></dt>
391 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
393 <span class=
"br0">(</span>define
<span class=
"br0">(</span>use-another-func
<span class=
"sy0">!
</span> func
<span class=
"br0">)</span>
394 <span class=
"br0">(</span>for-each
395 <span class=
"br0">(</span><span class=
"kw1">lambda
</span> <span class=
"br0">(</span>object
<span class=
"br0">)</span>
396 <span class=
"br0">(</span><span class=
"kw1">and
</span> <span class=
"br0">(</span>attribute? object
<span class=
"br0">)</span>
397 <span class=
"br0">(</span>set-attrib-value
<span class=
"sy0">!
</span>
399 <span class=
"br0">(</span>number-
<span class=
"sy0">></span>string
400 <span class=
"br0">(</span>func
<span class=
"br0">(</span>string-
<span class=
"sy0">></span>number
<span class=
"br0">(</span>attrib-value object
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
401 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span></pre>
405 Usage of the procedure in
<strong>gschem
</strong>:
407 <pre class=
"code lisp"><span class=
"br0">(</span>use-another-func
<span class=
"sy0">!
</span> -
<span class=
"br0">)</span>
408 <span class=
"br0">(</span>define
<span class=
"br0">(</span>multiply-by-
<span class=
"nu0">2</span> x
<span class=
"br0">)</span>
409 <span class=
"br0">(</span>*
<span class=
"nu0">2</span> x
<span class=
"br0">)</span><span class=
"br0">)</span>
410 <span class=
"br0">(</span>use-another-func
<span class=
"sy0">!
</span> multiply-by-
<span class=
"nu0">2</span><span class=
"br0">)</span></pre>
414 <h4 id=
"movingobjectsusingarrows">Moving objects using arrows
</h4>
418 Let
's define actions to move selected objects using
419 <kbd>Shift
</kbd> + arrow keys.
422 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=19" title=
"Download Snippet" class=
"mediafile mf_scm">arrow-move.scm
</a></dt>
423 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
425 <span class=
"co1">; Default offset to move
</span>
426 <span class=
"br0">(</span>define offset
<span class=
"nu0">100</span><span class=
"br0">)</span>
428 <span class=
"co1">; Get moving vector
</span>
429 <span class=
"br0">(</span>define
<span class=
"br0">(</span>move-selection direction
<span class=
"br0">)</span>
430 <span class=
"br0">(</span><span class=
"kw1">apply
</span> translate-objects
<span class=
"sy0">!
</span>
431 <span class=
"br0">(</span><span class=
"kw1">case
</span> direction
432 <span class=
"br0">(</span><span class=
"br0">(</span>left
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"br0">(</span>- offset
<span class=
"br0">)</span> <span class=
"nu0">0</span><span class=
"br0">)</span><span class=
"br0">)</span>
433 <span class=
"br0">(</span><span class=
"br0">(</span>right
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"br0">(</span>+ offset
<span class=
"br0">)</span> <span class=
"nu0">0</span><span class=
"br0">)</span><span class=
"br0">)</span>
434 <span class=
"br0">(</span><span class=
"br0">(</span>down
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"nu0">0</span> <span class=
"br0">(</span>- offset
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
435 <span class=
"br0">(</span><span class=
"br0">(</span>up
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"nu0">0</span> <span class=
"br0">(</span>+ offset
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
436 <span class=
"br0">(</span>else #f
<span class=
"br0">)</span><span class=
"br0">)</span>
437 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
439 <span class=
"co1">; Define actions
</span>
440 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-left
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'left
<span class=
"br0">)</span><span class=
"br0">)</span>
441 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-right
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'right
<span class=
"br0">)</span><span class=
"br0">)</span>
442 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-down
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'down
<span class=
"br0">)</span><span class=
"br0">)</span>
443 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-up
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'up
<span class=
"br0">)</span><span class=
"br0">)</span>
445 <span class=
"co1">; Define shortcuts
</span>
446 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"<Shift
>Left
"</span> '
<span class=
"sy0">&</span>move-selection-left
<span class=
"br0">)</span>
447 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"<Shift
>Right
"</span> '
<span class=
"sy0">&</span>move-selection-right
<span class=
"br0">)</span>
448 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"<Shift
>Up
"</span> '
<span class=
"sy0">&</span>move-selection-up
<span class=
"br0">)</span>
449 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"<Shift
>Down
"</span> '
<span class=
"sy0">&</span>move-selection-down
<span class=
"br0">)</span></pre>
453 The following script redefines current shortcuts so that if
454 nothing is selected the canvas is moved with arrow keys (without
455 <kbd>Shift
</kbd> in this case), otherwise selected objects are
459 <dt><a href=
"/./doku.php?do=export_code&id=:geda:guile_scripting.txt&codeblock=20" title=
"Download Snippet" class=
"mediafile mf_scm">arrow-move2.scm
</a></dt>
460 <dd><pre class=
"code file lisp"><span class=
"br0">(</span>use-modules
<span class=
"br0">(</span>gschem selection
<span class=
"br0">)</span><span class=
"br0">)</span>
462 <span class=
"co1">; Default offset to move
</span>
463 <span class=
"br0">(</span>define offset
<span class=
"nu0">100</span><span class=
"br0">)</span>
465 <span class=
"co1">; Get moving vector
</span>
466 <span class=
"br0">(</span>define
<span class=
"br0">(</span>move-selection direction
<span class=
"br0">)</span>
467 <span class=
"br0">(</span><span class=
"kw1">let
</span> <span class=
"br0">(</span><span class=
"br0">(</span>selection
<span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
468 <span class=
"br0">(</span><span class=
"kw1">if
</span> <span class=
"br0">(</span><span class=
"kw1">null
</span>? selection
<span class=
"br0">)</span>
469 <span class=
"co1">; default behaviour
</span>
470 <span class=
"br0">(</span><span class=
"kw1">case
</span> direction
471 <span class=
"br0">(</span><span class=
"br0">(</span>left
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"sy0">&</span>view-pan-left
<span class=
"br0">)</span><span class=
"br0">)</span>
472 <span class=
"br0">(</span><span class=
"br0">(</span>right
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"sy0">&</span>view-pan-right
<span class=
"br0">)</span><span class=
"br0">)</span>
473 <span class=
"br0">(</span><span class=
"br0">(</span>down
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"sy0">&</span>view-pan-down
<span class=
"br0">)</span><span class=
"br0">)</span>
474 <span class=
"br0">(</span><span class=
"br0">(</span>up
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"sy0">&</span>view-pan-up
<span class=
"br0">)</span><span class=
"br0">)</span>
475 <span class=
"br0">(</span>else #f
<span class=
"br0">)</span><span class=
"br0">)</span>
476 <span class=
"co1">; modified behaviour
</span>
477 <span class=
"br0">(</span><span class=
"kw1">apply
</span> translate-objects
<span class=
"sy0">!
</span>
478 <span class=
"br0">(</span><span class=
"kw1">case
</span> direction
479 <span class=
"br0">(</span><span class=
"br0">(</span>left
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"br0">(</span>- offset
<span class=
"br0">)</span> <span class=
"nu0">0</span><span class=
"br0">)</span><span class=
"br0">)</span>
480 <span class=
"br0">(</span><span class=
"br0">(</span>right
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"br0">(</span>+ offset
<span class=
"br0">)</span> <span class=
"nu0">0</span><span class=
"br0">)</span><span class=
"br0">)</span>
481 <span class=
"br0">(</span><span class=
"br0">(</span>down
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"nu0">0</span> <span class=
"br0">(</span>- offset
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
482 <span class=
"br0">(</span><span class=
"br0">(</span>up
<span class=
"br0">)</span> <span class=
"br0">(</span><span class=
"kw1">cons
</span> <span class=
"nu0">0</span> <span class=
"br0">(</span>+ offset
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
483 <span class=
"br0">(</span>else #f
<span class=
"br0">)</span><span class=
"br0">)</span>
484 <span class=
"br0">(</span>page-selection
<span class=
"br0">(</span>active-page
<span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span><span class=
"br0">)</span>
485 <span class=
"br0">)</span><span class=
"br0">)</span>
487 <span class=
"co1">; Define actions
</span>
488 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-left
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'left
<span class=
"br0">)</span><span class=
"br0">)</span>
489 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-right
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'right
<span class=
"br0">)</span><span class=
"br0">)</span>
490 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-down
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'down
<span class=
"br0">)</span><span class=
"br0">)</span>
491 <span class=
"br0">(</span>define
<span class=
"br0">(</span><span class=
"sy0">&</span>move-selection-up
<span class=
"br0">)</span> <span class=
"br0">(</span>move-selection 'up
<span class=
"br0">)</span><span class=
"br0">)</span>
493 <span class=
"co1">; Define shortcuts
</span>
494 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"Left
"</span> '
<span class=
"sy0">&</span>move-selection-left
<span class=
"br0">)</span>
495 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"Right
"</span> '
<span class=
"sy0">&</span>move-selection-right
<span class=
"br0">)</span>
496 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"Up
"</span> '
<span class=
"sy0">&</span>move-selection-up
<span class=
"br0">)</span>
497 <span class=
"br0">(</span>global-set-key
<span class=
"st0">"Down
"</span> '
<span class=
"sy0">&</span>move-selection-down
<span class=
"br0">)</span></pre>