Author Topic: Code scrolling  (Read 2361 times)

0 Members and 1 Guest are viewing this topic.

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Code scrolling
« on: April 18, 2007, 10:04:11 AM »
Code: [Select]
property TypeList : {"BMP ", "EPSF", "GIFf", "JPEG", "PDF ", "PICT", "PNGf", "TIFF", "..CT"} -- File types of your graphic files
property LabelHeight : 16 -- Height of the Label Box (in points)
property HorSpace : 6 -- Gutter between column (in points)
property VerSpace : 12 -- Gutter between rows (in points)

property BoxWidth : 0 -- will be defined at run time
property BoxHeight : 0 -- will be defined at run time
property SourceFolder : "" -- will be defined at run time
property Xor : 0 -- will be defined at run time
property Yor : 0 -- will be defined at run time
property LabelSpace : 0 -- will be defined at run time
property curLabelHeight : 0 -- will be defined at run time
property MarginTop : 0 -- will be defined at run time
property MarginBottom : 0 -- will be defined at run time
property MarginLeft : 0 -- will be defined at run time
property MarginRight : 0 -- will be defined at run time
property docName : "" -- will be defined at run time
property ParaStyle : "" -- will be defined at run time
property ParaStyleSmall : "" -- will be defined at run time

property CurrentPictureWidth : 0
property CurrentPictureHeight : 0
property CurrentFileType : 0
property CurrentColorModel : 0
property CurrentScale : 0

tell application "QuarkXPress Passport 7"
activate
set QFolder to "Please locate the folder containing the images you wish to process"
set VContinue to false
set SetupTemp to false
try
set docName to name of document 1
set QOverwrite to "Do you really wish to overwrite the current document?"
set DOverwrite to display dialog QOverwrite buttons {"No – Use the template", "Yes"} default button 1 with icon note
if button returned of DOverwrite is "Yes" then
set SourceFolder to (choose folder with prompt QFolder) as text
set VContinue to true
tell document docName
make new page at beginning
make new page at beginning
try
delete (pages 2 thru -1)
end try
end tell
else
set SetupTemp to true
end if
on error
set SetupTemp to true
end try
end tell

if SetupTemp is true then
set TempFolder to (path to me) as text
tell application "QuarkXPress Passport 7"
set TemplateFile to (my FindReplace("Contact Sheet_Maker", "Contact Sheet_Template", TempFolder)) as alias
set SourceFolder to (choose folder with prompt QFolder) as text
open TemplateFile
set docName to name of document 1
tell master document docName
try
set contents of story 1 of text box "txt_Header" to my GetTExtItem(SourceFolder, ":", -2)
end try
end tell
set VContinue to true
end tell
end if

if VContinue then
set ItemList to list folder SourceFolder without invisibles
set FileList to {}
repeat with ThisItem in ItemList
set TheInfo to info for (file (SourceFolder & ThisItem))
if folder of TheInfo is false then
if file type of TheInfo is in TypeList then
set end of FileList to (ThisItem as text)
end if
end if
end repeat


tell application "QuarkXPress Passport 7"
activate
set QRows to "You have selected " & FileList's length & " images" & return & return & "How many rows would you like me to produce?"
set doLoop to true
repeat while doLoop is true
set DRows to display dialog QRows default answer "0" with icon note
try
set NumRows to (text returned of DRows) as integer
if NumRows > 0 then
set doLoop to false
else
display dialog "Number must be greater than 0!" with icon caution
end if
on error
display dialog "Numbers only please!" with icon caution
end try
end repeat

set QColumns to "You have selected " & FileList's length & " images" & return & return & "How many columns would you like me to produce?"
set doLoop to true
repeat while doLoop is true
set DColumns to display dialog QColumns default answer "0" with icon note
try
set NumCols to (text returned of DColumns) as integer
if NumCols > 0 then
set doLoop to false
else
display dialog "Number must be greater than 0!" with icon caution
end if
on error
display dialog "Numbers only please!" with icon caution
end try
end repeat

