Skip to main content
This topic has been closed for replies.

1 reply

Vamitul
Legend
June 18, 2013

Hello!

First of all, CONGRATULATIONS!!

Your coding style is way way better than mine, the functions and variables clearly named (mine are usualy a mess like myT, myS, pag, etc), the code is well commented.. like i said.. nice.

For now, except for adding error handling, (for that, please see: http://www.javascriptkit.com/javatutors/trycatch.shtml), there is not much that needs to be done.

One thing, instead of just calling main(), i would use doScript, so you can take advantage of a single undo point:

instead of the first line, just use:

app.doScript("main()",undefined,undefined,"Page Resizer");

for your next scripts i suggest the following:

1) use ScriptUI instead of indesign's dialogs. It's not much harder, and the extra power it's well worth the effort. See Peter's amazing guide: http://www.kahrel.plus.com/indesign/scriptui.html

2) use a object oriented approach, especialy if the script is as large as this. Procedural programming is ok for a small, simple script, but as the size and complexity goes up you will find it's more easier to mainain and debug OOP code. However, the jump from procedural to object oriented is difficult if you are note used to OOP.

June 18, 2013

Hi Vamitul,

Thanks a ton. You have made me feel proud. I will try to add your suggestions and try to make it better.

Regards,

Muthuraj. D

Known Participant
June 19, 2013

Hi Muthuraj,

If you find yourself repeating code, you can reduce it by creating functions and pass in variables for the parts that are different.

For example, in your code where you do several find/change operations using grep, you can do something like this:

function findChangeUsingGrep (lookFor, changeTo, appliedFont, fontSize, fontStyle) {

  app.findGrepPreferences = NothingEnum.nothing;

  app.changeGrepPreferences = NothingEnum.nothing;

  app.findGrepPreferences.findWhat = lookFor;

  app.findGrepPreferences.appliedFont = changeTo;

  app.findGrepPreferences.pointSize = fontSize;

  app.findGrepPreferences.fontStyle = fontStyle;

  app.activeDocument.changeGrep();

}

Then call it with something like this:

 

var lookFor = ",\\s+[\\l\\u]+?\\s?\\d{4},?\\s*[\\l\\u]*\\.*\\s*\\d*"

if (RevNumber == "") {

  findChangeUsingGrep(lookFor, RevToReplace1, "Simplified", 7, "Light");

}

if (RevNumber !== "") {

  findChangeUsingGrep(lookFor, RevToReplace2, "Simplified", 7, "Light");

}

But like Vamitul said, well done!

John