• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

... item number ONLY — image name label ?

Contributor ,
Jan 11, 2018 Jan 11, 2018

Copy link to clipboard

Copied

I have a compiled script (.scpt) that does a good job of labeling frames with the image name contained within said frame (screenshots 1-2 below).

Fine and good.

What I need is a script that will do the same except with only the 5 digit item number only...(screenshot 3 below)?

Hence said script will have to somehow delete the first 4 characters in the name and the remaining characters after the 9th character space, hence:

Something like:

006429960MBP1_062.jpg

... becomes ...

29960

OR something like:

006429960MBP1_062_long_name_here.jpg

... becomes ...

29960

See what I mean.

I need a script that can accomplish this.

Any leads?

As always any help is greatly appreciated.

Cheers.

1. The dialogue window of the image name labeling script.

Screen Shot 2018-01-11 at 19.28.17.png

2. The original script (Key E I manually adjusted).

Screen Shot 2018-01-11 at 19.28.58.png

3. Item number only — what I wish the script could do.

Screen Shot 2018-01-11 at 19.29.47.png

TOPICS
Scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Jan 21, 2018 Jan 21, 2018

Okay the below code allows me to accomplish the item-number-only label in one move which I’m grateful for (screenshot below code).

Thanks all and I really  appreciate all the help, especially from Laubender, since his code is the core of this final 3 part code:

1. Adding paragraph and object style

2. Laubender’s code

3. GREP code

Some things to keep in mind:

If you label any extra images after the initial use of the script, additional Object style duplicates will be created, but they’re benign.

Beyond

...

Votes

Translate

Translate
Guide ,
Jan 11, 2018 Jan 11, 2018

Copy link to clipboard

Copied

It is quite simple, please provide your source code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 12, 2018 Jan 12, 2018

Copy link to clipboard

Copied

...that’s the thing, it’s a compiled script. So the source code isn’t accessible.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2018 Jan 12, 2018

Copy link to clipboard

Copied

Hi Neal,

the label seems to be an InDesign text frame.
If the text comes with a distinct paragraph style or a distinct formatting property that is only used with the labels you could change the labels with a GREP Find/Replace action. No script necessary!

GREP Find:

(\d{4})(\d+).+$

plus the paragraph style that is currently used for the labels

GREP Replace:

$2

Something like that…

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 12, 2018 Jan 12, 2018

Copy link to clipboard

Copied

..tried that but it didn’t really do anything.

Also, I’m trying to accomplish the end result in one move, versus first using the script and then using GREP.

But I’m totally still interested in the GREP option if we can get that to work — it’s better than nothing.

Cheers.

Screen Shot 2018-01-12 at 13.11.30.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2018 Jan 12, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/neal+derekl34934377  wrote

..tried that but it didn’t really do anything.

Hi Neal,

strange…

Tested my GREP on a sample with InDesign CS6 and CC 2018.
GREPFindReplace-ImageLabel-1.png

Are the textframes with the labels positioned on a locked layer?

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 12, 2018 Jan 12, 2018

Copy link to clipboard

Copied

...I  gotcha now, it worked when I searched for Arial Regular — the only question I have now is can this all be scripted..?

Meaning can 1 script find/replace via the above criteria — so I can then key command it..?

Also is there a way to increase the overall size also — meaning the font size and frame size — say by 150%.

We’re getting there.

Cheers.

Screen Shot 2018-01-12 at 15.31.14.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2018 Jan 13, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/neal+derekl34934377  wrote

...I  gotcha now, it worked when I searched for Arial Regular

That's still strange. It should also work without a definition in Find Format.

For all other things:

Before running the script define a new object style with a paragraph style that fit your needs, also with necessary insets, a fill and automatic size perhaps. Then drag the icon from the [Basic Textframe] object style to your new object style. That will prep InDesign to use exactly that object style if a new text frame is created. Hopefully also for frames that created by your "Redcats PhotoID" script.

From my German InDesign:

ObjectStyle-Label-prefered.png

Or is your script doing a new object style for labels?
Then you could change that object style in the Object Styles panel or replace it with your own.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2018 Jan 13, 2018

