Skip to content

Instantly share code, notes, and snippets.

View grefel's full-sized avatar

Gregor Fellenz grefel

View GitHub Profile
@grefel
grefel / getTypeArea
Last active August 29, 2015 14:03
Get type area from page #indesign #js
function getTypeArea(page) {
typeArea = {};
typeArea.y1 = page.marginPreferences.top;
typeArea.x1 = page.side == PageSideOptions.LEFT_HAND ? page.marginPreferences.right : page.marginPreferences.left;
typeArea.y2 = page.bounds[2] - page.marginPreferences.bottom;
typeArea.x2 = page.side == PageSideOptions.LEFT_HAND ? page.bounds[3] - page.marginPreferences.left : page.bounds[3] - page.marginPreferences.right;
typeArea.geometricBounds = [typeArea.y1, typeArea.x1, typeArea.y2, typeArea.x2]
typeArea.height = typeArea.y2 - typeArea.y1;
typeArea.width = typeArea.x2 - typeArea.x1;
@grefel
grefel / getNexPage.js
Last active July 21, 2016 09:59
Get next Page #InDesign #JS
function getNextPage(page) {
var dok = page.parent.parent;
var nextPage = dok.pages[page.documentOffset+1];
if (!nextPage.isValid) {
nextPage = dok.pages.add();
nextPage.appliedMaster = page.appliedMaster;
}
return nextPage;
}
@grefel
grefel / gist:d2245fdc4d094a6be643
Last active August 29, 2015 14:03
Point to Millimeter conversion for #InDesign calculation
function pt2mm(numberInPt) {
return ( numberInPt * 25.4 ) / 72;
}
function mm2pt(numberInMm) {
return ( numberInMm * 72 ) / 25.4;
}
@grefel
grefel / gist:26fef91ce1f00318693c
Created July 12, 2014 12:03
InDesign CS Whitespace Handling via Processing Instruction (Does not help :-( )
<?xml version="1.0" encoding="UTF-8"?>
<?whitespace-handling use-tags?>
<test xmlns:aid3="http://ns.adobe.com/AdobeInDesign/3.0/">
<p>Test Tab:<aid3:tab/>End of Paragraph here:<aid3:br/>End</p>
</test>
@grefel
grefel / gist:979d7f612e261f687ff1
Last active August 29, 2015 14:05
Escaping JSON String from ExtendScript toSource()
var myObject = {text:"a\rz"};
var json = myObject.toSource().replace(/\r/g,"\\r");
var myObject2 = eval(json);
$.writeln(myObject2.text)
@grefel
grefel / getAllTables.js
Last active September 7, 2016 11:42
Find all Tables in InDesign Document
function getAllTables(dok) {
allTables = [];
app.findTextPreferences = NothingEnum.NOTHING;
app.findTextPreferences.findWhat = "<0016>";
var result = dok.findText();
for (var i =0 ; i < result.length; i++) {
allTables[i] = result[i].tables[0];
}
return allTables;
}
@grefel
grefel / gist:c3934933abdaea03e49e
Last active August 29, 2015 14:07
Anchor is in overset text or XML #indesignjs
// Based on Marc Autret Idea http://www.indiscripts.com/post/2011/10/how-to-detect-a-ghost-item
var isGhost = (frame.parent instanceof Character) && (!frame.parent.parentTextFrames.length || frame.parent.parent instanceof XmlStory);
@grefel
grefel / idversion.js
Last active March 19, 2016 12:55
Get #InDesign version with one decimal place e.g. user folder navigation
function getVersion() {
var version = parseFloat(app.version).toFixed (1);
return (version % 1 == .5) ? version : Math.floor(version).toFixed(1);
}
@grefel
grefel / gist:55afd90a8e6a5ccd1a7b
Last active August 29, 2015 14:07
Get #InDesign Style by String
var root = app.activeDocument;
var result = getStyleByString(root, "Formatgruppe 2:Form\\:atgruppe 1:Zeichen\\:\\:format 1", "characterStyles", true);
$.writeln(result.name);
function getStyleByString(root, string, property, recreate) {
if (recreate == undefined) recreate = false;
stringResult = string.match (/^(.*?[^\\]):(.*)$/);
var cStyleName = (stringResult) ? stringResult[1] : string;
cStyleName = cStyleName.replace(/\\:/g, ":");
@grefel
grefel / gist:e9a333d5332ddbd3ca0a
Created November 4, 2014 15:54
Add standard namespaces for using evaluateXPathExpression() on #InDesign #XML subtrees
function addStandardNameSpace(xmlContainer) {
if( !xmlContainer.xmlAttributes.itemByName("xmlns:xml").isValid ) {
xmlContainer.xmlAttributes.add( "xmlns:xml", "http://www.w3.org/XML/1998/namespace" );
}
if( !xmlContainer.xmlAttributes.itemByName("xmlns:aid").isValid ) {
xmlContainer.xmlAttributes.add( "xmlns:aid", "http://ns.adobe.com/AdobeInDesign/4.0/");
}
if( !xmlContainer.xmlAttributes.itemByName("xmlns:aid5").isValid ) {
xmlContainer.xmlAttributes.add( "xmlns:aid5", "http://ns.adobe.com/AdobeInDesign/5.0/");
}