Support the development of a script of file-placement?

Chip Hello Folks,

Who we are: we are a small shop (OS X Leopard, CS4) designers in education non-profit. We use a script that was downloaded by Olav Kvern usefully in this forum, which then made us minor adjustments to, and works very well for us - it looks for a document and replaces the tag filenames inline graphics placed in a selected folder.

We recently realized there is a situation that seems to trigger the script each time - when we have several files to be placed on a single line. For example, if the script crosses

< < 12345a.eps > > [tab] < < 12345b.eps > > [para back]

... it will be the first file on the line, and then stop the script and remove the rest of the text on the line (ouch!).

Any suggestions on how to approach this would be appreciated. Script is below.

Thank you

Ian Carey

main();

main() {} function

myFolder is Folder.selectDialog ("select a file");.

If (myFolder! = null) {}

myReplaceGraphics (myFolder);

}

}

function myReplaceGraphics (myFolder) {}

var myInlineGraphic, myX1, myY1, myX2, myY2, myFoundItem;

myDocument var = app.documents.item (0);

myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

var myRegExp = "(?i) < <(.*)" > > ""

myDocument var = app.documents.item (0);

var myDoc = app.activeDocument;

myDoc.selection = NothingEnum.nothing;            deselect all objects to avoid replacing the color of an object that could already be selected

myDoc.pageItemDefaults.strokeColor = 'None ';   Set the color of outline by default document 'None '.

myDoc.pageItemDefaults.fillColor = "None" / / sets the color of filling by default document 'None '.

Clear the find/change grep preferences.

app.findGrepPreferences = NothingEnum.nothing;

app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.findWhat = myRegExp;

Search in the document.

var myFoundItems = myDocument.findGrep (true);

Clear the find/change preferences after the search.

app.findGrepPreferences = NothingEnum.nothing;

app.changeGrepPreferences = NothingEnum.nothing;

If (myFoundItems.length! = 0) {}

for (var myCounter = 0; myCounter < myFoundItems.length; myCounter ++) {}

myFoundItem = myFoundItems [myCounter];

myX1 = myFoundItem.characters.item (0) .horizontalOffset;

myY1 = myFoundItem.characters.item (0) .baseline;

Change the following values to change the size of the image.

myX2 = myX1 + 72;

myY2 = myY1 + 72;

myFileName = myFoundItem.contents.replace (/ < <(.*) > > / i, '$1');

CheminMonFichier = myFolder + "/" + myFileName.

$.writeln (myFilePath);

myFrame = myFoundItem.insertionPoints.item (0).rectangles.add ();

Recompose text after you add the inline frame.

myFoundItem.parent.recompose ();

myFrame.geometricBounds = [myX1, myY2, myY1, myX2];

try {}

myInlineGraphic = myFrame.place (File (myFilePath)) [0];

myFrame.fit (FitOptions.frameToContent);

} catch (myError) {}

}

}

Now replace the tags.

app.findGrepPreferences.findWhat = myRegExp;

app.changeGrepPreferences.changeTo = "";

myDocument.changeGrep ();

Clear the find/change preferences after the search.

app.findGrepPreferences = NothingEnum.nothing;

app.changeGrepPreferences = NothingEnum.nothing;

}

Thanks for posting using scripts > advanced Java syntax highlighting in the editor.

Your problem seems to be that this regexp:

var myRegExp = "(?i)<<(.*)>>"

Gourmand and corresponds to all of the first < to="" the="" last=""> >. (In addition, the line is missing a semicolon).

Try to replace it with:

var myRegExp = "(?i)<<(.*?)>>"

to turn off the greediness.

Tags: InDesign

Similar Questions

Maybe you are looking for

  • Lost most of the Contacts

    Hello. Today, I noticed that I have lost 80% of the names and addresses I had in my file of Contacts on my iMac. I still have the complete list on my iPhone. My iCloud Contacts settings are on my phone and computer. How do I transfer my contacts list

  • Lines on screen Macbook

    Picked up my Macbook to the table and these lines appeared. First time that's ever happened. Any info on what happened actually technically? Thank you.

  • Firefox freeze for all 10-15 seconds on some websites.

    When I am browsing of sites on the internet, most operate normally. But there's a lot that when I go to these Web sites, freeze firefox completely for about 10-15 seconds before returning to normal. I've included the url for 2 sites that it does on.

  • How can I clear the notifications from the notification Center while I can not click on the delete button?

    How can I clear the notifications from the notification Center while I can not click on the delete button? I have an iphone with ios 9.3 6

  • WRT56G Firmware upgrade fails

    With losing connectivity problems so decided to update v1.00.7 firmware to the latest version available. Download the upgrade file and log into the web-based administrator.  Select file, and then click the UPGRADE button.  A few clicks on the timelin