Copy link to clipboard

Copied

Did a test with Object Find/Replace.

Find Text Frames with fill color: [Paper]
Replace with new object style.

That worked successfully.

And it will even work if the applied object style of a found item has an override.

What is not working very well:

Remove Object Style A from the Object Styles panel with Object Style B.
Found overrides on the frames where Object Style A was initially applied.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 14, 2018 Jan 14, 2018

Copy link to clipboard

Copied

...in the last round of experiments — I used and object style (with a key command of shift keypad 7) to accomplish the resizing —which is a good thing.

The bad thing — the GREP inputs of

find what: (\d{4})(\d+).+$

change to: $2

Result in also the copy blocks changing?

I just want purely the image label frames to change. not the actual catalog content, obviously...?

Thanks.

Look close at the actual catalog copy — the item number is being affected also....i don’t want that to occur.

Screen Shot 2018-01-14 at 23.46.30.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

..No the original script isn’t creating it’s own object style.

Also Dragging the to the object style I created myself — then running the script did not produce the desired result — until I “Cleared Overrides” (screenshots 1-3 below).

I’ll be going over the other responses below as soon as I can.

We’re still on the right path, it may take a hybrid of all these solutions combined in a script, which it seems will include GREP.

Cheers.

1.

Screen Shot 2018-01-18 at 00.18.15.png

2.

Screen Shot 2018-01-18 at 00.21.43.png

3.

Screen Shot 2018-01-18 at 00.18.30.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2018 Jan 13, 2018

Copy link to clipboard

Copied

Also, I’m trying to accomplish the end result in one move, versus first using the script and then using GREP.

Which is hard to do directly if the script is binary and you don’t have access to the source code.

A script can play a script, so if you can get the grep bit scripted, adding the code to first play the other script, then grep the result should work:

Call another InDesign script with doScript in InDesign CS4 js

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 14, 2018 Jan 14, 2018

Copy link to clipboard

Copied

...once all the pieces are working – it would would be awesome if it could all be accomplished with one key command — this proposal could very well be the key.

Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 14, 2018 Jan 14, 2018

Copy link to clipboard

Copied

..also — there are instances where a particular image name isn’t being affected — maybe perhaps because it is not adequately removing all characters after the 9th character — OR somehow maybe there’s a finite number of instances, versus a continuous loop until all instances are ‘catch’....no?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2018 Jan 14, 2018

Copy link to clipboard

Copied

There are more than one equivalent regular expressions… Another regex to try (presuming that there will always be four digits to be ignored and then 5 digits to capture):

(\d{4})(\d{5})(.*)

$2

or

(^\d{4})(\d{5})(.*)

$2

Are you sure that the specific text formatting is unique to the labels and that you are searching for this? Your screenshot does not show a “find format” in use. Notice in my sample that the body text is in Times font, while the label is in Arial font:

find.png

Of course, this is not scripting the grep find/change process… which is what you will need to do if you wish to have a single script that does it all… Otherwise you may need a 3rd party macro tool that can record the mouse movements and GUI clicks etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

As an alternative, you should be able to achieve this via a live grep style, so no need to manually run or script a grep find/change command!!!

grep-style.png

The paragraph style GREP style uses this regex:

[\l\u].+|(^\d{4})

or

[\l\u].+|^\d{4}

The upper part of the screenshot shows the GREP find in all it’s glory, with the character style coloured magenta – this is the pattern being matched…

The lower part of the screenshot uses the final character style formatting. The “Faux Delete” character style has a fill of none and a point size of 0.1pt to effectively hide/shuffle the unwanted text.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

...okay now I got the results you did with

(^\d{4})(\d{5})(.*)

$2

Previously I erroneously had the filled out the “Find Format” under ‘Text’ versus under ‘GREP’ thinking that’s how it worked — my mistake. Now I got it, and it only targets the labels now. Great.

I’m a little concerned as to what the GREP code is specifically saying — because it’s still not catching other labels with different character counts in them, or maybe there’s a number discrepancy versus letters — to be clear — what will help me in a majority of image name cases is specifically a GREP that says:

