Canvas 8 Place an image problem
Canvas 8 Place an image problem
- Subject: Canvas 8 Place an image problem
- From: Jeremy Sellors <email@hidden>
- Date: Sun, 5 Jan 2003 07:42:12 -0800
The following script which was included with Canvas 8 but does not
place the image at the line beginning with the inserted ****
I am using Mac OS X 10.2.3. The applescript editor is 1.9.1 I am don't
know how to get the Applescript version.
The Canvas 8 dictionary shows the command parameters as
"place: Place file into document
place string -- File name
into reference -- document reference to place file
[at position point] -- position in document as point {x,y}
[with options current position/additional layer/additional page] --
Placement option
[Result: reference] -- Object that represents the placed file. "
any comment/help would be appreciated
The script makes a catalog of a folder of images
--start script
tell application "Finder"
activate --get the folder with images to be displayed
set imageFolder to choose folder with prompt "Select image folder:"
set imageFiles to every file in folder imageFolder --create file list
set totalImages to count items in imageFiles -- total number of files
in folder
set folderString to folder of item 1 of imageFiles as string
--set folderString to name of item 2 of imageFiles
end tell
---------------------some default settings ---------------------
set myMargin to 25 -- page margins (top, bottom, left, right)
set myOffset to 20 -- offset between rows
set numberOfColumns to 2 -- number of columns
set numberOfRows to 4 -- number of rows
set totalPages to totalImages / (numberOfColumns * numberOfRows) + 0.5
--round it up
set totalPages to totalPages div 1 --make an integer
set needFooter to false
set defaultBounds to {0, 0, 10, 10}
-----------------------------------------------------------
tell application "Canvasb" 8"
activate
set myDoc to make new document with properties {document
type:illustration}
set theWidth to (width of myDoc) - (2 * myMargin + myOffset)
set theHeight to (height of myDoc) - (2 * myMargin + (numberOfRows -
1) * myOffset)
set thePage to 1
set indexColm to 0
set indexRow to 0
set boxWidth to theWidth / numberOfColumns
set boxHeight to theHeight / numberOfRows
repeat with theItem from 1 to totalImages
tell application "Finder"
set theFile to item theItem of imageFiles as string --get next file
end tell
****set theImage to place theFile into myDoc at position {0, 0}
--place image into main document
set visible of theImage to false --don't display until scale/move is
done!
set theRect to geometric bounds of theImage
set imgWidth to (item 3 of theRect) - (item 1 of theRect) --calc
image dimension
set imgHeight to (item 4 of theRect) - (item 2 of theRect)
--calc scale factor (not expanding)
set scaleFactor to CalcScaleFactor(imgWidth, imgHeight, boxWidth,
boxHeight - myOffset) of me
if (scaleFactor b 1.0) then
scale theImage given B+class horZB;:scaleFactor, B+class
verTB;:scaleFactor
end if
set theRect to geometric bounds of theImage --get the new dimensions
set imgWidth to (item 3 of theRect) - (item 1 of theRect)
set imgHeight to (item 4 of theRect) - (item 2 of theRect)
-- allign the image to the middle of the column/row (NOTE: calculate
it relative to current object position)
set xMove to myMargin + boxWidth / 2 - imgWidth / 2 - (item 1 of
theRect) + indexColm * boxWidth
set yMove to myMargin + boxHeight / 2 - imgHeight / 2 - (item 2 of
theRect) + indexRow * boxHeight
move theImage by {xMove, yMove}
tell application "Finder" --get name and date of image
set nameString to name of item theItem of imageFiles as string
set theDate to creation date of item theItem of imageFiles
set creatingString to theDate as string
end tell
--create text object above image (lower position)
set dateObject to make new text with properties B,
{geometric bounds:defaultBounds, text type:caption,
contents:creatingString, visible:false, font:"Arial", size:4}
set nameObject to make new text with properties B,
{geometric bounds:defaultBounds, text type:caption,
contents:nameString, visible:false, font:"Arial", size:4}
--get the current bounding box of the text objects
set theRect to geometric bounds of nameObject --allign the name to
left
--set objWidth to (item 3 of theRect) - (item 1 of theRect)
--set objHeight to (item 4 of theRect) - (item 2 of theRect)
set theImageRect to geometric bounds of theImage --the image bouding
box as a reference
set xPos to (item 1 of theImageRect)
set yPos to (item 4 of theImageRect) + 5
move nameObject(xPos, yPos)
set theRect to geometric bounds of dateObject --allign the date to
right
set xPos to (item 3 of theImageRect) - ((item 3 of theRect) - (item 1
of theRect))
move dateObject(xPos, yPos)
--make the objects visible
set visible of theImage to true
set visible of nameObject to true
set visible of dateObject to true
set needFooter to true --reset footer flag
--calc next image box
if (indexColm < (numberOfColumns - 1)) then
set indexColm to indexColm + 1
else
set indexColm to 0
if (indexRow < (numberOfRows - 1)) then
set indexRow to indexRow + 1
else
--make footer text
PageLabels(theWidth, theHeight, thePage, totalPages,
numberOfColumns, numberOfRows, myMargin, folderString, totalImages) of
me
set needFooter to false
--new page
set myDoc to active document
set curPage to active page of myDoc
make new page at after curPage
set thePage to thePage + 1
set indexRow to 0
end if
end if
end repeat
if (needFooter) then
PageLabels(theWidth, theHeight, thePage, totalPages, numberOfColumns,
numberOfRows, myMargin, folderString, totalImages) of me
end if
end tell
on PageLabels(theWidth, theHeight, thePage, totalPages,
numberOfColumns, numberOfRows, myMargin, folderString, totalImages)
--handle text objects for footer/header
tell application "Canvasb" 8"
activate
--page text
set pageStr to "Page " & thePage & "/" & totalPages
set pageNumObject to make new text with properties B,
{geometric bounds:{0, 5, 11, 11}, text type:caption,
contents:pageStr, visible:false, font:"Arial", size:9}
set xPos to theWidth - (width of pageNumObject)
set yPos to (theHeight + 2 * myMargin) - (height of pageNumObject) - 3
move pageNumObject(xPos, yPos)
set footerYPos to yPos
set visible of pageNumObject to true
--folder text (this folder of the images should be the name of the
storage media)
set startIndex to (numberOfColumns * numberOfRows) * (thePage - 1)
set endIndex to startIndex + (numberOfColumns * numberOfRows)
if (endIndex > totalImages) then
set endIndex to totalImages
end if
set folderString to folderString & "(" & (1 + startIndex) & " - " &
endIndex & ")"
set folderNameObject to make new text with properties B,
{geometric bounds:{0, 5, 11, 11}, text type:caption,
contents:"Catalog Index of B;" & folderString & "B+", visible:false,
font:"Arial", size:12}
set xPos to theWidth / 2 - (width of folderNameObject) / 2 + myMargin
set yPos to 5
move folderNameObject(xPos, yPos)
set visible of folderNameObject to true
--name text (user name of CNV application)
set theNameString to user name of properties
set theNameObject to make new text with properties B,
{geometric bounds:{0, 5, 11, 11}, text type:caption,
contents:theNameString, visible:false, font:"Arial", size:9}
move theNameObject(myMargin, footerYPos)
set visible of theNameObject to true
end tell
end PageLabels
on CalcScaleFactor(imgWidth, imgHeight, theWidth, theHeight) --function
to calculate the best scaling factor
set scaleFactor to 1.0 --default factor
if (imgWidth > theWidth) then --just check if the image is wider than
the fitting box
set scaleFactor to theWidth / imgWidth
end if
set imgHeight to imgHeight * scaleFactor
if (imgHeight > theHeight) then
set scaleFactor to scaleFactor * (theHeight / imgHeight)
end if
return scaleFactor
end CalcScaleFactor
--end script
__jeremy
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.