Post Reply 

Somewhat like a Script-Fu Documentation in Source. (Originally about load-routine)

Jun 22, 2011, 21:16 (This post was last modified: Jun 24, 2011 10:18 by lupo.)
Post: #1
Somewhat like a Script-Fu Documentation in Source. (Originally about load-routine)
1. Context of the Problem

I'm trying to automate some repetitive tasks in creating textures. These involve saving different layers to different output png images, blurring and applying bump-maps and some minor other tasks. Those tasks occur up to once per minute, because I have constantly to switch between the Second Life client and gimp in order to adjust the textures to the 3D objects and the UV-maps seams in particular, e.g. in order to make a line go continously from back to front of an avatar.

For this sake I have written a layer-name-parser, that reads arguments for later to be implemented plug-ins for executing those commands encoded into the layer names.

The Scheme code has gotten pretty complex by now. My source file currently has 400 lines with 15 top-level function definitions, containing both general purpose routines (like a list-set! method and methods for associative list manipulation) and plugin-specific routines, making breaking the file up into several files very enticing, especially creating a folder structure.

2. The Problem

The problem comes down to: Can I somehow load script file's relative to a script files directory?

2.1 Details

In a script meant for testing the routines, I wrote (load "bumpmap-project.scm"). It turned out that this doesn't work, unless I specify an absolute path (load "E:\\lib\\gimp-scripts\\bumpmap-project.scm"), which would reduce the portabilty of the script. Apparently the same problem would apply to script files moved to subfolders and included into top-level scripts.

Furthermore no way I know of updating scripts seems to work properly. When I write in the console (script-fu-refresh n) where n is 0 or 1, or use the "Filter->Script-Fu->Refresh Scripts" (or whatever it is called in English) menu option, the console still would not use updated scripts, unless I explicitly load the source files with (load absolute-path). Using a using a construct like (gimp-message (some-function)) though, I have verified, that the new definitions are read -- just the console keeps the old ones.

This changes the simple call (load "E:/lib/gimp-scripts/tests/testsfile") into (load file1)(load file2) (load file3) (load "E:/......."). Well, it works of course, but again its at least little elegant.

Of course E:\lib\gimp-scripts is added as script-folder in GIMP.

3. Possible Solutions?

I have though of a couple of unsatisfactory work-arounds, e.g. "compiling" the files by including preprocessor directives. The C preprocessor should work finde, despite not being meant for Scheme. Still, there should be some Script-Fu native solution. After all, distributing a damn script with a makefile sounds pretty awkward... And distributing the "compiled" file would make debugging difficult for other users (e.g. when using it in an incompatible script-fu in future).

4. Executing Environment

Windows 7
GIMP 2.6
Python 2.5 and 2.6 installed and included in PATH variable; Python-Fu still doesn't show up in GIMP.
Cygwin installed for easier access to scripting tools.
Find all posts by this user
Quote this message in a reply
Jun 22, 2011, 22:46
Post: #2
RE: Script-Fu's load routine: Relative paths to script files?
Well, I'd prefer a solution for Scheme ^^
Find all posts by this user
Quote this message in a reply
Jun 23, 2011, 16:11
Post: #3
RE: Script-Fu's load routine: Relative paths to script files?
(Jun 23, 2011 08:31)paynekj Wrote:  You can access the standard users scripts folder by using the gimp-directory internal function
(see: )
so your standard scripts folder should be
(string-append gimp-directory DIR-SEPARATOR "scripts")

I just noticed again, how badly documented Script-Fu is...

Is there some way to obtain a list of all defined functions? The procedure browser only includes gimp-specific functions, but Tiny-Scheme functions, that are no gimp-specific but neither in the R5RS specification are not listed anywhere in a complete and correct way. E.g. under your link "gimp-directory" is called a function even though it is a string constant.

Also I can't quite believe, that there is a function "assoc" as specified in R5RS, for obtaining a specific key-value pair from an associative list, but no "assoc-set-entry" or "assoc-delete-entry". Neither does the specification, to my knowledge, contain a routine for copying a list (which can be done by "(reverse (reverse list))" though). Also I've noticed that some routines handle arguments differently from the specification in R5RS, though I don't remember which.

My current solution to the original problem though is to put a line "(define current-directory "E:\\lib\\gimp-scripts\\")" in the beginning of a file and handle imports from there.

Thus the "only" problem of a lack of proper documentation for both
  • Tiny Fu's extensions of and changes to Standard Scheme
  • Script-Fu's extensions (and changes?) to Tiny Fu, that are not represented in the procedure browser

Ideally of course there would be a comprehensive official documentation of Gimp 2.6 Tiny-Fu, but considering that the Gimp documentation contains a TUTORIAL on Script-Fu, but nothing else, I doubt there is such a thing.

(Jun 23, 2011 08:31)paynekj Wrote:  On another note, I almost never use the console. I'd try running your scripts from menu entries.

Well, the console is useful for debugging.
  1. Interactive testing of subroutines which allows viewing the output of the `write' and `display' routines. I don't know any interactive way outside the console to print arbitrary length external representations of Scheme objects other than strings and symbols.
  2. Trying out Scheme constructs, I'm not sure about: The error messages generated by tiny-fu aren't exactly helpful and tracing is too verbose.
  3. ...

By the way, I have again confirmed, that only explicity use of the `load' routine updates the definitions in a running console session. Not a problem though, as I have just defined a routine for that in my top-level script.
Find all posts by this user
Quote this message in a reply
Jun 24, 2011, 10:16
Post: #4
RE: Script-Fu's load routine: Relative paths to script files?
I just found something interesting with regard to documentation:

In the source:
  • gimp-2.6.2/plug-ins/script-fu/tinyscheme/Manual.txt : Lists many function that are implemented, and explanations why some are not.
  • Function "(oblist)": Supposedly returns a list of all defined symbols.
  • (get-closure-code closure) for printing the definition of non-primitivefunctions.
  • gimp-2.6.2/plug-ins/script-fu/script-fu-enums.h : Lists SF-constants; Maybe all of them?
  • gimp-2.6.2/plug-ins/script-fu/scripts/script-fu.init : Defines many interesting non-primitivefunction -- that includes such common function as caar, cadr...
  • gimp-2.6.2/plug-ins/script-fu/tinyscheme/opdefines.h : Contains a very extensive list of native functions in a actually "C" but still tabular format. Also specifies the arguments (valid types and whether an arbitrary tail of arguments is accepted). Things like "let" are not here though (so I suppose it only contains true procedures).
Find all posts by this user
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Run script on action rchav 2 880 Aug 13, 2018 14:57
Last Post: rchav
  Script Fu Errors Gimp 2.10.4 lightsaber jd3481 1 559 Aug 2, 2018 05:13
Last Post: paynekj
  Script-fu script to conversion pdf to image 4ever 12 11,470 Jul 17, 2018 16:01
Last Post: paynekj
  Problems with a bat script :( ThaUnknown_ 1 526 Mar 26, 2018 21:14
Last Post: paynekj
  Script-fu ordered file list vnicent 1 341 Mar 19, 2018 17:33
Last Post: paynekj

Forum Jump:

GIMP ForumPortalArchiveContactTermsRSS