“remove the first 4 characters (numbers or not) — then keep the next 5 characters (numbers or not) — then remove everything else afterwards (numbers or not)”

It would reassure me more if that was the case, so that every label gets affected, regardless of character count length.

But this is good nonetheless.

**Now if I could only script this?

**I do already have this script (found on here, thanks) that I use to remove hanging empty paragraphs.

app.findGrepPreferences.findWhat="\\s+\\Z";

app.changeGrepPreferences.changeTo="";

app.activeDocument.changeGrep();

That I’m assuming I can plug the below into...I know brackets should be doubled, although is that still true when within parenthesis versus just the quotes — i.e. the script above enters \s+\Z in the Find What GREP window?

app.findGrepPreferences.findWhat="(^\d{4})(\d{5})(.*)";

app.changeGrepPreferences.changeTo="$2";

app.activeDocument.changeGrep();

**Also how would I account for the Find Format: + Arial + Regular with the same script?

Almost there, this is all great.

Also is it possible for the same script to add an object style and then apply it to the arial regular text frame — to get the size results needed, etc...?

Thanks again all, really appreciate this.

Screen Shot 2018-01-18 at 00.40.27.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/neal+derekl34934377  wrote

..also — there are instances where a particular image name isn’t being affected — maybe perhaps because it is not adequately removing all characters after the 9th character — OR somehow maybe there’s a finite number of instances, versus a continuous loop until all instances are ‘catch’....no?

Hi Neal,

to do a working script you need a unique handle on the label text frames.
One idea is to give them a unique object style with a unique paragraph style while creating them.

I think, I was showing a way how to do that in answer #7.

But the biggest issue you seem to have is the contents of the labels, a.k. the names of the placed images.
If these are not consistent in any way you have no chance to restrict them to the number you want.

The same logic that goes into a GREP will also go into a script.

If there is no unique logic that fits, how could a script help?

Below a script (ExtendScript/JavaScript) that will do all the labeling for selected items.

1. You can undo it in one go.

2. It will add an object style and a new layer to the document.

You only have to change the object style to your personal needs.

3. It will add a new text frame on top of every graphic found in the selection provided there is an accessible link.

To change the text frame's size and position, also its typography, just change the applied object style.


You can change the name of the object style and the name of the layer in lines 23 and 24.

The name of the placed graphic is added in line 60.

That's the hook for a change if a distinct GREP pattern would fit.

/**

* @@@BUILDINFO@@@ SetCaption-GraphicName-SELECTION.jsx !Version! Mon Jan 15 2018 10:30:17 GMT+0100

*/

// By Uwe Laubender

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

app.doScript

    (

  

    labelAllGraphicsOfSelection,

    ScriptLanguage.JAVASCRIPT,

    [],

    UndoModes.ENTIRE_SCRIPT,

    "Label all linked graphics of selection | SCRIPT"

  

    );

function labelAllGraphicsOfSelection()

{

if(app.documents.length == 0){ return };

var objectStyleName = "Label";

var layerName = "Label";

var doc = app.documents[0];

var activeSpread = doc.layoutWindows[0].activeSpread;

var sel = app.selection;

var selLength = sel.length;

var allGraphics = [];

var objectStyle = doc.objectStyles.itemByName(objectStyleName);

if(!objectStyle.isValid){objectStyle = doc.objectStyles.add({name : objectStyleName})};

var newLayer = doc.layers.itemByName(layerName);

if(!newLayer.isValid){ newLayer = doc.layers.add({ name : layerName })};

newLayer.move( LocationOptions.BEFORE , doc.layers[0] );

newLayer.visible = true;

newLayer.locked = false;

// Get all graphics of selection:

for(var n=0;n<selLength;n++)

{

    allGraphics = allGraphics.concat(sel.allGraphics);

};

var allGraphicsLength = allGraphics.length;

for(var n=0;n<allGraphicsLength;n++)

{

    if(allGraphics.itemLink == null){ continue };

    if(allGraphics.itemLink.status == LinkStatus.LINK_INACCESSIBLE){ continue };

  

    activeSpread.textFrames.add

    (

        {

            geometricBounds : allGraphics.parent.geometricBounds ,

            appliedObjectStyle : objectStyle ,

            contents : allGraphics.itemLink.name ,

            itemLayer : newLayer

        }

    );

};

};

