Re: sorting based on X, Y coordinates as opposed to creation sequence
Re: sorting based on X, Y coordinates as opposed to creation sequence
- Subject: Re: sorting based on X, Y coordinates as opposed to creation sequence
- From: has <email@hidden>
- Date: Thu, 6 Oct 2005 14:19:42 +0100
Patrik B. wrote:
>I am trying to put together a script that orders all my text frames/page
>items based on their x, y coordinates as opposed to their creation time.
>Indesign CS and CS2 basically indexes all items based on when they were
>placed/made. [...] any ideas on how I would approach the problem?
Using AppleMods' List library <http://applemods.sourceforge.net/mods/Data/List.php>, something like:
property _Loader : run application "LoaderServer"
----------------------------------------------------------------------
-- DEPENDENCIES
property _List : missing value
on __load__(loader)
set _List to loader's loadLib("List")
end __load__
----------------------------------------------------------------------
__load__(_Loader's makeLoader())
-- get lists of frame refs and their positions (pseudo-code)
tell app "InDesign"
tell document
set frameCoords to position of every frame
set frameRefs to every frame
end tell
end tell
-- callbacks used by powerSort() command to get the values to sort on
script SortByYCoord
prop reverseSort : false
on eval({coords, ref})
return coords's item 2 -- (should be index of Y coordinate)
end eval
end script
script SortByXCoord
prop reverseSort : false
on eval({coords, ref})
return coords's item 1 -- (should be index of X coordinate)
end eval
end script
-- sort references according to Y and X coordinates (uses 'Schwartzian transform')
set lst to _List's recomposeList({frameCoords, frameRefs})
set lst to _List's powerSort(lst, {SortByYPos, SortByXPos}, 0)
return item 2 of _List's recomposeList(lst)
Don't have a copy of ID to hand so that bit of code'll need work, and can't mind if ID uses XY or YX ordering in coordinates so you might need to fix the indexes for that too, but you should get the general idea.
If you've not used AppleMods' libraries before, you'll need to download and install AppleMods' Loader system first <http://applemods.sourceforge.net/getstarted.html>. Run the Loader installer, then download the List library and add it to the ASLibraries folder. You can use the LoaderWizard applet to generate the library loading code to paste at the top of your script.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden