//Columns2Frames.jsx /* This InDesign CS3 script can be used for replacing textframe columns with individual textframes. Select a textframe first, then run the script. */ // Use the findPage function to get the page the textframe is on function findPage(theObj) { var thePage = theObj; if (thePage.hasOwnProperty("baseline")) { thePage = thePage.parentTextFrames[0]; } while (thePage.constructor.name != "Page") { var whatIsIt = thePage.constructor.name; switch (whatIsIt) { case "Story" : thePage = thePage.textFrames[-1].parent; break; case "Character" : thePage = thePage.parentTextFrames[0]; break; case "Cell" : try { thePage = thePage.insertionPoints[0].parentTextFrames[0]; break; } catch (e) { // must be overset, so ignore return null; } case "Application" : // must be off page, so ignore return null; } thePage = thePage.parent; } return thePage } if (app.selection.length != 1 || app.selection[0] != "[object TextFrame]") { alert("To run this script please select a textframe first."); } else { //Get properties of textframe var myDocument = app.activeDocument; var myTextFrame = app.selection[0]; var myTextFramePrev = myTextFrame.previousTextFrame; var myTextFrameNext = myTextFrame.nextTextFrame; var myColAmount = myTextFrame.textFramePreferences.textColumnCount; var myMultipleCols = myColAmount - 1; //The cols. after the first one var myTextFrameBounds = myTextFrame.geometricBounds; var myGutterWidth = myTextFrame.textFramePreferences.textColumnGutter; var myColWidth = ( (myTextFrameBounds[3] - myTextFrameBounds[1]) - (myGutterWidth * myMultipleCols) ) / myColAmount; var myGutterAmount = myTextFrame.textFramePreferences.textColumnCount; //Find the first textFrame in the thread that myTextFrame is in, get it's contents myFirstTextFrame = myTextFrame; while (myFirstTextFrame.previousTextFrame == "[object TextFrame]") { myFirstTextFrame = myFirstTextFrame.previousTextFrame; } var myContents = myFirstTextFrame.contents; //Find the page to work on var myPage = findPage(myTextFrame); // Create individual textframes if the original has more than one column if (myColAmount > 1) { myTextFrame.label = "marked"; // Mark original textframe for removal var myNewFrames = new Array(); //Create textframe for col. 1 myNewFrames[0] = myPage.textFrames.add(); myBounds = new Array(); myBounds[0] =myTextFrameBounds[0]; myBounds[1] = myTextFrameBounds[1]; myBounds[2] = myTextFrameBounds[2]; myBounds[3] = (myTextFrameBounds[1] +myColWidth); myNewFrames[0].geometricBounds = myBounds; myNewFrames[0].label = "0"; //Create textframes for col. 2 -> end for (i = 1; i <= myMultipleCols; i ++) { myNewFrames[i] = myPage.textFrames.add(); myBounds[1] = myBounds[3] + myGutterWidth; myBounds[3] = (myBounds[1] +myColWidth); myNewFrames[i].geometricBounds = myBounds; myNewFrames[i].label = (i + "") ; } //Link the new frames for (i =myMultipleCols; i > 0; i --) { j = i - 1; myNewFrames[i].previousTextFrame = myNewFrames[j]; } // If the texframe was part of a thread, relink the new frame to the thread if (myTextFramePrev != null) // If there was a frame before { myNewFrames[0].previousTextFrame = myTextFramePrev; } //If there was no frame before, but a frame after if (myTextFrameNext != null && myTextFramePrev == null) { myNewFrames[myMultipleCols].nextTextFrame = myTextFrameNext; } // if there are no frames before or after if (myTextFramePrev == null && myTextFrameNext == null) { myDocument.textFrames.itemByName("marked").nextTextFrame = myNewFrames[0]; } //Remove original textFrame myDocument.textFrames.itemByName("marked").remove(); } }