Hope, you'll find a GREP that fit your needs.

Only then it would make sense to add that GREP to the script to make it a one-click solution.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

...this worked with a preexisting Object style, yes.

Now, could the same script add the object style if it yet doesn’t exist?

When I build tedious assets, like swatches, color names, etc...I have a key command to ‘Load Object Styles…’ which allows me to point to a indd doc with the styes I need.

But I‘ve always just wanted the styles to automatically load whenever I open any document.....is there a way to permanently keep objects..? Globally versus document by document..?

Beyond that I could definitely see this working with the right GREP.

So far I was thinking of the below — but how would I begin to adequately add that to your script, also the Find Format is a snag?

Thanks again....almost there. This is going to work in one move and change my work-life....cheers.

**I do already have this script (found on here, thanks) that I use to remove hanging empty paragraphs.

app.findGrepPreferences.findWhat="\\s+\\Z";

app.changeGrepPreferences.changeTo="";

app.activeDocument.changeGrep();

That I’m assuming I can plug the below into...I know brackets should be doubled, although is that still true when within parenthesis versus just the quotes — i.e. the script above enters \s+\Z in the Find What GREP window?

app.findGrepPreferences.findWhat="(^\d{4})(\d{5})(.*)";

app.changeGrepPreferences.changeTo="$2";

app.activeDocument.changeGrep();

**Also how would I account for the Find Format: + Arial + Regular with the same script?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

This is where I’m finally at, I don’t mean to exhaust everyone, but I combined your script with the below (after finding the find format script)..the complete script is below.

And it runs pretty well, but...

• Would still love a way to permanently, or for the script, to add the object stye it uses somehow, WITHOUT having to load object styles for each document..?

• Also the GREP code still doesn’t catch everything (screenshot below)...?

But this is great, I can start using this right now.

Right now it’s a two step process, load objrct style, then run the script — of coarse key commanding both.

But I still know we can do this is one step.

Cheers all and I appreciate everyone’s hard work. This is really great.

  1. /**
  2. * @@@BUILDINFO@@@ SetCaption-GraphicName-SELECTION.jsx !Version! Mon Jan 15 2018 10:30:17 GMT+0100
  3. */ 
  4. // By Uwe Laubender 
  5.  
  6. app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll; 
  7. app.doScript 
  8.     ( 
  9.     
  10.     labelAllGraphicsOfSelection, 
  11.     ScriptLanguage.JAVASCRIPT, 
  12.     [], 
  13.     UndoModes.ENTIRE_SCRIPT, 
  14.     "Label all linked graphics of selection | SCRIPT" 
  15.     
  16.     ); 
  17.  
  18. function labelAllGraphicsOfSelection() 
  19.  
  20. if(app.documents.length == 0){ return }; 
  21.  
  22. var objectStyleName = "Label"; 
  23. var layerName = "Label"; 
  24.  
  25. var doc = app.documents[0]; 
  26. var activeSpread = doc.layoutWindows[0].activeSpread; 
  27.  
  28. var sel = app.selection; 
  29. var selLength = sel.length; 
  30. var allGraphics = []; 
  31.  
  32. var objectStyle = doc.objectStyles.itemByName(objectStyleName); 
  33. if(!objectStyle.isValid){objectStyle = doc.objectStyles.add({name : objectStyleName})}; 
  34.  
  35. var newLayer = doc.layers.itemByName(layerName); 
  36. if(!newLayer.isValid){ newLayer = doc.layers.add({ name : layerName })}; 
  37. newLayer.move( LocationOptions.BEFORE , doc.layers[0] ); 
  38. newLayer.visible = true; 
  39. newLayer.locked = false; 
  40.  
  41. // Get all graphics of selection: 
  42. for(var n=0;n<selLength;n++) 
  43.     allGraphics = allGraphics.concat(sel.allGraphics); 
  44. }; 
  45.  
  46. var allGraphicsLength = allGraphics.length; 
  47.  
  48. for(var n=0;n<allGraphicsLength;n++) 
  49.     if(allGraphics.itemLink == null){ continue }; 
  50.     if(allGraphics.itemLink.status == LinkStatus.LINK_INACCESSIBLE){ continue }; 
  51.     
  52.     activeSpread.textFrames.add 
  53.     ( 
  54.         { 
  55.             geometricBounds : allGraphics.parent.geometricBounds , 
  56.             appliedObjectStyle : objectStyle , 
  57.             contents : allGraphics.itemLink.name , 
  58.             itemLayer : newLayer 
  59.         } 
  60.     ); 
  61. }; 
  62.  
  63. }; 
  64. //GREP script to get 5 digit item number
  65. app.findGrepPreferences.appliedFont="Arial";
  66. app.findGrepPreferences.fontStyle="Regular";
  67. app.findGrepPreferences.findWhat="(^\\d{4})(\\d{5})(.*)";
  68. app.changeGrepPreferences.changeTo="$2";
  69. app.activeDocument.changeGrep();

