ExtendScript libraries
Hello All,
I want to create a library of commonly used functions, etc. that I can use in my ExtendScript scripts. I created a script that I put in the JavaScript startup folder that has this content:
var CPF = {};
CPF.getText = function () {
var text = "";
return {
getText: function (textObj) {
// Get a list of strings in the text object.
var textItems = textObj.GetText(Constants.FTI_String);
// Concatenate the strings.
for (var i = 0; i < textItems.len; i += 1) {
text += (textItems.sdata);
}
}
};
}
Now when I want to get the text of a text object, I can use this:
alert (CPF.getText(pgf)); // pgf is a paragraph.
One important note: I am using ExtendScript with FrameMaker here, not InDesign, so the code itself may look unfamiliar. I am posting here because the principles should be the same in InDesign and there are a lot of smart people here :-). I have been looking at JavaScript libraries and reading about good design patterns, but I am having a hard time translating this to the ExtendScript environment.
My questions are: Is this the best way to do this kind of thing? Or, is there a better way to have a library of functions that can be used in my scripts? Thanks in advance.
Rick

