Saturday, October 01, 2005
Standard Methods and Functions
I'm becoming concerned that my script postings here are become unwieldy because of the length of the standard methods and functions I use over and over. By way of an experiment, I'm going to post some of the more common ones here so I won't have to repeat them in posts about specific scripts:
isText() Method
This method returns true if an object is any kind of text object and false otherwise. Constructing it this ways allows it to be called like this:if (myObj.isText()) { // myObj is text so continueHere's the definition of the method. I always put my method definitions at the top of my scripts, immediately after the description.
Object.prototype.isText = function() {
switch(this.constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "TextFrame":
return true;
default :
return false;
}
}
errorExit(myMsg) function
This function throws up an alert if an argument is present, otherwise it just exits. For CS2 or later, it issues a beep immediately before displaying the alert.function errorExit(message) {I always put my functions after the main body of the script, usually preceded by a comment line that indicates the start.
if (arguments.length > 0) {
if (app.version != 3) { beep() } // CS2 includes beep() function.
alert(message);
}
exit(); // CS exits with a beep; CS2 exits silently.
}
getParentTextFlow(theTextRef) Function
This function returns the parent text flow of the referenced text item. Notice that the function does no error checking; if you pass it something that doesn't have a parentStory property you'll get an error. The script checks to see if the referenced text is in a cell in a table, and if so it returns a reference to the text of the cell rather than the parentStory which in this case is the parentStory of the table.function getParentTextFlow(theTextRef) {That's it for now. Last updated 10/1/05.
// Returns reference to parent story or text of cell, as appropriate
if (theTextRef.parent.constructor.name == "Cell") {
return theTextRef.parent.texts[0];
} else {
return theTextRef.parentStory;
}
}
Comments:
<< Home
Dear Saunders
I am really happy and Thanks to you!
Please keep in touch, I know your Questions in Adobe-Forums.
I saw your photo, you look fine.
Post a Comment
I am really happy and Thanks to you!
Please keep in touch, I know your Questions in Adobe-Forums.
I saw your photo, you look fine.
<< Home