SC, Image Files and MPI

More Exporting - Multiple files - Scripting

Here is a script for the Export Button
on mouseUp

--First Collect all the information we need
put the short name of btn id 321 into tFileType
if tFileType = "jpeg" then put the short name of btn id 322 into tquality
put the currentValue of cd btn id 324=2 into needToScale
if needtoscale
then
put cd fld "maxwidth" into tMaxWidth
put cd fld "maxHeight" into TmaxHeight
if Not isnumber( TmaxHeight )
then
answer "You need to fill in max height."
exit to superCard
end if
if Not isnumber( TmaxWidth )
then
answer "You need to fill in max width."
exit to superCard
end if
end if
put the number of lines in cd fld "imageList" of cd 1 of wd 1 into tMax
put the currentValue of cd btn id 329 = 1 into useOriginalnames
if not useOriginalnames
then
if the hilight of cd btn "use prefix" then put cd fld "prefix" into tPreFix
else put "" into tPreFix
put 0 into tnum
--we want numbers with leading zeros so that 15 is not before 2 in finder
repeat the number of chars in tMax
put 0 after tNumberFormat
end repeat
put ".####" after tNumberFormat
put the numberformat into toldNumberFormat
set the numberformat to tNumberFormat
end if
put the uImagePaths of cd fld "imagelist" of cd 1 of wd 1 into tFiles

Now we have the information we get a folder to put the exported files into


answer  folder "Export images to folder:" 

if it is "" then exit mouseUp
put it into tfolderPath
--close the export window or make sure the autodim of the image graphic is false
close wd "export"
setWindow Wd 1 --just in case, or if we don't close wd above
lock screen

We now have all the information we need so should be able to loop though the files exporting them.
repeat with x = 1 to tMax

set the cursor to busy
put line x of tFiles into tSourceFile
if uSeOriginalnames
then
--we need the file name without extension
set the itemDel to colon
put last item of tSourceFile into tName
set the itemDel to "."
delete last item of tName
put tFolderPath&tName&"."&tFileType into tfilepath
else --if we are making numbered names
put tFolderPath&TPreFix&tnum&"."&tFileType into tfilepath
add 1 to tNum
end if
set the pictureData of cd grc "imageDisplay" to tSourceFile
if not needToScale
then
--just export the picturedata
if tfileType is not "jpeg"
then do merge("export the pictureData of cd grc `imageDisplay` of cd 1 of wd 1 to [[tFileType]] file `[[tfilepath]]`")
else do merge("export the pictureData of cd grc `imageDisplay` of cd 1 of wd 1 to [[tFileType]] file `[[tfilepath]]` with [[tquality]]")
else
--we will resize the graphic and export card from topLeft of graphic to Bottomright
put the topleft of cd grc "imageDisplay" into tTopleft
--we will use the shrinktoFit handler we used before, it might be best in the project script now rather than the card script
get shrinkTofit( the width of cd grc "imageDisplay",the height of cd grc "imageDisplay",tMaxWidth,tmaxHeight)
set the itemdel to comma
set the width of cd grc "imageDisplay" to item 1 of it
set the height of cd grc "imageDisplay" to item 2 of it
set the topleft of cd grc "imageDisplay" to tTopLeft
if tfileType is not "jpeg"
then do merge("export card from topleft of cd grc `imageDisplay` to bottomright of cd grc `imageDisplay` to [[tFileType]] file `[[tfilepath]]`")
else do merge("export card from topleft of cd grc `imageDisplay` to bottomright of cd grc `imageDisplay` to [[tFileType]] file `[[tfilepath]]` with [[tquality]]")
end if
end repeat
set the pictureData of cd grc "imageDisplay" to (the upath of cd grc "imageDisplay")
send sizeGraphic to cd 1 of wd 1
end mouseUp
The last 2 lines of the script:
set the pictureData of cd grc "imageDisplay" to (the upath of cd grc "imageDisplay")

send sizeGraphic to cd 1 of wd 1
just makes sure the image that was shown at the start is the one shown at the end. We need to change the script in the imagelist field to set the userprop when choosing an image, after first defining the uPath of cd grc "imagedisplay" with MPI's userProp module.
The script of card field "imagelist" should now be:
on clicklist

lock screen
put the hilitedLines of me into tLine
put line tline of the uImagePaths of me into tfile
set the pictureData of cd grc 1 to file tfile
set the upath of cd grc "imageDisplay" to tfile
sizeGraphic
end clicklist