Screen Shot 2018-01-18 at 02.12.52.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

I’m a little concerned as to what the GREP code is specifically saying — because it’s still not catching other labels with different character counts in them, or maybe there’s a number discrepancy versus letters — to be clear — what will help me in a majority of image name cases is specifically a GREP that says:

“remove the first 4 characters (numbers or not) — then keep the next 5 characters (numbers or not) — then remove everything else afterwards (numbers or not)”

It would reassure me more if that was the case, so that every label gets affected, regardless of character count length.

This is where I’m finally at... Also the GREP code still doesn’t catch everything (screenshot below)...?

(^\\d{4})(\\d{5})(.*)

I would use the following regular expression for the find/search:

(^.{4})(.{5})(.*)

=

Capture Group 1: From the beginning of the line/string, match “any character” exactly 4 times

Capture Group 2: After the first 4 characters, match “any character” exactly 5 times

Capture Group 3: After the first 9 characters, match “any character” zero or more times

You would still use $2 for the replace, which references Capture Group 2.

In long documents, this alternative may also have “technical merit” in preference to the previous regex:

Find = (?:^.{4})(.{5})(?:.*)

Replace = $1

The forum would really need a list of filenames to test if there were any edge cases that did not meet this criteria. If you can provide a list of filenames, that would be great. I can provide info on how to do this so that you can batch copy all filenames in a folder – are you Mac or Win based?

P.S.: I have noted in red from your latest code (line 84) what I believe are extra backslash characters \ that may be mistakes and would break the regex.

NOTE: I still believe that my suggestion in post #15 of using a GREP STYLE rather than a GREP FIND/REPLACE may be a better solution, as it is live and “automagic” and does not require scripting or multiple runs if further content is later added.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 21, 2018 Jan 21, 2018

Copy link to clipboard

Copied

LATEST

Okay the below code allows me to accomplish the item-number-only label in one move which I’m grateful for (screenshot below code).

Thanks all and I really  appreciate all the help, especially from Laubender, since his code is the core of this final 3 part code:

1. Adding paragraph and object style

2. Laubender’s code

3. GREP code

Some things to keep in mind:

If you label any extra images after the initial use of the script, additional Object style duplicates will be created, but they’re benign.

Beyond that this is a great script for labeling images with only the five digit item number, great for building catalogs and just needing a quick reference to identify items on the fly.

Will help tremendously.

