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

Add "bleed size" to script...

Explorer ,
May 11, 2017 May 11, 2017

Copy link to clipboard

Copied

Here's the script. How do i add a "bleed size" variable to it?

// https://forums.adobe.com/thread/2049382 

// Main script by Loic Aigon Add highly customized Text Variables to InDesign | Ozalto 

// Additions (First Page Dimensions and variable update on script execution) 

// and modifications (without permission, sorry Loic) by Trevor http://www.creative-scripts.com 

#targetengine 'usernameVariable' 

 

//This function adds static text variables in InDesign 

//They won't be dynamically updated though. 

//That's why we need the updating function below 

 

function toTitleCase(s) { // By Trevor 

    return s.toLowerCase().replace(/\b\w/g, function () {return arguments[0].toUpperCase()}); 

 

function myRound(thisNumber, digits) { // By Trevor 

        digits = (digits) ? Math.pow(10, digits) : 1000; 

        return Math.round(thisNumber * digits) / digits; 

 

function addVariables(openEvent){ 

    if (!openEvent) return; 

    var doc = (openEvent.constructor == Document) ? openEvent : openEvent.parent; // By Trevor 

    while ( doc.constructor.name != "Document" ) 

    { 

        if ( doc.constructor.name == "Application" ){ return; } 

 

       doc = doc.parent; 

    } 

 

    //Adding User name to text variables 

    createTextVariable(doc, "User name", $.getenv($.os[0] == "M" ? "USER" : "username") ); // changed by Trevor 

    //Adding Computer name to text variables 

    createTextVariable(doc, "HD Name", (Folder.system).parent.displayName ); 

 

    //Adding Computer name to text variables 

    createTextVariable(doc, "Computer Name", getComputerName() ); 

 

    //Adding a link to my website 

    createTextVariable(doc, "_About Loic Aigon", "Feel free to visit my website: http://www.loicaigon.com !" ); 

 

    //Adding a link to my website 

    createTextVariable(doc, "_About Trevor", "Feel free to visit my website: http://www.creative-scripts.com !" ); // by Trevor 

 

    //Adding First Page Dimensions 

    createTextVariable(doc, "First Page Dimensions", getPageDimentions(doc.pages[0])); // by Trevor 

 

 

addVariables(app.properties.activeDocument); // callback by Trevor 

 

//Generic function to add static custom text variables 

function createTextVariable(target, variableName, variableContents){ 

 

    var usernameVariable = target.textVariables.itemByName(variableName); 

    if(!usernameVariable.isValid){ 

        usernameVariable = target.textVariables.add(); 

        usernameVariable.variableType = VariableTypes.CUSTOM_TEXT_TYPE; 

        usernameVariable.name = variableName; 

    } 

    usernameVariable.variableOptions.contents = variableContents; 

 

 

//Snippet for grabbing the  deep name of the computer 

function getComputerName(){ // by Trevor 

    return $.os[0] == "M" ? app.doScript("get computer name of (system info)", ScriptLanguage.APPLESCRIPT_LANGUAGE) : $.getenv("computername"); 

 

function getPageDimentions(page){ // by Trevor 

    var width, height, bounds, units, decPlaces; 

    // function presumes that normal pages 

    // i.e. same vertical and horizontal and no page shape transformations 

    decPlaces = 3; 

    units = toTitleCase(page.parent.parent.viewPreferences.horizontalMeasurementUnits.toString()); // If you forgot to include the toTitleCase function then remove the method 

    bounds = page.bounds; 

    height = bounds[2] - bounds[0]; 

    height = myRound(height, decPlaces); 

    width = bounds[3] - bounds[1]; 

    width = myRound(width, decPlaces); 

    return width + " X " + height + " " + units 

 

//Add listeners to update file when opened. 

app.addEventListener('afterOpen', addVariables); 

// You might like to add some or all of these to make the update better 

app.addEventListener('beforeSave', addVariables); // by Trevor 

app.addEventListener('beforeSaveAs', addVariables); // by Trevor 

app.addEventListener('beforeSaveACopy', addVariables); // by Trevor 

app.addEventListener('beforeExport', addVariables); // by Trevor 

app.addEventListener('beforePrint', addVariables); // by Trevor 

app.addEventListener('beforeDeactivate', addVariables); // by Trevor 

app.addEventListener('afterActivate', addVariables); // by Trevor

TOPICS
Scripting

Views

3.0K

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 ,
May 11, 2017 May 11, 2017

Copy link to clipboard

Copied

Hi,

you define bleed in the documentPreferences.

// Active document:

var doc = app.documents[0];

// Change uniform bleed size:

doc.documentPreferences.properties =

{

    documentBleedUniformSize : true ,

    documentBleedTopOffset : "3 mm"

};

See DOM documentation for properties of non uniform bleed sizes:

Adobe InDesign CS6 (8.0) Object Model JS: DocumentPreference

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
Explorer ,
May 12, 2017 May 12, 2017

Copy link to clipboard

Copied

Hi, Uwe. Thank you for the script, but i appologize, i did not ask the question correctly. I have a slug in Indesign that pulls document information into text variables like "page dimensions", "filename", "Date", etc. I was looking to add to the script to enable another variable that picks up the "Page Bleed Size" from the "Document Setup" menu.

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 Beginner ,
Dec 14, 2017 Dec 14, 2017

Copy link to clipboard

Copied

Did you ever find a solution to this?

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 25, 2018 Jan 25, 2018

Copy link to clipboard

Copied

Hi attil ,

as I said you'll get this information from the documentPreferences.

Simply first look after:

documentBleedUniformSize

if that returns true, read the value for documentBleedTopOffset and either add that directly to the text frame in the slug or do another createTextVariable() and another addTextVariable() for bleed.

If it returns false you have to read out all four properties for bleed as listed here:

documentBleedBottomOffset,

documentBleedInsideOrLeftOffset,

documentBleedOutsideOrRightOffset and

documentBleedTopOffset

and repeat the prescription I gave above.

Boiler plate code is waiting here:

Re: I need to add in a page size text variable to my already working .jsx script

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
Explorer ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

Sorry for asking, but what would the final code look like?

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 Beginner ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

LATEST

The following works for me. Keep in mind that I always set a uniform bleed so grabbing top offset gives me the same value as bleeds for left, right and bottom.

var myDocument = app.documents[0];

var bleed = myDocument.documentPreferences.properties.documentBleedTopOffset;

alert ("bleed = " + bleed);

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