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

Draft Stamp InDesign script

New Here ,
Aug 29, 2017 Aug 29, 2017

Hi InDesign Script folks

Wondering if anyone has an InDesign javascript that will add a draft stamp to an active document? It's a workflow thing that I'm trying to streamline a bit more.

It's a basic red stroked (5pt), rounded cornered (5mm) text box (100mm wide x 70mm high) with the word 'DRAFT' in large red type and a modification date (insert variable text field) below in smaller red type.

The end game is to have three  separate stamps off the one script. DRAFT, FINAL, SENT TO PRODUCTION with dates below.

I've tried to alter a couple of scripts but no luck.

Any help would be appreciated.

Thanks

(F)

TOPICS
Scripting
2.6K
Translate
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 ,
Aug 29, 2017 Aug 29, 2017

Moved it from InDesign to InDesign Scripting.

Translate
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
New Here ,
Aug 29, 2017 Aug 29, 2017

Thanks Ten A. First time user of the forum. Didn't realise there was a specific InDesign Scripting forum. Appreciated.

Translate
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
People's Champ ,
Aug 30, 2017 Aug 30, 2017

Something like that ?

var doc = app.activeDocument;

var buildUI = function(strings, canRemove) {

var

u,

ui = new Window ( "dialog" ),

ls = ui.add('dropdownlist', u, strings),

btnGp = ui.add('group'),

koBtn = btnGp.add('button',u,'Cancel' ),

remBtn = btnGp.add('button',u,'Remove' ),

okBtn = btnGp.add('button',u,'Add' ),

res;

ui.preferredSize.width = 400;

ui.alignChildren = ["fill","top"];

btnGp.alignChildren = ["fill","top"];

okBtn.enabled = false;

remBtn.enabled = canRemove;

ls.onChange = function() {

if ( !ls.selection) return;

ui.status = ls.selection.index;

okBtn.enabled = ls.selection !=null;

}

koBtn.onClick = function() {

ui.close(0);

}

remBtn.onClick = function() {

ui.close(2);

}

okBtn.onClick = function() {

ui.close(1);

}

return ui;

}

var main = function () {

var doc = app.properties.activeDocument, ui, uiCall,

props = {

watermarkDoPrint:true,

watermarkDrawInBack:false,

watermarkFontPointSize:45,

watermarkOpacity:30,

watermarkRotation:-15,

watermarkVerticalPosition:WatermarkVerticalPositionEnum.WATERMARK_V_CENTER,

watermarkHorizontalPosition:WatermarkHorizontalPositionEnum.WATERMARK_H_CENTER

},

strings = ["DRAFT", "FINAL", "SENT TO PRODUCTION "],

colors = [UIColors.RED, UIColors.GREEN, UIColors.BLUE];

if ( !doc ) return;

ui = buildUI(strings, doc.watermarkPreferences.watermarkVisibility == true);

uiCall = ui.show();

if ( !uiCall) return;

if ( uiCall == 1 ) {

props.watermarkText = strings[ui.status];

props.watermarkVisibility = true;

props.watermarkFontColor = colors[ui.status];

doc.watermarkPreferences.properties = props;

}

else if ( uiCall == 2 ) {

doc.watermarkPreferences.watermarkVisibility = false;

}

}

main();

Capture d’écran 2017-08-30 à 09.59.59.png

Translate
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 ,
Aug 30, 2017 Aug 30, 2017

You are welcome.

Can you show your code?

Its better way that someone can know what you doing and find incorrect coding.

Translate
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
Mentor ,
Aug 30, 2017 Aug 30, 2017

Exactly

Translate
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
New Here ,
Sep 06, 2017 Sep 06, 2017

My journey so far has lead me to this script. (Below). Like most people stating out, it'll be 5 times longer and badly written, but it's a start. I'll attempt to attach a couple of screen grabs of what I have and what I'l like.

I just can't seem to add colours and another paragraph for my variable data information. Driving me mental.

So I thought I'd ask the people that know. Any help would be appreciated.

Cheers

(F)

Draft Stamp-What I

Draft Stamp-Where I am.png

-----------------------------------------------

Main();

// If you want the script to be un-doable, comment out the line above, and remove the comment from the line below

//app.doScript(Main, undefined, UndoModes, ENTIRE_SCRIPT, "Run Script");

