User Tools

Site Tools


geda:guile_scripting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
geda:guile_scripting [2015/09/11 17:27]
vzh A few examples on group attribute editing
geda:guile_scripting [2016/02/09 11:56] (current)
vzh Add a link to new page about REPL
Line 15: Line 15:
 ==== Reference documents ==== ==== Reference documents ====
   * [[gnetlist Scheme primitives]]   * [[gnetlist Scheme primitives]]
 +  * [[gschem repl|Using REPL in gschem]]
  
 ==== Scripting examples ==== ==== Scripting examples ====
Line 20: Line 21:
   * just hit <​key>:</​key>​ and enter <code lisp>​(load "​filename.scm"​)</​code>​   * just hit <​key>:</​key>​ and enter <code lisp>​(load "​filename.scm"​)</​code>​
   * then hit <​key>​Enter</​key>​   * then hit <​key>​Enter</​key>​
 +
 +You can install them as well if you don't want to load them every time:
 +  * copy the script you want into your //''​~/​.gEDA''//​ directory
 +  * put the line <code lisp>​(load "​filename.scm"​)</​code>​ into your //''​~/​.gEDA/​gschemrc''//​ (replace //​filename.scm//​ with the real name of the script)
 +
  
 === Removing objects with specific properties === === Removing objects with specific properties ===
Line 74: Line 80:
 **gaf shell** batch scripts: **gaf shell** batch scripts:
   * ''​schematic-file->​page''​   * ''​schematic-file->​page''​
-  * ''​page->​schematic-files''​+  * ''​page->​schematic-file''​
  
 <file lisp geda-io.scm>​ <file lisp geda-io.scm>​
Line 167: Line 173:
 ; If no objects are selected, opens gschem message dialog with ; If no objects are selected, opens gschem message dialog with
 ; warning. ; warning.
-Returns ​value is unspecified.+Return ​value is unspecified.
 (define (multiple-copy-move-and-rotate-selection vector angle num) (define (multiple-copy-move-and-rotate-selection vector angle num)
   (if (null? (page-selection (active-page)))   (if (null? (page-selection (active-page)))
Line 301: Line 307:
 Usage of the procedure in **gschem**: Usage of the procedure in **gschem**:
 <code lisp> <code lisp>
-(use-another-func! ​100 -)+(use-another-func! -)
 (define (multiply-by-2 x) (define (multiply-by-2 x)
   (* 2 x))   (* 2 x))
 (use-another-func! multiply-by-2) (use-another-func! multiply-by-2)
 </​code>​ </​code>​
 +
 +=== Moving objects using arrows ===
 +Let's define actions to move selected objects using
 +<​key>​Shift</​key>​ + arrow keys.
 +
 +<file lisp arrow-move.scm>​
 +(use-modules (gschem selection))
 +
 +; Default offset to move
 +(define offset 100)
 +
 +; Get moving vector
 +(define (move-selection direction)
 +  (apply translate-objects!
 +    (case direction
 +      ((left ) (cons (- offset) 0))
 +      ((right) (cons (+ offset) 0))
 +      ((down ) (cons 0 (- offset)))
 +      ((up   ) (cons 0 (+ offset)))
 +      (else #f))
 +    (page-selection (active-page))))
 +
 +; Define actions
 +(define (&​move-selection-left ) (move-selection 'left ))
 +(define (&​move-selection-right) (move-selection '​right))
 +(define (&​move-selection-down ) (move-selection 'down ))
 +(define (&​move-selection-up ​  ) (move-selection '​up ​  ))
 +
 +; Define shortcuts
 +(global-set-key "<​Shift>​Left" ​ '&​move-selection-left)
 +(global-set-key "<​Shift>​Right"​ '&​move-selection-right)
 +(global-set-key "<​Shift>​Up" ​   '&​move-selection-up)
 +(global-set-key "<​Shift>​Down" ​ '&​move-selection-down)
 +</​file>​
 +
 +The following script redefines current shortcuts so that if
 +nothing is selected the canvas is moved with arrow keys (without
 +<​key>​Shift</​key>​ in this case), otherwise selected objects are
 +moved.
 +
 +<file lisp arrow-move2.scm>​
 +(use-modules (gschem selection))
 +
 +; Default offset to move
 +(define offset 100)
 +
 +; Get moving vector
 +(define (move-selection direction)
 +  (let ((selection (page-selection (active-page))))
 +    (if (null? selection)
 +      ; default behaviour
 +      (case direction
 +          ((left ) (&​view-pan-left))
 +          ((right) (&​view-pan-right))
 +          ((down ) (&​view-pan-down))
 +          ((up   ) (&​view-pan-up))
 +          (else #f))
 +      ; modified behaviour
 +      (apply translate-objects!
 +        (case direction
 +          ((left ) (cons (- offset) 0))
 +          ((right) (cons (+ offset) 0))
 +          ((down ) (cons 0 (- offset)))
 +          ((up   ) (cons 0 (+ offset)))
 +          (else #f))
 +        (page-selection (active-page))))
 +    ))
 +
 +; Define actions
 +(define (&​move-selection-left ) (move-selection 'left ))
 +(define (&​move-selection-right) (move-selection '​right))
 +(define (&​move-selection-down ) (move-selection 'down ))
 +(define (&​move-selection-up ​  ) (move-selection '​up ​  ))
 +
 +; Define shortcuts
 +(global-set-key "​Left" ​ '&​move-selection-left)
 +(global-set-key "​Right"​ '&​move-selection-right)
 +(global-set-key "​Up" ​   '&​move-selection-up)
 +(global-set-key "​Down" ​ '&​move-selection-down)
 +</​file>​
  
geda/guile_scripting.1442006864.txt.gz ยท Last modified: 2015/09/11 17:27 by vzh