/*
				Process-Dir.rexx

				Example script that applies a plugin-effect to all files of a
				directory

				Refer to ArtEffect:Rexx/Rexx.doc for a complete command
				description

				Attention: filenames must not include any blank spaces!
*/

OPTIONS RESULTS
OPTIONS FAILAT 21
SIGNAL ON ERROR

/* Check for ArtEffect ARexx port */
IF ~SHOW(P,"ArtEffect") THEN DO
		SAY D2C(7)
		SAY "ATTENTION:"
		SAY "Could not find ArtEffect ARexx port."
		SAY "Please make sure that ArtEffect is running."
		SAY
		EXIT
END

ADDRESS "ArtEffect"

/* check for rexxsupport.library (necessary for ShowDir) */
IF ~SHOW('L', "rexxsupport.library") THEN
		IF ~ADDLIB('rexxsupport.library', 0, -30) THEN DO
				REQUESTNOTIFY TITLE '"System error"' PROMPT '"rexxsupport.library
				could not be opened"'
				EXIT 10
		END

/* Filerequester - get a list of all files to be processed */
REQUESTFILE VAR filterdir PATH "ArtEffect:" TITLE '"Choose directory"' DIR
IF ~RC = 0 THEN REQUESTNOTIFY TITLE '"An error has occured"' PROMPT '"You cancelled the requester"'

filelist = ShowDir(filterdir, FILE,)

REQUESTRESPONSE VAR inplace TITLE '"Please select..."' PROMPT '"Do you want to save the modified pictures|over the original ones?"' OPTIONS "Yes|No"

IF inplace = 1 THEN REQUESTFILE VAR savepath TITLE '"Choose directory"' DIR

/* keep user from interfering */
LOCKGUI

/* repeat loop until all files have been processed */
DO WHILE ~(Compress(filelist) = "")

		/* get name of file to be processed */
		currfile = SubWord(filelist, 1, 1)

		/* attach full path to filename */
		picpath = filterdir || currfile

		/* load the picture */
		LOADPIC picpath

		/* change this to the desired plugin */
		DOMETHOD QUIT 'POINTISE'

		IF inplace = 0 THEN SAVEPIC NAME picpath PLUGIN 'JFIF-JPEG' /* insert
		desired save format here */
				ELSE DO
						picpath = savepath || currfile
						SAVEPIC NAME picpath PLUGIN 'JFIF-JPEG' /* insert desired save
						format here */
				END

		/* close the picture */
		CLOSEPIC FORCE

		/* remove the file that was just processed from the list of files
		still to be processed */
		filelist = SubStr(filelist, Length(currfile)+2)
END

/* Tell the user everything went fine */
REQUESTNOTIFY TITLE '"User information"' PROMPT "All pictures were
processed successfully."

/* return control to user - NEVER forget this! */
UNLOCKGUI

EXIT

/* this function is executed when an error occurs in the script */
ERROR:
		/* tell the user in which line of this script to look for the error */
		REQUESTNOTIFY TITLE '"ARexx-Error"' PROMPT "ARexx-error no." RC " has occured in line" SIGL "."

		/* do not forget to unlock the GUI */
		UNLOCKGUI

EXIT


/******************************************************************/
/*                                                                */
/*                VAnim.rexx V1.1 for ArtEffect 2.5.x             */
/*                                                                */
/* This rexxscript assembles a series of pictures to form a       */
/* TransferAnim for Voyager or IBrowse.                           */
/*                                                                */
/* Written by: Eike M. Lang <elang@online-club.de>                */
/* Homepage:   http://jayhawk.home.pages.de/                      */
/*                                                                */
/* Usage: create a number of pictures of equal size that will be  */
/* the frames of the animation.  These pictures must be numbered  */
/* consistently.                                                  */
/* The name format for the frames MUST be <filename>.xxxx         */
/* Where xxxx can be anything between 0000 and 9999               */
/* <filename> can be any AmigaDOS-legal file name.                */
/* Run the script from the shell or directly from ArtEffect.      */
/* You can freely choose the start- and end-frames, but naturally */
/* all frames in between those should exist.                      */
/* Once the animation is assembled you are given the choice of    */
/* saving it immediately.                                         */
/*                                                                */
/* The script tries to cover all common error-situations, but if  */
/* you try hard enough, you'll still be able to mess it up.       */
/* So don't get fancy and try to use anim-frames of different     */
/* sizes (which would also look funny in Voyager and IBrowse) and */
/* don't try to use your C sources or anything like that as anim  */
/* frames.                                                        */
/*                                                                */
/* This script is freeware which means I retain full copyright    */
/* on it. Permission is granted to Haage&Partner GmbH to include  */
/* this script with ArtEffect.                                    */
/*                                                                */
/******************************************************************/

