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:33
Post: #2
RE: Script-Fu's load routine: Relative paths to script files?
I use Python, and you can, from Python code, add directories to the Python path before loading some other python file. I no longer run Windows but at the time I installed Gimp with Python support without problems, using gimp-win's "experimental" installer. Otherwise t think it's mostly an appropriate declaration of the interpreter in some config file.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jun 22, 2011, 22:46
Post: #3
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 22, 2011, 22:57
Post: #4
RE: Script-Fu's load routine: Relative paths to script files?
(Jun 22, 2011 22:46)lupo Wrote:  Well, I'd prefer a solution for Scheme ^^
<breath>Come to the dark side of the scripts<breath>

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jun 23, 2011, 08:31
Post: #5
RE: Script-Fu's load routine: Relative paths to script files?
You can access the standard users scripts folder by using the gimp-directory internal function
(see: http://www.ve3syb.ca/wiki/doku.php?id=so...sf:writing )
so your standard scripts folder should be
Code:
(string-append gimp-directory DIR-SEPARATOR "scripts")

On another note, I almost never use the console. I'd try running your scripts from menu entries.
Find all posts by this user
Quote this message in a reply
Jun 23, 2011, 16:11
Post: #6
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: http://www.ve3syb.ca/wiki/doku.php?id=so...sf:writing )
so your standard scripts folder should be
Code:
(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
persists.

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, 08:39
Post: #7
RE: Script-Fu's load routine: Relative paths to script files?
I certainly agree that it's very badly documented and that rummaging around in the source code may be the only way to get a definitive list of what is supported.

Beware of assuming that R5RS is a good reference point however:
http://www.gimpusers.com/forums/gimp-dev...eventually
Find all posts by this user
Quote this message in a reply
Jun 24, 2011, 10:16
Post: #8
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
  Request for script chlebna 1 172 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 230 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 2 231 Aug 31, 2017 14:32
Last Post: Bertholomäus
  How to modify this script-fu? Zakary81 1 196 Aug 23, 2017 12:48
Last Post: paynekj
  Need help in running a gui script-fu via command line eyalzek 2 356 Oct 4, 2014 14:05
Last Post: eyalzek

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS