Question
[AS][CS3] mathtype replace script
Hi, I edited the mathtype importscript to work better with the selection method.
In CS2 it was working fine, in CS3 not any more of course after I converted my document to the new version and wanted to replace the tect to inline graphics.
Problem is off course the find function, it gives an error on «event K2 Find»
I have read some topics but need some help on what I should alter, of course «event K2 Find» but is this the only line or should it be completely rewritten?
Here is the script:
Deleted some intro info or it's too long.
-- get the source folder for the equations from the user and compile a list of the enclosed files
set the sourceFolder to choose folder with prompt "Select the directory containing the equations:"
set the fileList to list folder sourceFolder without invisibles
-- step through each file in the list, search for a matching name tag in the active document, and
-- replace with the file and move the baseline of the placed equation
repeat with i from 1 to the number of items in the fileList
set currentItem to item i of the fileList
set currentFilePath to ((sourceFolder as string) & currentItem)
-- test if the filename is not a folder and then place it
if (info for (currentFilePath as alias)) is not folder then
set searchstring to "<<" & currentItem & ">>"
place_file(searchstring, currentFilePath, get_baseline(currentFilePath as alias))
end if
end repeat
display dialog "Finished placing files from the folder " & (sourceFolder as string) & "."
(************************************************************
* place_file():
************************************************************)
on place_file(fileName, filePath, fileBaseline)
tell application "Adobe InDesign CS3"
-- test that a document is open
if (count documents) > 0 then
set myDocument to active document
tell myDocument
-- search for all references of the filename
b «event K2 Find» story given «class for »:fileName
set hitz to the result
set lapz to the number of items of hitz
if lapz > 0 then
-- repeat for each reference to the file
repeat until lapz = 0
select item lapz of hitz
-- get a reference to the selected text
set myInsertionPoint to item lapz of hitz
set myRef to myInsertionPoint
tell item 1 of myRef
set myInsertion to index of first character
set myInsertion2 to index of second character
set myStory to parent of first character
-- delete the string at the reference point
set contents to ""
end tell
-- place the file at the insertion point
tell (insertion point myInsertion of myStory)
place filePath
end tell
-- select the inline graphic
select text from insertion point myInsertion to insertion point myInsertion2 of myStory
set graphicLocation to object reference of selection
set myGraphic to item 1 of all graphics of item 1 of graphicLocation
set mySelection to parent of myGraphic
-- move the graphic equivalent to the baseline for that inline graphic
move mySelection by {"0pt", fileBaseline}
set lapz to (lapz - 1)
end repeat
end if
end tell
end if
end tell
end place_file
(********** get_baseline():***************)
on get_baseline(myFile)
set matchText to "%%Baseline: "
set theBaseline to ""
-- read in the EPS file
open for access myFile
set fileLines to read myFile as string using delimiter {return}
close access myFile
-- find the line with the baseline
set lapz to the number of items in fileLines
repeat until (lapz = 0) or theBaseline begins with the matchText
set theBaseline to item lapz of fileLines
set lapz to (lapz - 1)
end repeat
-- extract the baseline number
set theBaseline to characters -2 thru -1 of theBaseline as string
-- return the baseline number
return theBaseline & "pt" as string
end get_baseline
In CS2 it was working fine, in CS3 not any more of course after I converted my document to the new version and wanted to replace the tect to inline graphics.
Problem is off course the find function, it gives an error on «event K2 Find»
I have read some topics but need some help on what I should alter, of course «event K2 Find» but is this the only line or should it be completely rewritten?
Here is the script:
Deleted some intro info or it's too long.
-- get the source folder for the equations from the user and compile a list of the enclosed files
set the sourceFolder to choose folder with prompt "Select the directory containing the equations:"
set the fileList to list folder sourceFolder without invisibles
-- step through each file in the list, search for a matching name tag in the active document, and
-- replace with the file and move the baseline of the placed equation
repeat with i from 1 to the number of items in the fileList
set currentItem to item i of the fileList
set currentFilePath to ((sourceFolder as string) & currentItem)
-- test if the filename is not a folder and then place it
if (info for (currentFilePath as alias)) is not folder then
set searchstring to "<<" & currentItem & ">>"
place_file(searchstring, currentFilePath, get_baseline(currentFilePath as alias))
end if
end repeat
display dialog "Finished placing files from the folder " & (sourceFolder as string) & "."
(************************************************************
* place_file():
************************************************************)
on place_file(fileName, filePath, fileBaseline)
tell application "Adobe InDesign CS3"
-- test that a document is open
if (count documents) > 0 then
set myDocument to active document
tell myDocument
-- search for all references of the filename
b «event K2 Find» story given «class for »:fileName
set hitz to the result
set lapz to the number of items of hitz
if lapz > 0 then
-- repeat for each reference to the file
repeat until lapz = 0
select item lapz of hitz
-- get a reference to the selected text
set myInsertionPoint to item lapz of hitz
set myRef to myInsertionPoint
tell item 1 of myRef
set myInsertion to index of first character
set myInsertion2 to index of second character
set myStory to parent of first character
-- delete the string at the reference point
set contents to ""
end tell
-- place the file at the insertion point
tell (insertion point myInsertion of myStory)
place filePath
end tell
-- select the inline graphic
select text from insertion point myInsertion to insertion point myInsertion2 of myStory
set graphicLocation to object reference of selection
set myGraphic to item 1 of all graphics of item 1 of graphicLocation
set mySelection to parent of myGraphic
-- move the graphic equivalent to the baseline for that inline graphic
move mySelection by {"0pt", fileBaseline}
set lapz to (lapz - 1)
end repeat
end if
end tell
end if
end tell
end place_file
(********** get_baseline():***************)
on get_baseline(myFile)
set matchText to "%%Baseline: "
set theBaseline to ""
-- read in the EPS file
open for access myFile
set fileLines to read myFile as string using delimiter {return}
close access myFile
-- find the line with the baseline
set lapz to the number of items in fileLines
repeat until (lapz = 0) or theBaseline begins with the matchText
set theBaseline to item lapz of fileLines
set lapz to (lapz - 1)
end repeat
-- extract the baseline number
set theBaseline to characters -2 thru -1 of theBaseline as string
-- return the baseline number
return theBaseline & "pt" as string
end get_baseline