• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: INDESIGN: Problem Passing Doc Through Handlers of Called Script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: INDESIGN: Problem Passing Doc Through Handlers of Called Script


  • Subject: RE: INDESIGN: Problem Passing Doc Through Handlers of Called Script
  • From: Rick Gordon <email@hidden>
  • Date: Thu, 15 Sep 2011 21:51:43 -0700

Title: RE: INDESIGN: Problem Passing Doc Through Handlers of Call
Still bumping up against the same error. I changed:

        my fProcess(it, vHandler) --it being the object reference of the doc
...to...
        my fProcess(id, vHandler)

...with the handlers in the workhorse script doing:
        on fDocSetup(aDocID)
          tell application "Adobe InDesign CS5"
            return "GOT HERE"
            set vDoc to object reference of document id aDocID
            tell vDoc
       ...

...but still no joy. Same error: "Can't make document id 912 of application \"Adobe InDesign CS5\" into the expected type." Can't even get to return "GOT HERE"

On a backwards note, I find one more typo fix of the original, but still doesn't seem to make it work.

on fDocSetup(aDoc)
  tell application "Adobe InDesign CS5"
    tell vDoc  --SHOULD HAVE BEEN aDoc, but we're into ID land now...

What am I missing?

Thanks again.
Rick

------------------

On 9/15/11 at 8:49 PM -0700, Rick Gordon wrote in a message entitled
"Re: INDESIGN: Problem Passing Doc Through Handlers of Calle":

There are a couple other glitches I forgot to clean up before sending. Documents requiring attention should be opened visibly into a window for human processing. And I've run into some instances where an anchored image reports errors where there are none -- a case of not handling content offset appropriately, I think.

Rick Gordon

------------------

On 9/15/11 at 8:37 PM -0700, Rick Gordon wrote in a message entitled
"INDESIGN: Problem Passing Doc Through Handlers of Called Sc":

>I've got a script that is designed to loop through selected chapters of an .INDB book file to hunt down images that don't fill their container on all four sides.
>
>It's divided into two script documents (which need to be in the same folder): the workhorse that processes one document via multiple handlers, and the other that travels through the chosen book documents, leaving documents requiring action open, closing the others, and providing a list on images needing adjustment.
>
>The workhorse document works fine when directly run on a single document. The book traversing document successfully calls the main handler (fMain) of the workhorse doc ("Find Images Smaller Than Frame.scpt").
>
>The problem happens when the workhorse doc, when called by the book traversing doc, calls additional handlers in the same script document. When fMain passes the reference to the current document to successive handlers, I get the error "Can't make document id <IDNUMBER> of application \"Adobe InDesign CS5\" into the expected type."
>
>I've tried passing the document reference as it, object reference of it, a ref to it (then trying to access its contents or it directly), and passing it through a property -- always with the same error.
>What am I doing wrong here? Thanks for any help.
>
>I'll include both script components below:
>
>--THE WORKHORSE SCRIPT (Works when run independently)--
>--Must reside in same folder as the calling script
>
>--Uncomment to run directly on front document
>(*
>tell application "Adobe InDesign CS5"
>  my fMain(document 1)
>end tell
>*)
>--------
>on fMain(aDoc)
>  set vList to {}
>  tell application "Adobe InDesign CS5"
>    set vApp to it
>    set vOldUserInteractionLevel to my fAppSetup()
>    tell aDoc
>      set vOriginalRulerOrigin to my fDocSetup(it)
>      try
>        set end of vList to return & return & name & return
>        set vContainerList to all graphics
>        repeat with vItem in vContainerList
>          set vComparedBounds to my fCompareBounds(parent of vItem)
>          set end of vList to vComparedBounds
>          if vComparedBounds = -1 then my vDocCleanup(it)
>        end repeat
>      on error
>        my fDocCleanup(it, vOriginalRulerOrigin)
>        my fAppCleanup(vOldUserInteractionLevel)
>      end try
>      my fDocCleanup(it, vOriginalRulerOrigin)
>    end tell
>    my fAppCleanup(vOldUserInteractionLevel)
>    return vList
>  end tell
>end fMain
>--
>on fAppSetup()
>  tell application "Adobe InDesign CS5"
>    set rUserInteractionLevel to a reference to user interaction level of script preferences
>    set vOldUserInteractionLevel to rUserInteractionLevel
>    set rUserInteractionLevel to never interact
>    return vOldUserInteractionLevel
>  end tell
>end fAppSetup
>--
>on fDocSetup(aDoc)
>  tell application "Adobe InDesign CS5"
>    tell vDoc
>      set rRulerOrigin to a reference to ruler origin of view preferences
>      set vOriginalRulerOrigin to ruler origin of view preferences
>      set contents of rRulerOrigin to spread origin
>    end tell
>  end tell
>end fDocSetup
>--
>on fCompareBounds(aContainer)
>  set vList to {}
>  set vFoundError to false
>  try
>    tell application "Adobe InDesign CS5"
>      tell aContainer
>        set vStrokeAlignment to stroke alignment
>        set vStrokeWeight to stroke weight
>        if vStrokeAlignment is outside alignment then
>          set vStrokeAdjustment to 0
>        else if vStrokeAlignment is center alignment then
>          set vStrokeAdjustment to vStrokeWeight / 2
>        else
>          set vStrokeAdjustment to vStrokeWeight --inside alignment
>        end if
>        set vImage to image 1
>        set vImageName to name of item link of vImage
>        repeat with i from 1 to 4
>          tell item i of geometric bounds
>            set vImageBound to item i of geometric bounds of vImage
>            set vOffset to it - vImageBound
>            if i = 1 then
>              set vTopOffset to vOffset + vStrokeAdjustment
>              set vTopOk to (vTopOffset " 0)
>            else if i = 2 then
>              set vLeftOffset to vOffset + vStrokeAdjustment
>              set vLeftOk to (vLeftOffset " 0)
>            else if i = 3 then
>              set vBottomOffset to vOffset - vStrokeAdjustment
>              set vBottomOk to (vBottomOffset 3Î4 0)
>            else if i = 4 then
>              set vRightOffset to vOffset - vStrokeAdjustment
>              set vRightOk to (vRightOffset 3Î4 0)
>            end if
>          end tell
>        end repeat
>      
>        if (vTopOk and vLeftOk and vBottomOk and vRightOk) is false then
>          set vFoundError to true
>          if label does not contain "FIXBOUNDS" then
>            if label is "" then
>              set label to "FIXBOUNDS"
>            else
>              set label to "FIXBOUNDS" & label & return
>            end if
>          end if
>          select
>          set vParentPage to parent page
>          set end of vList to (return as text) & "  page " & (name of vParentPage) & ": " & ¬
>            vImageName & return
>          if vTopOk is false then set end of vList to "  top: " & vTopOffset & return
>          if vLeftOk is false then set end of vList to "   left: " & vLeftOffset & return
>          if vBottomOk is false then set end of vList to "   bottom: " & vBottomOffset & return
>          if vRightOk is false then set end of vList to "   right: " & vRightOffset & return
>        end if
>      end tell
>    end tell
>  on error
>    return vList
>    error -1
>  end try
>  if vFoundError then
>    return vList
>  else
>    return {}
>  end if
>end fCompareBounds
>--
>on fDocCleanup(aDoc, aOriginalRulerOrigin)
>  tell application "Adobe InDesign CS5"
>    set ruler origin of view preferences of aDoc to aOriginalRulerOrigin
>  end tell
>end fDocCleanup
>--
>on fAppCleanup(aOldUserInteractionLevel)
>  tell application "Adobe InDesign CS5"
>    set user interaction level of script preferences to aOldUserInteractionLevel
>  end tell
>end fAppCleanup
>
>-------------------
>--THE BOOK TRAVERSING SCRIPT--
>--(fMain is successfully called, but InDesign objects fail when passed to other handlers)--
>--Must reside in same folder as the called script
>
>set vList to {}
>--
>try
>  set vScriptName to "Find Images Smaller Than Frame.scpt"
>  set vScript to my fLoadScript(vScriptName)
>  set vHandler to vScript's fMain
>on error
>  error "Can't load a script."
>end try
>--
>tell application "Adobe InDesign CS5"
>  set vApp to it
>  set vOldUserInteractionLevel to my fAppSetup()
>  set vTargetList to my fChooseChapters(active book)
>  if vTargetList is {} then error "Nothing was chosen."
>  repeat with vItem in vTargetList
>    set vChapterAlias to full name of vItem
>    set vCurrentDoc to open vChapterAlias without showing window
>    tell vCurrentDoc
>      set vProcessResult to my fProcess(it, vHandler)
>      set end of vList to vProcessResult
>      if vProcessResult is not {} then
>        set end of last item of vList to my fPostprocess(it)
>      else
>        set end of last item of vList to my fPostprocessFail(it)
>      end if
>    end tell
>  end repeat
>  my fAppCleanup(vOldUserInteractionLevel)
>  return vList as text
>end tell
>
>--
>on fAppSetup()
>  tell application "Adobe InDesign CS5"
>    set rUserInteractionLevel to a reference to user interaction level of script preferences
>    set vOldUserInteractionLevel to rUserInteractionLevel
>    set rUserInteractionLevel to never interact
>    return vOldUserInteractionLevel
>  end tell
>end fAppSetup
>--
>on fChooseChapters(aBook)
>  tell application "Adobe InDesign CS5"
>    set vContents to a reference to book contents of aBook
>    set vContentsList to name of vContents
>    tell me to set vReturnedNames to (choose from list vContentsList with title "Open Selected Chapters" default items vContentsList with multiple selections allowed without empty selection allowed)
>    set vChapterList to items of vContents where name is in (vReturnedNames as text)
>    return vChapterList
>  end tell
>end fChooseChapters
>--
>on fLoadScript(aScriptName)
>  --assumes this script and the script containing the handler are in the same folder
>  set vScriptPath to path to me
>  tell application "Finder"
>    set vScriptFolder to (container of vScriptPath) as alias as text
>  end tell
>  set vScriptPath to (vScriptFolder & aScriptName) as alias
>  return load script vScriptPath
>end fLoadScript
>--
>on fProcess(aDoc, aHandler)
>  script sPassHandler
>    property pHandler : aHandler
>    return pHandler(aDoc)
>  end script
>  run sPassHandler
>end fProcess
>--
>on fPostprocess(aDoc)
>  try
>    tell aDoc
>      --save
>      close
>    end tell
>    return true
>  on error
>    return false
>  end try
>end fPostprocess
>--
>on fPostprocessFail(aDoc)
>  tell aDoc
>    --close without saving
>  end tell
>  return -1
>end fPostprocessFail
>--
>on fAppCleanup(aOldUserInteractionLevel)
>  tell application "Adobe InDesign CS5"
>    set user interaction level of script preferences to aOldUserInteractionLevel
>  end tell
>end fAppCleanup
>
>--
>___________________________________________________
>
>RICK GORDON
>EMERALD VALLEY GRAPHICS AND CONSULTING
>___________________________________________________
>
>WWW:   http://www.shelterpub.com
>
>
>------------------------------------
>
>Yahoo! Groups Links
>
>
>

--
___________________________________________________

RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________

WWW:   http://www.shelterpub.com


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/applescriptingindesign/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/applescriptingindesign/join
    (Yahoo! ID required)

<*> To change settings via email:
    email@hidden
    email@hidden

<*> To unsubscribe from this group, send an email to:
    email@hidden

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


--
___________________________________________________

RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________

WWW:   http://www.shelterpub.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: INDESIGN: Problem Passing Doc Through Handlers of Called Script
      • From: Shane Stanley <email@hidden>
References: 
 >INDESIGN: Problem Passing Doc Through Handlers of Called Script (From: Rick Gordon <email@hidden>)
 >RE: INDESIGN: Problem Passing Doc Through Handlers of Called Script (From: Rick Gordon <email@hidden>)

  • Prev by Date: Re: INDESIGN: Problem Passing Doc Through Handlers of Called Script
  • Next by Date: Re: INDESIGN: Problem Passing Doc Through Handlers of Called Script
  • Previous by thread: RE: INDESIGN: Problem Passing Doc Through Handlers of Called Script
  • Next by thread: Re: INDESIGN: Problem Passing Doc Through Handlers of Called Script
  • Index(es):
    • Date
    • Thread