function Main() {

  //Check to see whether any InDesign documents are open.

  // If no documents are open, display an error message.

    if (app.documents.length > 0) {

        var myDoc = app.activeDocument;

       

       // var myDraftLayer = myDoc.layers.add();

       

// DRAFT start

  var myDraftText = "DRAFT";

                myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;

                myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

        var myTextFrame = myDoc.textFrames.add();

            myTextFrame.geometricBounds = [30, 10, 80, 90];

            myTextFrame.contents = myDraftText;

            myTextFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;

            myTextFrame.bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.topLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.topRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.strokeColor = ("Black");

            myTextFrame.strokeWeight = ("10");

            myTextFrame.absoluteRotationAngle = 10;

        var myText = myTextFrame.paragraphs[0];

            myText.appliedFont = app.fonts.item("Arial");

            myText.fontStyle = "Bold";

            myText.justification = Justification.centerAlign;

            myText.pointSize = 40;

// DRAFT end

// PRINT start

        var myPrintText = "SENT TO PRINT";

                myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;

                myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

        var myTextFrame = myDoc.textFrames.add();

            myTextFrame.geometricBounds = [90, 10, 150, 90];

            myTextFrame.contents = myPrintText;

            myTextFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;

            myTextFrame.bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.topLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.topRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.strokeColor = ("Black");

            myTextFrame.strokeWeight = ("10");

            myTextFrame.absoluteRotationAngle = 10;

        var myText = myTextFrame.paragraphs[0];

            myText.appliedFont = app.fonts.item("Arial");

            myText.fontStyle = "Bold";

            myText.justification = Justification.centerAlign;

            myText.pointSize = 40;

// PRINT end

       

// FINAL start           

        var myFINALText = "FINAL";

            myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;

            myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

        var myTextFrame = myDoc.textFrames.add();

            myTextFrame.geometricBounds = [160, 10, 210, 90];

            myTextFrame.contents = myFINALText;

            myTextFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;

            myTextFrame.bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.topLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.topRightCornerOption = CornerOptions.ROUNDED_CORNER;

            myTextFrame.strokeColor = ("Black");

            myTextFrame.strokeWeight = ("10");

            myTextFrame.absoluteRotationAngle = 10;

        var myText = myTextFrame.paragraphs[0];

            myText.appliedFont = app.fonts.item("Arial");

            myText.fontStyle = "Bold";

            myText.justification = Justification.centerAlign;

            myText.pointSize = 40;

// FINAL end

  }

    else {

    // No documents are open, so display an error message.

  alert("No InDesign documents are open. Please open a document and try again.");

  }

}

---------------------------------------------------

Translate
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
Mentor ,
Sep 06, 2017 Sep 06, 2017

Hi,

Exam below code.

It is not a final solution but a suggested way to reach the current (your code) goal:

Main();

function Main() {

    if (!app.documents.length) {

        alert("No InDesign documents are open. Please open a document and try again.");

        exit();

        }

    //  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    var

        myDoc = app.activeDocument,

        inputArray =[

            ["DRAFT", [30, 10, 80, 90] ],

            ["SENT TO PRINT", [90, 10, 150, 90] ],

            ["FINAL", [160, 10, 210, 90] ]

            ],

        currentFrame, step;

    //  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||      

    myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;

    myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

    for (step = 0; step < inputArray.length; step++) {

        currentFrame = createFrame(inputArray[step]);

        formatFrame(currentFrame);

        }

    //  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    function createFrame (cProp)

    {

        var myTextFrame = myDoc.textFrames.add();

        with (myTextFrame) {

            geometricBounds = cProp[1];

            contents = cProp[0];

            bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;

            topLeftCornerOption = CornerOptions.ROUNDED_CORNER;

            topRightCornerOption = CornerOptions.ROUNDED_CORNER;

            strokeColor = myDoc.swatches.item("Red");

            strokeWeight = "10";

            absoluteRotationAngle = 10;

            textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;

            }

        return myTextFrame;

        }

    //  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    function formatFrame (cFrame)

    {

        var

            mFont = app.fonts.item("Arial"),

            mStyle = "Bold",

            mJust = Justification.centerAlign;

            mBigSize = 40,

            mSmallSize = 18,

            mData = new Date().toLocaleString();

          

            cFrame.contents += "\r" + mData;

            cFrame.parentStory.paragraphs[0].properties = {

                appliedFont: mFont,

                fontStyle: mStyle,

                justification: mJust,

                pointSize: mBigSize,

                fillColor: myDoc.swatches.item("Red")

                }

            cFrame.parentStory.paragraphs[1].properties = {

                appliedFont: mFont,

                fontStyle: mStyle,

                justification: mJust,

                pointSize: mSmallSize,

                fillColor: myDoc.swatches.item("Red")

                }

        }

}

My advice:

if some part of code is going to be run many times with different data - do it and create a function.

Jarek

Translate
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
New Here ,
Sep 06, 2017 Sep 06, 2017

Thanks Jump_Over

Your script functions the way I'd like, which is great, thank you! Also your code is very different to mine. Your obviously a seasoned pro... where as I am neither seasoned, or a pro!

One issue, is that the "Red" colour doesn't seem to work. It showed an error, so I changed it to "Black" and it worked. Ideally I'd like this as a 'Pantone Spot colour' Red 032 if possible?

And if possible, could the date be set, Day / Month / Year (e.g. 06 September 2017), nothing else, no time etc.?

I realise I'm being picky, but those are the only things that are stopping it from being perfect. Your input is much appreciated.

Cheers

(F)

Translate
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
Mentor ,
Sep 07, 2017 Sep 07, 2017

Hi,

In case of colors - It should work with every swatch name pasted from Swatch Panel (if proper doc is activated).

In case od Date - I recommend to use Object Model which gives you all control:

ExtendScript API

so if your var mDate = new Date()

you can i.e. use method

mDate.toLocaleDateString()     //     returns a string without time whitch can be splitted, cut, reordered

