home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / conv / imagestudio / rexx.lha / BatchProcess.isrx < prev    next >
Text File  |  1995-03-01  |  8KB  |  307 lines

  1. /* ImageStudio ARexx script **************************************/
  2.  
  3. /* Allow commands to return results */
  4.  
  5. options results
  6.  
  7. /* On error, goto ERROR:. Comment out this line if you wish to */
  8. /* perform your own error checking. */
  9.  
  10. signal on error
  11.  
  12. /* BEGIN PROGRAM *************************************************/
  13.  
  14. /* Warn the user if they are about to overwrite their current project */
  15.  
  16. IMAGEINFO_GET STEM imageinfo.
  17.  
  18. if imageinfo.changed == 1 then
  19.     REQUEST_MESSAGE TEXT '"Project has changed, continue?"',
  20.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  21.  
  22. /* Choose source files */
  23.  
  24. REQUEST_MULTIFILE TITLE '"Choose source files..."' STEM srcfiles.
  25.  
  26. /* Use separate destination directory ? */
  27.  
  28. REQUEST_MESSAGE TEXT '"Use different destination directory?"',
  29.     BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  30.  
  31. if result == 1 then
  32.     REQUEST_DIR TITLE '"Choose destination directory..."' VAR destdir
  33. else
  34.     destdir = ':NONE:'
  35.  
  36. REQUEST_LIST TITLE '"Choose output format..."' STRINGS,
  37.     '"IFF-ILBM"',
  38.     '"BMP"',
  39.     '"EPS"',
  40.     '"JPEG"',
  41.     '"PCX"',
  42.     '"Targa"' STEM saveformat.
  43.  
  44. /* Set up a blank ARGS string, which we can add to */
  45.  
  46. saveargs = 'ARGS "'
  47.  
  48. /* Get any IFF-ILBM args ? */
  49.  
  50. if saveformat.string == 'IFF-ILBM' then do
  51.     /* Get a subformat */
  52.  
  53.     REQUEST_MESSAGE TEXT '"Choose ILBM format..."' BUTTONTEXT,
  54.         '"As buffer|HAM6|HAM8|EHB|Cancel"' AUTOCANCEL
  55.  
  56.     /* Store subformat */
  57.  
  58.     if result == 2 then
  59.         saveargs = saveargs||'SUBFORMAT HAM6'
  60.     else if result == 3 then
  61.         saveargs = saveargs||'SUBFORMAT HAM8'
  62.     else if result == 4 then
  63.         saveargs = saveargs||'SUBFORMAT EHB'
  64.  
  65.     /* Get the dither if not saving as buffer */
  66.  
  67.     if result ~= 1 then do
  68.         REQUEST_MESSAGE TEXT '"Choose ILBM dither..."' BUTTONTEXT,
  69.             '"None|Floyd-Steinberg|Cancel"' AUTOCANCEL
  70.  
  71.         /* Store the dither */
  72.  
  73.         if result == 2 then
  74.             saveargs = saveargs||' DITHER FS'
  75.  
  76.         end
  77.  
  78.     /* Ask whether should set screenmode of images */
  79.  
  80.     REQUEST_MESSAGE TEXT '"Set screenmode of images?"',
  81.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  82.  
  83.     if result == 1 then do
  84.         setscreenmode = 1
  85.  
  86.         REQUEST_SCREENMODE STEM screenmode.
  87.  
  88.         imagescreenmode = screenmode.modeid
  89.  
  90.         end
  91.     else
  92.         setscreenmode = 0
  93.     end
  94. else if saveformat.string == 'EPS' then do
  95.     /* Get the DPI of the image */
  96.  
  97.     REQUEST_STRING TEXT1 '"Enter the DPI resolution of"',
  98.         TEXT2 '"the EPS files to be saved:"',
  99.         STRING 300 VAR dpiinfo
  100.  
  101.     saveargs = saveargs||dpiinfo
  102.  
  103.     /* Ask whether to save as colour or greyscale */
  104.  
  105.     REQUEST_MESSAGE TEXT '"Greyscale or colour EPS?"' BUTTONTEXT,
  106.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  107.  
  108.     if result == 2 then
  109.         saveargs = saveargs||' COLOUR'
  110.  
  111.     end
  112. else if saveformat.string == 'JPEG' then do
  113.     /* Get the DPI of the image */
  114.  
  115.     REQUEST_STRING TEXT1 '"Enter the JPEG quality setting"',
  116.         TEXT2 '"for the files to be saved."',
  117.         TEXT3 '"(Valid values 25 to 100):"',
  118.         STRING 75 VAR qualityinfo
  119.  
  120.     saveargs = saveargs||qualityinfo
  121.  
  122.     /* Ask whether to save as colour or greyscale */
  123.  
  124.     REQUEST_MESSAGE TEXT '"Greyscale or colour JPEG?"' BUTTONTEXT,
  125.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  126.  
  127.     if result == 1 then
  128.         saveargs = saveargs||' GREYSCALE'
  129.  
  130.     end
  131.  
  132. /* We may or may not have created an ARGS string. If we have, lets */
  133. /* finish it off, else lets delete it */
  134.  
  135. if saveargs == 'ARGS "' then
  136.     saveargs = ''
  137. else
  138.     saveargs = saveargs||'"'
  139.  
  140. /* Rename filenames ? */
  141.  
  142. REQUEST_MESSAGE TEXT '"Rename filenames ?"' BUTTONTEXT,
  143.     '"Yes|No|Cancel"' AUTOCANCEL
  144.  
  145. if result == 1 then do
  146.     /* Set the rename files */
  147.  
  148.     renamefiles = 1
  149.  
  150.     /* Get the rename pattern */
  151.  
  152.     REQUEST_STRING TEXT1 '"Choose the filename extension"',
  153.         TEXT2 '"for example: .pcx .ilbm"',
  154.         TEXT3 '"would rename all PCX files to ILBM"',
  155.         STRING '". .'||saveformat.string||'"',
  156.         VAR renamestring
  157.     end
  158. else
  159.     renamefiles = 0
  160.  
  161. /* If we're renaming, we should ask if they want the source file */
  162. /* deleted. If we're not renaming, we should warn the user that */
  163. /* the source file will be overwritten. */
  164.  
  165. if renamefiles == 1 then do
  166.     REQUEST_MESSAGE TEXT '"Delete source files ?"',
  167.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  168.  
  169.     if result == 1 then
  170.         deletesource = 1
  171.     else
  172.         deletesource = 0
  173.     end
  174. else if renamefiles == 0 & destdir == ':NONE:' then
  175.     REQUEST_MESSAGE TEXT '"WARNING : Source files will\nbe overwritten."',
  176.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  177.  
  178. /* Ask user for process(s) to apply to image before saving out */
  179.  
  180. REQUEST_STRING TITLE '"Enter processes to apply..."',
  181.     TEXT1 '"Enter the processes to apply before"',
  182.     TEXT2 '"saving out the image (separate "',
  183.     TEXT3 '"commands with semi-colon ;)"' VAR process
  184.  
  185. /* Loop around and convert all the files */
  186.  
  187. do l = 0 to (srcfiles.files.count - 1)
  188.     /* Open the file */
  189.  
  190.     OPEN FILE '"'srcfiles.files.l'"' FORCE
  191.  
  192.     /* If you wish to customize this macro to perform any operations */
  193.     /* on the image before saving it out (e.g. resizing, colour */
  194.     /* reduction etc...), add the commands here */
  195.  
  196.     interpret process
  197.  
  198.     /* Set the screenmode if neccessary */
  199.  
  200.     if setscreenmode == 1 then
  201.         IMAGEINFO_SET MODEID imagescreenmode
  202.  
  203.     /* Create the output filename */
  204.  
  205.     if destdir ~= ':NONE:' then do
  206.         /* Get the filepart of the source filename */
  207.  
  208.         FILE_SPLIT FILE '"'srcfiles.files.l'"' STEM filesplit.
  209.  
  210.         /* Create the destfile */
  211.  
  212.         FILE_JOIN PATHPART '"'destdir'"',
  213.             FILEPART '"'filesplit.filepart'"' VAR 'destfile'
  214.  
  215.         end
  216.     else
  217.         destfile = srcfiles.files.l
  218.  
  219.     /* Rename file ? */
  220.  
  221.     if renamefiles == 1 then 
  222.         FILE_RENAME FILE '"'destfile'"' renamestring,
  223.             VAR 'destfile'
  224.  
  225.     /* Save the fileout in the new format */
  226.  
  227.     SAVE FILE '"'destfile'"' FORMAT '"'saveformat.string'"',
  228.         saveargs FORCE
  229.  
  230.     /* Delete source file (and icon) if required */
  231.  
  232.     if renamefiles == 1 & deletesource == 1 then do
  233.         /* Make sure hasn't been renamed to same name */
  234.  
  235.         if upper(srcfiles.files.l) == upper(destfile) then
  236.             break
  237.  
  238.         address command 'delete <NIL: >NIL: "'||srcfiles.files.l||'"'
  239.  
  240.         if exists(srcfiles.files.l||'.info') == 1 then
  241.             address command 'delete <NIL: >NIL: "'||,
  242.                 srcfiles.files.l||'.info"'
  243.         end
  244.     end
  245.  
  246.  
  247. /* END PROGRAM ***************************************************/
  248.  
  249. exit
  250.  
  251. /* On ERROR */
  252.  
  253. ERROR:
  254.  
  255. /* If we get here, either an error occurred with the command's */
  256. /* execution or there was an error with the command itself. */
  257. /* In the former case, rc2 contains the error message and in */
  258. /* the latter, rc2 contains an error number. SIGL contains */
  259. /* the line number of the command which caused the jump */
  260. /* to ERROR: */
  261.  
  262. if datatype(rc2,'NUMERIC') == 1 then do
  263.     /* See if we can describe the error with a string */
  264.  
  265.     select
  266.         when rc2 == 103 then
  267.             err_string = "ERROR 103, "||,
  268.                 "out of memory at line "||SIGL
  269.         when rc2 == 114 then
  270.             err_string = "ERROR 114, "||,
  271.                 "bad command template at line "||SIGL
  272.         when rc2 == 115 then
  273.             err_string = "ERROR 115, "||,
  274.                 "bad number for /N argument at line "||SIGL
  275.         when rc2 == 116 then
  276.             err_string = "ERROR 116, "||,
  277.                 "required argument missing at line "||SIGL
  278.         when rc2 == 117 then
  279.             err_string = "ERROR 117, "||,
  280.                 "value after keywork missing at line "||SIGL
  281.         when rc2 == 118 then
  282.             err_string = "ERROR 118, "||,
  283.                 "wrong number of arguments at line "||SIGL
  284.         when rc2 == 119 then
  285.             err_string = "ERROR 119, "||,
  286.                 "unmatched quotes at line "||SIGL
  287.         when rc2 == 120 then
  288.             err_string = "ERROR 120, "||,
  289.                 "line too long at line "||SIGL
  290.         when rc2 == 236 then
  291.             err_string = "ERROR 236, "||,
  292.                 "unknown command at line "||SIGL
  293.         otherwise
  294.             err_string = "ERROR "||rc2||", at line "||SIGL
  295.         end
  296.         end
  297. else if rc2 == 'RC2' then do
  298.     err_string = "ERROR in command at line "||SIGL
  299.     end
  300. else do
  301.         err_string = rc2||", line "||SIGL
  302.         end
  303.  
  304. request_message TEXT '"'err_string'"'
  305.  
  306. exit
  307.