Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

ExtendScript libraries

$
0
0

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[i].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


Viewing all articles
Browse latest Browse all 15932

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>