set QLabels to "What kind of labels wold you like?"
set DLabels to display dialog QLabels buttons {"None", "Full Info", "File name"} default button 2 with icon note
set LabelType to button returned of DLabels
--*)

if LabelType is not "None" then
if LabelType is "Full Info" then
set curLabelHeight to LabelHeight * 2.5
end if
if not (exists character spec "Label" of document docName) and not (exists style spec "Label" of document docName) then
set CharStyle to make new character spec at document docName's end with properties {name:"Label"}
set ParaStyle to make new style spec at document docName's end with properties {name:"Label"}
set character style of ParaStyle to CharStyle
end if
if not (exists character spec "Label Small" of document docName) and not (exists style spec "Label Small" of document docName) then
set CharStyleSmall to make new character spec at document docName's end with properties {name:"Label Small"}
set ParaStyleSmall to make new style spec at document docName's end with properties {name:"Label Small"}
set character style of ParaStyle to CharStyle
end if
set LabelSpace to curLabelHeight
else
set LabelSpace to 0
end if

tell document docName
set ParaStyle to object reference of style spec "Label" --of document DocName
set ParaStyleSmall to object reference of style spec "Label Small" --of document DocName
set OldHor to horizontal measure
set OldVer to vertical measure
set horizontal measure to points
set vertical measure to points
set PageWidth to page width as real
set PageHeight to page height as real
my Set_MarginValue(count of pages)
set DisplayWidth to PageWidth - MarginLeft - MarginRight
set DisplayHeight to PageHeight - MarginTop - MarginBottom
set BoxWidth to (DisplayWidth - (HorSpace * (NumCols - 1))) / NumCols
set BoxHeight to ((DisplayHeight - (VerSpace * (NumRows - 1))) / NumRows) - LabelSpace
tell ParaStyle
set tab list of paragraph attributes to {{justification:right justified, position:(BoxWidth - 5)}}
end tell
tell ParaStyleSmall
set tab list of paragraph attributes to {{justification:left justified, position:42}, {justification:right justified, position:(BoxWidth - 5)}}
end tell
end tell

set i to 1
repeat while i ? FileList's length
repeat with j from 1 to NumRows
repeat with K from 1 to NumCols
try
my Make_PicBox(K, j, (item i of FileList) as text)
if LabelType is "File name" then
my Make_LabelBox(K, j, (item i of FileList) as text)
else if LabelType is "Full Info" then
set ImageInfo to ((item i of FileList) as text) & tab & "(@ " & CurrentScale & ")" & return & "Largeur: " & tab & CurrentPictureWidth & tab & " (@ 100%)" & return & "Hauteur: " & tab & CurrentPictureHeight & tab & " (@ 100%)"
my Make_LabelBox(K, j, ImageInfo)
end if
on error
exit repeat
end try
set i to i + 1
end repeat
end repeat
if i < FileList's length then
tell document docName
make new page at end
set current page to page (count of pages)
my Set_MarginValue(count of pages)
end tell
end if
end repeat
tell document docName
set horizontal measure to OldHor
set vertical measure to OldVer
end tell

(*
if SetupTemp is true then
set PageCount to count of pages of document docName
tell master document docName
try
set contents of story 1 of text box "txt_TotalPages" to PageCount
end try
end tell
end if
*)
end tell
end if
beep 3

on Set_MarginValue(ThisPage)
tell application "QuarkXPress Passport 7"
tell document docName
set FacingPages to facing pages

tell page ThisPage
if (page number) mod 2 > 0 then -- Odd page
set Page_Parity to "Odd"
else -- Even page
set Page_Parity to "Even"
end if
end tell

if FacingPages and Page_Parity is "Odd" then
set MarginTop to top margin as real
set MarginBottom to bottom margin as real
set MarginLeft to inside margin as real
set MarginRight to outside margin as real

else if FacingPages and Page_Parity is "Even" then
set MarginTop to top margin as real
set MarginBottom to bottom margin as real
set MarginLeft to outside margin as real
set MarginRight to inside margin as real

else
set MarginTop to top margin as real
set MarginBottom to bottom margin as real
set MarginLeft to left margin as real
set MarginRight to right margin as real
end if