Cheers.

  1. /**
  2. * @@@BUILDINFO@@@ SetCaption-GraphicName-SELECTION.jsx !Version! Mon Jan 15 2018 10:30:17 GMT+0100
  3. */ 
  4. // By Uwe Laubender 
  5. /* Additions by Neal Derek Lawson
  6. Paragraph styles, Object styles and GREP inclusions, via found scripts on Adobe forums.
  7. Original credit goes to original coders.
  8. */
  9. //Paragraph and Object style inclusions
  10. myDocument = app.documents[0]; 
  11. //Paragraph style here
  12. myParagraphStyle = myDocument.paragraphStyles.add();
  13. myParagraphStyle.properties = {
  14. name:"Labels_pStyle",
  15. appliedFont: "Arial",
  16. fontStyle: "Regular",
  17. noBreak: true,
  18. pointSize: 20,
  19. },
  20.  
  21. //Object style here
  22. myObjectStyle = myDocument.objectStyles.add(); 
  23.   myObjectStyle.properties = { 
  24.   name: "Label", 
  25.   enableParagraphStyle: true, 
  26.   enabledStroke: true, 
  27. enableFill: true,
  28. enableTextFrameAutoSizingOptions: true, 
  29. enableTextFrameGeneralOptions: true,
  30.   strokeWeight: 1, 
  31. fillColor:"White",
  32. nonprinting: true,
  33. appliedParagraphStyle: "Labels_pStyle",
  34.  
  35. textFramePreferences: { 
  36.   autoSizingReferencePoint: AutoSizingReferenceEnum.CENTER_POINT, 
  37.   autoSizingType: AutoSizingTypeEnum.HEIGHT_AND_WIDTH,
  38. insetSpacing: ".1 in", 
  39.   } 
  40.   };
  41. // Uwe Laubender’s script
  42. app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll; 
  43. app.doScript 
  44.     ( 
  45.     
  46.     labelAllGraphicsOfSelection, 
  47.     ScriptLanguage.JAVASCRIPT, 
  48.     [], 
  49.     UndoModes.ENTIRE_SCRIPT, 
  50.     "Label all linked graphics of selection | SCRIPT" 
  51.     
  52.     ); 
  53.  
  54. function labelAllGraphicsOfSelection() 
  55.  
  56. if(app.documents.length == 0){ return }; 
  57.  
  58. var objectStyleName = "Label"; 
  59. var layerName = "Label"; 
  60.  
  61. var doc = app.documents[0]; 
  62. var activeSpread = doc.layoutWindows[0].activeSpread; 
  63.  
  64. var sel = app.selection; 
  65. var selLength = sel.length; 
  66. var allGraphics = []; 
  67.  
  68. var objectStyle = doc.objectStyles.itemByName(objectStyleName); 
  69. if(!objectStyle.isValid){objectStyle = doc.objectStyles.add({name : objectStyleName})}; 
  70.  
  71. var newLayer = doc.layers.itemByName(layerName); 
  72. if(!newLayer.isValid){ newLayer = doc.layers.add({ name : layerName })}; 
  73. newLayer.move( LocationOptions.BEFORE , doc.layers[0] ); 
  74. newLayer.visible = true; 
  75. newLayer.locked = false; 
  76.  
  77. // Get all graphics of selection: 
  78. for(var n=0;n<selLength;n++) 
  79.     allGraphics = allGraphics.concat(sel.allGraphics); 
  80. }; 
  81.  
  82. var allGraphicsLength = allGraphics.length; 
  83.  
  84. for(var n=0;n<allGraphicsLength;n++) 
  85.     if(allGraphics.itemLink == null){ continue }; 
  86.     if(allGraphics.itemLink.status == LinkStatus.LINK_INACCESSIBLE){ continue }; 
  87.     
  88.     activeSpread.textFrames.add 
  89.     ( 
  90.         { 
  91.             geometricBounds : allGraphics.parent.geometricBounds , 
  92.             appliedObjectStyle : objectStyle , 
  93.             contents : allGraphics.itemLink.name , 
  94.             itemLayer : newLayer 
  95.         } 
  96.     ); 
  97. }; 
  98.  
  99. }; 
  100. //GREP script to get 5 digit item number
  101. //reset GREP preferences
  102. app.findGrepPreferences=app.changeGrepPreferences=null;
  103. app.findGrepPreferences.appliedFont="Arial";
  104. app.findGrepPreferences.fontStyle="Regular";
  105. app.findGrepPreferences.findWhat="(^\\d{4})(\\d{5})(.*)";
  106. app.changeGrepPreferences.changeTo="$2";
  107. app.activeDocument.changeGrep();

Results screenshot.

Screen Shot 2018-01-21 at 17.24.15.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines