7 Replies Latest reply: Sep 10, 2010 1:12 PM by Hiroto
Fist Level 1 Level 1 (0 points)
Why does my peace of script doesn't work as it should be?

Like it is now, the scale syntax doesn't understand the returned scalefactor. If I replace VWidthscale by {50} then indd scales the selected items to 25%.

This is a small peace of a bigger script, so normally "tell application ..." sentence isn't in.

-------------------------------------------
--Put in the scale factor
-------------------------------------------
set VWidthscale to (text returned of (display dialog "Scalefactor widt" default answer "100")) as string
set VHeightscale to (text returned of (display dialog "Scalefactor height" default answer "100")) as string
tell application "Adobe InDesign CS4"
select all
set horizontal scale of selection to VWidthscale
set vertical scale of selection to VHeightscale
select nothing
end tell

G5
  • Fist Level 1 Level 1 (0 points)
    I'll give you the whole script.

    Point of the script is to import a multiple pdf file, center it and scale every item on every page.
    It seems that the repeat function is doing the loop one time to meany

    -------------------------------------------
    --Choose a pdf file
    -------------------------------------------------------------------------------- -
    set VPDF to choose file with prompt "Choose pdf"
    -------------------------------------------------------------------------------- -
    --Give end size of pdf
    -------------------------------------------------------------------------------- -
    set Vdocwidth to (text returned of (display dialog "width." default answer "210")) as string
    set Vdocheight to (text returned of (display dialog "Heigth" default answer "297")) as string

    tell application "Adobe InDesign CS4"
    tell document preferences to set facing pages to false
    if (count documents) > 0 then
    set vDocument to active document
    set vStartPageName to my vDisplayDialog(vDocument)
    if vStartPageName is not equal to "" then
    set vStartPage to page vStartPageName of vDocument
    end if
    else
    set vDocument to make document
    tell document preferences of vDocument
    set page height to Vdocheight
    set page width to Vdocwidth
    end tell
    set vStartPage to page 1 of vDocument
    end if
    my vPlacePDF(vDocument, vStartPage, VPDF)
    end tell
    -------------------------------------------
    --Place pdf
    -------------------------------------------
    on vPlacePDF(vDocument, vPage, VPDF)
    tell application "Adobe InDesign CS4"
    set vDone to false
    set PDF crop of PDF place preferences to crop media
    set vCounter to 1
    repeat until vDone is true
    tell vDocument
    if vCounter > 1 then
    set vPage to make page at after vPage
    end if
    end tell
    set page number of PDF place preferences to vCounter
    get page number of PDF place preferences
    tell vPage
    set vPDFPage to place VPDF
    set vPDFPage to item 1 of vPDFPage
    end tell
    get properties of PDF attributes of vPDFPage
    if vCounter = 1 then
    set vFirstPage to page number of PDF attributes of vPDFPage
    else
    if page number of PDF attributes of vPDFPage = vFirstPage then
    tell vPage to delete
    set vDone to true
    end if
    end if
    -------------------------------------------
    --Put in the scale factor
    -------------------------------------------
    --set VWidthscale to (text returned of (display dialog "Scalefactor Width" default answer "100")) as string
    --set VHeightscale to (text returned of (display dialog "Scalefactor height" default answer "100")) as string
    set mydoc to active document
    tell mydoc
    select all
    set absolute horizontal scale of selection to 50
    set absolute vertical scale of selection to 50
    select nothing
    end tell
    ------------------
    --Center
    ------------------
    -- page size: top, left, bottom, right.
    set {b, a, d, c} to bounds of page 1 of document 1
    set mySelection to selection
    set mydoc to active document
    tell mydoc
    select all
    -- size of the item
    set {y1, x1, y2, x2} to geometric bounds of selection
    --center
    move selection to {(c - x2 + x1) / 2, (d - y2 + y1) / 2}
    select nothing
    end tell
    ------------------
    -- end Center
    ------------------

    set vCounter to vCounter + 1
    end repeat
    ------------------------------------------------------------------------------- --------
    -- end place pdf
    ------------------------------------------------------------------------------- --------
    display alert "finished!"
    end tell
    end vPlacePDF
    on vGetPageNames(vDocument)
    tell application "Adobe InDesign CS4"
    set vPageNames to {}
    repeat with vCounter from 1 to (count pages of vDocument)
    copy name of page vCounter of vDocument to end of vPageNames
    end repeat
    return vPageNames
    end tell
    end vGetPageNames
  • Fist Level 1 Level 1 (0 points)
    Is there anyone who can help me?
  • Hiroto Level 5 Level 5 (6,030 points)
    Hello

    You should take care of the class of values more attentively.

    Scale parameter likely expects real or integer value rather than string.
    So the code should have been :

    set VWidthscale to (text returned of (display dialog "Scalefactor Width" default answer "100")) as integer
    set VHeightscale to (text returned of (display dialog "Scalefactor height" default answer "100")) as integer

    The same should apply to the width and height :

    set Vdocwidth to (text returned of (display dialog "width." default answer "210")) as integer
    set Vdocheight to (text returned of (display dialog "Heigth" default answer "297")) as integer

    *Not tested, for I don't have IDCSn.

    Regards,
    H
  • Fist Level 1 Level 1 (0 points)
    Hello Hiroto,

    I've adjusted the script, but the problem isn't solved.

    The last page of my "placed, scaled and centered" pdf is double scaled.
    It looks like the --place pdf-- loop doesn't stop after the last page but redo this last page.

    Very strange and I do not see the problem or the answer.

    F
  • Colin @ mac.com Level 1 Level 1 (75 points)
    Hello Fist,

    Maybe you can try this:

    Just scale your pdf with acrobat.
    You Can print to pdf or several other ways to scale the pdf.

    and then import the pdf in Indesign with (built in) applescript :
    So just make a new indesign document with the your paper settings
    and then use :
    --PlaceMultipagePDF.applescript

    You get a multi page document in indesign with the paper settings you need.

    Greetings Colin
  • Fist Level 1 Level 1 (0 points)
    Hey Colin,

    --PlaceMultipagePDF.applescript is the part that is causing the trouble I have.

    If you open the script in an editor and run it, for instance with a 10 page pdf, you will see that Indesign makes 11 pages and removes the last one and places page 10 again.

    If you add any kind of functionality in the place pdf loop, the last page will be executed twice.

    That is why my scale script scales the last page in indesign twice.

    I hope this make sence for all who like a good scripting schallenge:-)

    Fist
  • Hiroto Level 5 Level 5 (6,030 points)
    Hello

    I downloaded sample scripts and looked into the PlaceMultipagePDF.applescript :
    indesigncs4_samplescripts.zip


    It seems that you have inserted some code into the myPlacePDF() handler and have not adjusted its flow control accordingly. (You need to break the loop promptly when the vDone is set to true)

    Try something like the codes below :

    --CODE1
    --Place pdf
    on vPlacePDF(vDocument, vPage, VPDF)
    tell application "Adobe InDesign CS4"
    set vDone to false
    set PDF crop of PDF place preferences to crop media
    set vCounter to 1
    repeat until vDone is true
    repeat 1 times -- # added

    tell vDocument
    if vCounter > 1 then
    set vPage to make page at after vPage
    end if
    end tell
    set page number of PDF place preferences to vCounter
    get page number of PDF place preferences
    tell vPage
    set vPDFPage to place VPDF
    set vPDFPage to item 1 of vPDFPage
    end tell

    get properties of PDF attributes of vPDFPage
    if vCounter = 1 then
    set vFirstPage to page number of PDF attributes of vPDFPage
    else
    if page number of PDF attributes of vPDFPage = vFirstPage then
    tell vPage to delete
    set vDone to true
    exit repeat -- # added (exit inner one time loop; skip the rest of this iteration of inner loop)
    end if
    end if

    --Put in the scale factor
    set mydoc to active document
    tell mydoc
    select all
    set absolute horizontal scale of selection to 50
    set absolute vertical scale of selection to 50
    select nothing
    end tell

    --Center
    -- page size: top, left, bottom, right.
    set {b, a, d, c} to bounds of page 1 of document 1
    set mySelection to selection
    set mydoc to active document
    tell mydoc
    select all

    -- size of the item
    set {y1, x1, y2, x2} to geometric bounds of selection

    --center
    move selection to {(c - x2 + x1) / 2, (d - y2 + y1) / 2}
    select nothing
    end tell
    -- end Center

    end repeat -- # added (end of inner one time loop)

    set vCounter to vCounter + 1
    end repeat
    -- end place pdf
    display alert "finished!"
    end tell
    end vPlacePDF
    --END OF CODE1

    Or more simply :

    --CODE2
    --Place pdf
    on vPlacePDF(vDocument, vPage, VPDF)
    tell application "Adobe InDesign CS4"
    set PDF crop of PDF place preferences to crop media
    set vCounter to 1

    --set vDone to false -- # commented out (not used)
    --repeat until vDone is true -- # replaced with the below
    repeat -- # modified

    tell vDocument
    if vCounter > 1 then
    set vPage to make page at after vPage
    end if
    end tell
    set page number of PDF place preferences to vCounter
    get page number of PDF place preferences
    tell vPage
    set vPDFPage to place VPDF
    set vPDFPage to item 1 of vPDFPage
    end tell

    get properties of PDF attributes of vPDFPage
    if vCounter = 1 then
    set vFirstPage to page number of PDF attributes of vPDFPage
    else
    if page number of PDF attributes of vPDFPage = vFirstPage then
    tell vPage to delete
    --set vDone to true - # commented out (not used)
    exit repeat -- # added
    end if
    end if

    --Put in the scale factor
    set mydoc to active document
    tell mydoc
    select all
    set absolute horizontal scale of selection to 50
    set absolute vertical scale of selection to 50
    select nothing
    end tell

    --Center
    -- page size: top, left, bottom, right.
    set {b, a, d, c} to bounds of page 1 of document 1
    set mySelection to selection
    set mydoc to active document
    tell mydoc
    select all

    -- size of the item
    set {y1, x1, y2, x2} to geometric bounds of selection

    --center
    move selection to {(c - x2 + x1) / 2, (d - y2 + y1) / 2}
    select nothing
    end tell
    -- end Center

    set vCounter to vCounter + 1
    end repeat
    -- end place pdf
    display alert "finished!"
    end tell
    end vPlacePDF
    --END OF CODE2


    Hope this may help,
    H

    Message was edited by: Hiroto (oops, fixed a typo in the first code)