set Xor to MarginLeft
set Yor to MarginTop
end tell
end tell
end Set_MarginValue

on Make_PicBox(RowRun, ColRun, ThisPicture)
tell application "QuarkXPress Passport 7"
tell document docName
tell current page
set Y to ((ColRun - 1) * (BoxHeight + VerSpace + LabelSpace)) + Yor
set X to ((RowRun - 1) * (BoxWidth + HorSpace)) + Xor
set NewBox to make new picture box at beginning with properties {bounds:{Y, X, Y + BoxHeight, X + BoxWidth}, color:"none", frame:{color:"black", width:0.5}}
tell picture box 1
set image 1 to file ((SourceFolder & ThisPicture) as text)
tell image 1
set CurrentPictureWidth to (width of actual bounds) as text
set CurrentPictureHeight to (height of actual bounds) as text
set CurrentFileType to (file type) as text
set CurrentColorModel to «class modl» as text
end tell
set bounds of image 1 to proportional fit
set theScale to (scale of image 1) as list
set CurrentScale to (item 1 of theScale) as integer
if CurrentScale > 100 then
set scale of image 1 to {100, 100}
set bounds of image 1 to centered
set theScale to (scale of image 1) as list
end if
set CurrentScale to (item 1 of theScale) as text
end tell
end tell
end tell
end tell
end Make_PicBox

on Make_LabelBox(RowRun, ColRun, ThisLabel)
tell application "QuarkXPress Passport 7"
--set ParaStyle to object reference of style spec "Label" of document DocName
--set ParaStyleSmall to object reference of style spec "Label Small" of document DocName
tell document docName
tell current page
set Y to ((ColRun - 1) * (BoxHeight + VerSpace + LabelSpace)) + Yor
set X to ((RowRun - 1) * (BoxWidth + HorSpace)) + Xor
set NewBox to make new text box at beginning with properties {bounds:{Y + BoxHeight, X, Y + BoxHeight + curLabelHeight, X + BoxWidth}, color:"White", text inset:2, frame:{color:"black", width:0.5}}
tell NewBox
set contents of story 1 to ThisLabel
set style sheet of paragraph 1 of story 1 to ParaStyle
try
set style sheet of paragraphs 2 thru -1 of story 1 to ParaStyleSmall
end try
end tell
end tell
end tell
end tell
end Make_LabelBox

on DoMenu(This_Menu, First_Level, Second_Level)
tell application "QuarkXPress Passport 7"
try
if Second_Level is "" then
select menu item First_Level of menu This_Menu
else
select menu item Second_Level of menu item First_Level of menu This_Menu
end if
on error errMsg number errNum
display dialog ("An error " & errNum & " has occured" & return & return & errMsg) with icon stop
end try
end tell
end DoMenu

on GetTExtItem(ThisString, ThisDelim, ThisItem)
-- ThisString -> String to look in
-- ThisDelim -> Text element that delimit the string
-- ThisItem -> Number of the element to return
copy the text item delimiters to OldDelims
set the text item delimiters to ThisDelim
set arrItem to every text item of ThisString
set the text item delimiters to OldDelims
if ThisItem ? 0 then
return (item ThisItem of arrItem) as text
else
return arrItem -- return every items
end if
end GetTExtItem

on FindReplace(FindWhat, ReplaceBy, ThisString)
copy the text item delimiters to OldDelims
set the text item delimiters to {FindWhat}
set TempList to every text item of ThisString
set the text item delimiters to {ReplaceBy}
set NewString to TempList as text
set the text item delimiters to OldDelims
return NewString
end FindReplace

on Get_Info(ImagePath)
tell application "Adobe Photoshop CS2"
open file ImagePath showing dialogs never
set ruler units of settings to point units
tell current document
set theHeight to height
set theWidth to width
set TheRez to resolution
set TheMode to mode
close saving no
end tell
end tell
{height:theHeight, Width:theWidth, Resolution:TheRez, Mode:TheMode}
end Get_Info
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5