Hi,
i was looking to automate the layout of fraction with a script.
The script has to change 1/200, 1/20, 1/33 to fractions:
When we do it manually, we insert an anchored textframe which contains a 2 row/1 column table.
We then copy the numbers in the cells.
I found the script below in a previous discussion.
But i get an error 30480 on line 14.
I'm a bit of a dummy when it comes to scripting, so can anyone tell me what's wrong with it?
-------------------
var theDoc = app.activeDocument;
var myTableStyle = "tabelbreuk"; //MUST be set!!
var myCellStyle = "celbreuk"//MUST be set!!
var myObjectStyle = "TF-breuk"//MUST be set!!
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\d+/\\d+"; //should find all occurrences of number(s) + / + numbers(s)
var searchResults = theDoc.findGrep();
for(var i = searchResults.length -1; i >= 0; i--)
{
var foundFraction = searchResults[i];
var newTextFrame = foundFraction.insertionPoints[0].textFrames.add({geometricBounds: [0,0,foundFraction.leading, foundFraction.parentTextFrames[0].geometricBounds[3] - foundFraction.parentTextFrames[0].geometricBounds[1]], appliedObjectStyle:theDoc.objectStyles.itemByName(myObjectStyle)});
var tmpDest = foundFraction.move(LocationOptions.AT_BEGINNING, newTextFrame);
var fractionTable= tmpDest.convertToTable('\r', '/', 1);
fractionTable.appliedTableStyle = "tabelbreuk"
setTableWidth(fractionTable);
newTextFrame.fit(FitOptions.FRAME_TO_CONTENT);
}
function setTableWidth(fractionTable){
var widthArray = [];
var allCells = fractionTable.cells;
for(var c = 0; c < fractionTable.cells.length; c++){
var aCell = fractionTable.cells[c];
aCell.appliedCellStyle = "celbreuk"
widthArray.push((aCell.texts[0].endHorizontalOffset - aCell.texts[0].horizontalOffset) + aCell.leftInset + aCell.rightInset)
}
widthArray.sort(Numsort);
fractionTable.width = widthArray[widthArray.length-1]
}
function Numsort(a,b){return a - b}
--------------------------------
thx