or play with

mDate.getDay(), mDate.getFullYear(), etc      //     to get a part of desired string

Jarek

Translate
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
New Here ,
Sep 07, 2017 Sep 07, 2017

Thanks for your reply Jarek. I'm sure what you added is great, but I'm of such a low level, that I don't know what to do with your info, where to add it to my script or how to troubleshoot the issues.

I'll leave it here for now as I've used up more of your time than is polite. Again, thanks for your input thus far. I think I need to go away and learn lots more before embarking on javascripts projects. If and when I come unstuck, I'll be sure to post on this forum.

Thanks

(F)

Translate
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 ,
Aug 30, 2017 Aug 30, 2017

frasermckie  wrote

… It's a basic red stroked (5pt), rounded cornered (5mm) text box (100mm wide x 70mm high) with the word 'DRAFT' in large red type and a modification date (insert variable text field) below in smaller red type. …

Hi,

using InDesign's watermark functionality like Loic is showing may be not the thing you want because it lacks nearly all features you described in your first post. And it is document wide and cannot be varied page by page, spread by spread or section by section.

Your "Draft Stamps" could be "normal" InDesign text frames you are designing with unique names.
On an extra layer perhaps. All three versions. All invisible. A script with a basic UI where page ranges can be added would duplicate them to the appropriate pages and make them visible.

Regards,
Uwe

Translate
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
People's Champ ,
Sep 06, 2017 Sep 06, 2017

Given all Dom operations here, wouldn't that be easier to work with snippets ? You do them as wanted, place them and eventually change date right away.

FWIW

Loic

var main = function() {

var doc = app.properties.activeDocument;

var snippet = File ( Folder.desktop+"/snippet.idms" );

if ( !doc ) {

alert("Need some open documents" );

return;

}

if ( !snippet.exists ) {

alert("Couldn't find snippet !" );

return;

}

var ui = UI();

if ( !ui.show() ) return;

snippet = doc.layoutWindows[0].activePage.place ( snippet )[0];

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = "##mention##";

app.changeTextPreferences.changeTo = ui.mention;

snippet.changeText();

var date = new Date();

app.findTextPreferences.findWhat = "##date##";

app.changeTextPreferences.changeTo = date.toLocaleDateString();

snippet.changeText();

}

var UI = function() {

var

u,

w= new Window("dialog"),

ls = w.add('dropdownlist', u,["Draft", "Sent to production", "PDF Generated"] ),

btnGp = w.add('group'),

koBtn = btnGp.add("button",u,"Cancel" ),

okBtn = btnGp.add("button",u,"Add" );

ls.selection = 0;

w.preferredSize.width = 300;

w.alignChildren = btnGp.alignChildren = ["fill","top"];

koBtn.onClick = function(){ w.close(0) };

okBtn.onClick = function(){ w.close(1) };

ls.onChange = function() {

w.mention = ls.selection.text;

}

w.mention = ls.selection.text;

return w;

}

var u;

app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

The Snippet

Capture d’écran 2017-09-06 à 20.43.01.png

Capture d’écran 2017-09-06 à 20.43.05.png

Of course it lays on a shared ressource but in worst case, the xml string may be included in the script.

Translate
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
New Here ,
Sep 06, 2017 Sep 06, 2017

Thanks for your reply and idea. Yes, the snippet idea will work, but I was looking for a simple double click solution without any added steps or date changes (lazy, I know!). I also work across InDesign 5.5 up to CC 2107, and have encountered issues, hence my quest for a common cross version ID script.

Jump_Over has come up with a good script, that with a couple of tweaks could be the one. The colour issue does seems to be the thing I can't get right, or maybe its an CC 2017 clash?

Thanks for your reply and input. Appreciated.

(F)

Translate
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
Enthusiast ,
Sep 08, 2017 Sep 08, 2017

Hello Loic.Aigon,


I have two short questions about your approach:


- Can you explain the "/snippet.idms"?

- the block script on the line "snippet = doc.layoutWindows [0] .activePage.place (snippet) [0];"


thank you very much

-------

Bonjour Loic.Aigon​,

J'ai deux petite questions sur ton approche  :

- Peux-tu expliqué le "/snippet.idms" ?

- le script bloc sur la ligne "snippet = doc.layoutWindows[0].activePage.place ( snippet )[0]; "

merci beaucoup

Translate
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
Enthusiast ,
Sep 08, 2017 Sep 08, 2017

Ok Loic.Aigon​,

"Extrait InDesign" ... Magnifique !!!

Translate
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
People's Champ ,
Sep 08, 2017 Sep 08, 2017
LATEST

Liphou

- Can you explain the "/snippet.idms"?

Yes it's a reference to an indesign snippet ( aka extrait in french)

- le script bloc sur la ligne "snippet = doc.layoutWindows[0].activePage.place ( snippet )[0]; "

doc is the active document

layoutWindows the collection of windows for that document.

layoutWindows[0] the first item in the collection (meaning the active one)

activePage will return the page the user actually works on

place is the method that will allow placing an external file. This returns an array of placed objects.

so …place()[0] will return the first placed item.

HTH

Loic

Translate
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