core functions

connectToDataSource (dataSourceQuery)

Connect to a SQL database


#include ../bin/porky.jsx;

var thisParentFolder = File($.fileName).parent;
var thisRootFolder = File("~").fsName;
var thisAbsolutePath = unescape( thisParentFolder.toString().replace("~", thisRootFolder) );
alert(thisAbsolutePath);


// GLOBAL OBJECTS
settings.dataSource.type = "SQLite";
settings.dataSource.server = "-";
settings.dataSource.name = thisAbsolutePath + "/database.sqlite";
settings.dataSource.username = "-";
settings.dataSource.password = "-";

var mySQLiteResult = "";

mySQLiteResult = connectToDataSource("SELECT * FROM evenmorerows LIMIT 1000,1");

/*
    mySQLiteResult = connectToDataSource("SELECT COUNT(ClientLastname) AS ZAEHLER FROM MyTable");
    mySQLiteResult = connectToDataSource("SELECT * FROM MyTable");
    mySQLiteResult = connectToDataSource("UPDATE MyTable SET ClientLastname='Möller' WHERE ClientLastname='Müller'");
    mySQLiteResult = connectToDataSource("SELECT MyOtherTable.ClientFirstname, MyTable.ClientLastname FROM MyTable, MyOtherTable");
    mySQLiteResult = connectToDataSource("CREATE TABLE byebye(Spalte1 varchar(256), Spalte2 varchar(256), Spalte3 INT)");
    mySQLiteResult = connectToDataSource("INSERT INTO byebye (Spalte1, Spalte2, Spalte3) VALUES ('hallo', 'oli', 'ü')");
    mySQLiteResult = connectToDataSource("SELECT * FROM byebye");
    mySQLiteResult = connectToDataSource("DELETE FROM byebye WHERE(Spalte3='ü')");
    mySQLiteResult = connectToDataSource("ALTER TABLE byebye ADD Zeitstempel TIMESTAMP");
    mySQLiteResult = connectToDataSource("SELECT name FROM sqlite_master");
    mySQLiteResult = connectToDataSource("PRAGMA table_info(byebye)");
    mySQLiteResult = connectToDataSource("DROP TABLE byebye");
*/

alert("This comes from the database\n" + mySQLiteResult);


mySQLiteResult = json_parse(mySQLiteResult);
mySQLiteResult = mySQLiteResult[0].col7;

alert("Accessing keys directly is possible!\n" + mySQLiteResult);

addFrame (xFrame, yFrame, wFrame, hFrame, stringOrFile)


#include ../bin/porky.jsx;

var myString = "porky rocks!\nof course it does...\nmagic.";

var myTextframe = addFrame(15, 15, 100, 50, myString);

appendToFrame (frameObject, stringOrTwoDArray)

Create a textframe and append text to it


#include ../bin/porky.jsx;

var myString = "hey, ho, let's, go!";

var myTextframe = addFrame(15, 15, 100, 50, "test test one two...\r");

var myText = appendToFrame(myTextframe, myString);

And here a table example



#include ../bin/porky.jsx;

var myString = "1, 2, 3, 4|hey, ho, let's, go!";
var myArray = stringToTwoDArray(myString, ",", "|");

alert("Result\n" + myArray[0] + "\n" + myArray[1]);

var myTextframe = addFrame(15, 15, 100, 50, "");

var myTable = appendToFrame(myTextframe, myArray);

fitTextboxHeightToContent(frameObject)


#include ../bin/porky.jsx;

var myTextframe = addFrame(15, 15, 100, 5, "test test one two...\rtest test one two...\rtest test one two...\rtest test one two...\r");

// this adjusts the box height by iteration
myTextframe = fitTextboxHeightToContent(myTextframe);

resetCharacterStyle(textObject)


#include ../bin/porky.jsx;

var myString = "hey, ho, let's, go!";

var myTextframe = addFrame(15, 15, 100, 50, "test test one two...\r");

var myText = appendToFrame(myTextframe, myString);

// this resets the current characterstyle to none (e.g. the one which was active when the script was launched)
myText = resetCharacterStyle(myText);

createPlaceholderImage()


#include ../bin/porky.jsx;