OPTIONS RESULTS
OPTIONS FAILAT 21
SIGNAL ON ERROR

/* Check for ArtEffect ARexx port */
IF ~SHOW(P,"ArtEffect") THEN DO
		SAY D2C(7)
		SAY "ATTENTION:"
		SAY "Could not find ArtEffect ARexx port."
		SAY "Please make sure that ArtEffect is running."
		SAY
		EXIT
END

ADDRESS "ArtEffect"



/* keep the user from interfering */
LOCKGUI

/* Find out path and name of the first and last picture */
REQUESTFILE VAR firstfile TITLE '"Select the first picture"'
picpath=Left(firstfile, LastPos('/',firstfile))
REQUESTFILE VAR lastfile PATH picpath TITLE '"Select the last picture"'

/* Load the last picture to be used */
LOADBRUSH lastfile
IF RC~=0 THEN
		CALL NOTIFY("File" lastfile "could not be found.")

/* get width/height of the frames */
GET STEM brush. BRUSHINFO

/* assign some variables we need */
/* This is the base name of the variable without the number extension */
stemname=Left(firstfile, Pos('.', firstfile))

/* This is the number of the first image to use */
startnumber=Right(firstfile, Length(firstfile)-LastPos('.', firstfile))

/* This is the number of the last image to use */
endnumber=Right(lastfile, Length(lastfile)-LastPos('.', lastfile))

/* Now calculate the total width of the animation */
totalwidth=brush.width*(endnumber-startnumber+1)

/* Sanity check */
IF totalwidth<1 THEN
		NOTIFY("The last file must have a greater|number than the first one.")

/* Generate a new project with the right size */
NEW WIDTH totalwidth HEIGHT brush.height NAME "TransferAnim"

/* Main loop */
DO i=0 TO (endnumber-startnumber)

		/* calculate the current file for this cycle */
		currfile=stemname || Right(i+startnumber, 4, 0)

		/* attempt to load it */
		LOADBRUSH currfile

		/* Check existence of each file */
		IF RC~=0 THEN
				CALL NOTIFY("File" currfile "could not be found.|Please make sure all files between|" firstfile "and" lastfile "exist.")

		/* Make position caculation as easy as possible */
		CHANGEBRUSH HANDLE TOPLEFT

		/* Finally put the image on the page */
		PLOT i*brush.width 0 PT PEN MODE MATTE STR 100
END

/* Give the user the chance to save his creation right away */
REQUESTRESPONSE VAR choice TITLE '"User Query"' PROMPT '"Do you want to save this animation?"' OPTIONS "Yes|No|Don't Know"

/* Save-file feat. full(?) sanity-check */
IF choice=0 THEN DO
		REQUESTFILE VAR saveanim TITLE '"Save Animation"' FILE "TransferAnim"
		SAVE
		IF RC~=0 THEN
				CALL NOTIFY("You cancelled the saving process.")
		SAVEPIC NAME saveanim PLUGIN IFF-ILBM
		IF RC~=0 THEN
				CALL NOTIFY("File" savenanim "could not be saved.")
END

/* Notify user that he can save the file at a later time */
ELSE REQUESTNOTIFY TITLE "Message" OK '"I see"' PROMPT "You can still save the|animation manually."

/* return control to user */
UNLOCKGUI

EXIT

/* Error notification - saves a few lines of rexx code */
NOTIFY:
		/* Get the actual error */
		PARSE ARG Errorstring

		/* Notify user via the ArtEffect-provided requester */
		REQUESTNOTIFY TITLE "Error" PROMPT Errorstring

		/* always make sure the GUI is unlocked after errors */
		UNLOCKGUI
		EXIT
RETURN

/* Handling of errors that are not intercepted by the script itself
	 The most common situation for this message to appear is that the
	 user did not follow the naming conventions for the frames.
	 This error will of course also occur when trying to load files of
	 the wrong format - ASCII, binaries, etc. ;-) */

ERROR:
		REQUESTNOTIFY TITLE "ARexx-Error" PROMPT "ARexx-error no." RC "has occured in line" SIGL ".|Please make sure the pictures are properly named|and numbered."
		UNLOCKGUI
EXIT