var myImagefile = createPlaceholderImage();//create file object
var myImageframe = addFrame(15, 65, 50, 50, myImagefile);

placeSnippet(snippetPath, xSnippet, ySnippet)


#include ../bin/porky.jsx;

var mySnippet = placeSnippet( "/snippet.idms", 115, 65);//placing file at position 115/65

addNewPage()


#include ../bin/porky.jsx;

var myPage = addNewPage();
alert("Setting new page size:\n" + setPageSize(210, 210));

setPageSize(xWidth, yHeight)


#include ../bin/porky.jsx;

var myPage = addNewPage();
alert("Setting new page size:\n" + setPageSize(210, 210));

moveObjectToPage(frameObject, pageObject)


#include ../bin/porky.jsx;

var myNewPage = addNewPage();

var myTextframe = addFrame(0, 0, 50, 50, "Hello porky!");
myNewPage = moveObjectToPage(myTextframe, myNewPage);

searchReplaceTextframe(textframeObject, searchText, replaceText)


#include ../bin/porky.jsx;

var mySnippet = placeSnippet( "/snippet.idms", 115, 65);

alert(mySnippet);
var searchAndReplaceInThisFrame = mySnippet[0];
alert( "Replacing some text in\n" + searchReplaceTextframe(searchAndReplaceInThisFrame, "This is a snippet", "porky rocks") );

stringToTwoDArray(separatedString, columnSeparator, rowSeparator)


#include ../bin/porky.jsx;

var myString = "1a, 2a, 3a, 4a|hey, ho, let's, go!";
var myArray = stringToTwoDArray(myString, ",", "|");
alert( JSON.stringify(myArray) );

var myOtherString = twoDArrayToString(myArray, ",","|");
alert(myOtherString);

twoDArrayToString(twoDArray, columnSeparator,rowSeparator)


#include ../bin/porky.jsx;

var myString = "1a, 2a, 3a, 4a|hey, ho, let's, go!";
var myArray = stringToTwoDArray(myString, ",", "|");
alert( JSON.stringify(myArray) );

var myOtherString = twoDArrayToString(myArray, ",","|");
alert(myOtherString);

tagThis (tagObject, syncScript, syncIdentifier)


#include ../bin/porky.jsx;

var myTextframe = addFrame(15, 15, 100, 50, "");

var myTextObject1 = appendToFrame(myTextframe, "Some placeholder text");

var mySyncObject1 = tagThis(myTextObject1, "/syncScript1.jsx", "1");

appendToFrame(myTextframe, "\n\nSome more static text...\n\n");

var myTextObject2 = appendToFrame(myTextframe, "Some other placeholder text");

var mySyncObject2 = tagThis(myTextObject2, "/syncScript2.jsx", "2");

recursiveSyncFrame (frameObject)

Select a frame object from your layout and run this script.
It will sync each element’s content recursive by running the script name and using the identifier which is inside each element’s tag.


#include ../bin/porky.jsx;

// setting the global object
// recursiveSyncFrame() uses this information so it can call the sync script found in the attributes of each tagged XML element
settings.sync.scriptFolder = "/syncScripts";

var mySyncedFrameObject = "";

for(var frameCounter=0; frameCounter<app.selection.length; frameCounter++){
    mySyncedFrameObject = recursiveSyncFrame(app.selection[frameCounter]);
}



syncXMLElement (taggedXMLElement)

Select an XML element in InDesign's XML structure and run this script.
It will sync the element's content by using the xml attributes name/value pair which is inside the element's tag.
Global variable syncIdentifier will be set by running this function.


#include ../bin/porky.jsx;

// setting the global object
// syncXMLElement() uses this information so it can call the sync script found in the attributes of each tagged XML element
settings.sync.scriptFolder = "/syncScripts";

// What to sync? Let's sync this XML element
var myXMLElement = syncXMLElement(app.selection[0]);

Documentation didn't solve your problem?

There's two ways to help you: contact our support or feel free to file an issue on GitHub.

Need Support?

This service is available for a fee.

Please drop us a line on anfrage@schreiber-freunde.de and provide us all technical information on your issue so we can calculate a quotation for you.

Github

In case something doesn't work properly (which can happen) please feel free to pull a change request on GitHub.