Back

If your email is not recognized and you believe it should be, please contact us.

Forum Replies Created

Viewing 15 posts - 46 through 60 (of 91 total)
  • Author
    Posts
  • in reply to: Object Layer Options Scripting #60704

    I need more information to solve the problem: a screenshot or detailed description of the error. Ideally, I'd like to get a sample file so I could test the script against it.

    in reply to: Resize selected line height / spacing #60703

    I don't know why you might want to do this by script, but here it is:

    Main();

    function Main() {
    if (app.documents.length == 0) {
    alert (“Please open a document, select some text, and try again.”);
    exit();
    }
    else if (app.selection.length > 1 || app.selection[0].hasOwnProperty(“baseline”) == false) {
    alert (“Please select some text, and try again.”);
    exit();
    }

    var the_document = app.documents[0];
    var the_selection = app.selection[0];

    var the_dialog = app.dialogs.add({name:”Change leading in the selected text”});
    with(the_dialog.dialogColumns.add()){
    with(dialogRows.add()){
    staticTexts.add({staticLabel:”Change leading in the selected text by”});
    var increase_by = measurementEditboxes.add({editUnits:MeasurementUnits.POINTS, editValue:0});
    }
    }
    var dialog_result = the_dialog.show();

    if (dialog_result) {
    if (the_selection.leading != Leading.AUTO) {
    the_selection.leading = the_selection.leading + increase_by.editValue;
    }
    else {
    the_selection.leading = (the_selection.pointSize * (the_selection.autoLeading/100)) + increase_by.editValue;
    }
    }
    }

    Written in CS5.5, Windows.

    Warning: it's not totally tested — just a quick exercise in scripting before going to bed.

    Make sure that Preferences > Type > Apply Leading to Entire Paragraphs should be off.

    Regards,
    Kasyan

    in reply to: Resize graphic frames with an Object style applied #60626

    Hi Mike,

    What version of InDesign are you on? I guess you're on CS3.

    It's always a good idea to specify the InDesign version and the platform — Mac or PC — for which you want the script.

    Let's try to replace

    if (objStyle.isValid) {

    with

    if (objStyle != null) {

    to make it compatible with CS3.

    Regards,
    Kasyan

    in reply to: Resize graphic frames with an Object style applied #60619

    Hi Dave,

    I have a suggestion: the new forum software should provide for possibility to post code. In the code I posted, backslashes have been removed before the quotes surrounding the CarImage in the line 24, which will result in error in case the object style doesn't exist in the document.

    The line should have been be like so:

    alert(“Object style [backslash]“CarImage[backslash]” doesn't exist”);

    Formerly I tried to enclose the code in

    tag in the HTML source editor, but this didn't help.

    Regards,
    Kasyan

    in reply to: Resize graphic frames with an Object style applied #60615

    Oops! My fingers work faster than my brain. Unfortunately I can't edit the post!

    Here's a new version:

    Main();

    function Main() {
    var frame, gb, gb_new;
    if (app.documents.length > 0) {
    var doc = app.activeDocument;
    var objStyle = doc.objectStyles.item(“CarImage”);
    if (objStyle.isValid) {
    doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
    doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

    var objPref = app.findObjectPreferences;
    objPref.appliedObjectStyles = objStyle;
    var found = doc.findObject();

    for (var i = 0; i < found.length; i++) {
    frame = found[i];
    gb = frame.geometricBounds;
    gb_new = [ gb[0], gb[1], gb[0]+13, gb[1]+26 ];
    frame.geometricBounds = gb_new;
    }
    }
    else {
    alert(“Object style “CarImage” doesn't exist”);
    }
    }
    else {
    alert(“No open documents.”);
    }
    }

    in reply to: Resize graphic frames with an Object style applied #60614

    Forgot to add var in the following lines:

    var frame = found[i];
    var gb = frame.geometricBounds;
    var gb_new = [ gb[0], gb[1], gb[0]+13, gb[1]+26 ];

    in reply to: Resize graphic frames with an Object style applied #60613

    Main();

    function Main() {
    if (app.documents.length > 0) {
    var doc = app.activeDocument;
    var objStyle = doc.objectStyles.item(“CarImage”);
    if (objStyle.isValid) {
    doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
    doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;

    var objPref = app.findObjectPreferences;
    objPref.appliedObjectStyles = objStyle;
    var found = doc.findObject();

    for (var i = 0; i < found.length; i++) {
    frame = found[i];
    gb = frame.geometricBounds;
    gb_new = [ gb[0], gb[1], gb[0]+13, gb[1]+26 ];
    frame.geometricBounds = gb_new;
    }
    }
    else {
    alert(“Object style “CarImage” doesn't exist”);
    }
    }
    else {
    alert(“No open documents.”);
    }
    }

    in reply to: Object Layer Options Scripting #60612

    Main();

    function Main() {
    var page, placedFile, graphics, i, j,
    doc = app.activeDocument,
    pages = doc.pages;

    for (i = 0; i < pages.length; i++) {
    page = pages[i];
    var graphics = page.allGraphics;
    for (j = graphics.length-1; j >= 0; j–) {
    placedFile = page.allGraphics[j];
    if (placedFile.constructor.name == “ImportedPage” && placedFile.itemLink.linkType == “InDesign Format Name”) {
    try {
    placedFile.graphicLayerOptions.graphicLayers.item(“Frames”).currentVisibility = false;
    }
    catch (err) {}
    }
    }

    }

    alert(“Done”);
    }

    P.S. Written in InDesign CS5.5, Windows.

    Hope this helps.

    Kasyan

    in reply to: CS 5.5 – Print paragraph styles… #60573

    Recently I wrote a similar script. It creates a list of all paragraph styles and character styles in the active document, showing the font, font size and leading. Saves the result in a csv-file which is automatically opened in Excel.

    in reply to: Batch converting Indesign files to PDF #60116

    Hi Blondie,

    Yes, Peter's script has some issues but it's impossible to fix it because it is posted in binary format (the author doesn't want anybody ti meddle with code).

    Today, while drinking my morning coffee, I wrote this script. It takes all indd-files from the selected folder and its subfolders and exports each file to pdf-format saving them in the 'Pdf' folder which is created by script. Note that there is possibility that in different subfolders can be files with identical names. The script handles this situation: it adds a sequential number to the file name so it never gets overwritten. For example: SomeFile.pdf, SomeFile.pdf(1), SomeFile.pdf(2) and so on.

    For better performance the script doesn't display documents being opened and closed, but the progress bar shows which file is being processed, how many files have already been processed.

    I haven't totally tested it yet — it's already time for me to go to my work — so probably I'll make some changes to it.

    Hope this helps.

    Regards,
    Kasyan

    // Script for InDesign CS3-5.
    // July 22 2011
    // Written by Kasyan Servetsky
    // https://www.kasyan.ho.com.ua
    // e-mail: askoldich@yahoo.com
    //======================================================================================
    var gScriptName = “Batch export INDD-files to PDF”; // Name of the script
    var gScriptVersion = “1.0”; // Version

    var gSet = GetSettings();
    CreateDialog();

    //===================================== FUNCTIONS ======================================
    function CreateDialog() {
    var pdfPresetsList =app.pdfExportPresets.everyItem().name;
    var win = new Window(“dialog”, gScriptName + ” – ” + gScriptVersion);

    win.p = win.add(“panel”, undefined, “”);
    win.p.alignChildren = “right”;
    win.p.alignment = “fill”;

    win.p.g = win.p.add(“group”);
    win.p.g.st = win.p.g.add(“statictext”, undefined, “PDF-presets:”);
    win.p.g.ddl = win.p.g.add(“dropdownlist”, undefined, pdfPresetsList);
    win.p.g.ddl.selection = gSet.selectedPdfPresetIndex;
    win.p.g.ddl.preferredSize.width = 220;

    win.buttons = win.add(“group”);
    win.buttons.orientation = “row”;
    win.buttons.alignment = “center”;
    win.buttons.ok = win.buttons.add(“button”, undefined, “OK”, {name:”ok” });
    win.buttons.cancel = win.buttons.add(“button”, undefined, “Cancel”, {name:”cancel”});

    var showDialog = win.show();

    if (showDialog == 1) {
    gSet.selectedPdfPresetIndex = win.p.g.ddl.selection.index;
    app.insertLabel(“Kas_” + gScriptName + gScriptVersion, gSet.toSource());
    Main();
    }
    }
    //——————————————————————————————————————————————————–
    function Main() {
    var folder = Folder.selectDialog(“Select a folder with InDesign files to resave”);
    if (folder == null) exit();
    var files = GetFiles(folder);
    var pdfFolder = new Folder(folder.fsName + “/” + “Pdf”);
    VerifyFolder(pdfFolder);

    if (files.length == 0) {
    alert(“No files to open.”, gScriptName + ” – ” + gScriptVersion);
    exit();
    }

    var pdfPresets =app.pdfExportPresets.everyItem().getElements();
    var selectedPdfPreset = pdfPresets[gSet.selectedPdfPresetIndex];
    var count = 1;
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

    // Progress bar ———————————————————————————–
    var progressWin = new Window (“window”, gScriptName + ” – ” + gScriptVersion);
    var progressBar = progressWin.add (“progressbar”, [12, 12, 350, 24], 0, files.length);
    var progressTxt = progressWin.add(“statictext”, undefined, “Starting exporting files”);
    progressTxt.bounds = [0, 0, 340, 20];
    progressTxt.alignment = “left”;
    progressWin.show();
    // Progress bar ———————————————————————————–

    for (var i = 0; i < files.length; i++) {
    var currentFile = files[i];

    try {
    var doc = app.open(currentFile, false);
    var docName = doc.name;

    // Progress bar ———————————————————————————–
    progressBar.value = count;
    progressTxt.text = String(“Exporting file – ” + docName + ” (” + count + ” of ” + files.length + “)”);
    // Progress bar ———————————————————————————–

    var file = new File(pdfFolder + “/” + GetFileName(docName) + “.pdf”);
    if (file.exists) {
    var increment = 1;
    while (file.exists) {
    file = new File(pdfFolder + “/” + GetFileName(docName) + “(” + increment++ + “).pdf”);
    }
    }

    doc.exportFile(ExportFormat.pdfType, file, false, selectedPdfPreset);
    doc.close(SaveOptions.NO);
    count++;
    }
    catch(e) {}
    }

    // Progress bar ———————————————————————————–
    progressWin.close();
    // Progress bar ———————————————————————————–

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

    alert(“Done.”, gScriptName + ” – ” + gScriptVersion);
    }
    //——————————————————————————————————————————————————–
    function VerifyFolder(folder) {
    if (!folder.exists) {
    var folder = new Folder(folder.absoluteURI);
    var array1 = new Array();
    while (!folder.exists) {
    array1.push(folder);
    folder = new Folder(folder.path);
    }
    var array2 = new Array();
    while (array1.length > 0) {
    folder = array1.pop();
    if (folder.create()) {
    array2.push(folder);
    } else {
    while (array2.length > 0) {
    array2.pop.remove();
    }
    throw “Folder creation failed”;
    }
    }
    }
    }
    //——————————————————————————————————————————————————–
    function GetFiles(theFolder) {
    var files = [],
    fileList = theFolder.getFiles(),
    i, file;

    for (i = 0; i < fileList.length; i++) {
    file = fileList[i];
    if (file instanceof Folder) {
    files = files.concat(GetFiles(file));
    }
    else if (file instanceof File && file.name.match(/.indd$/i)) {
    files.push(file);
    }
    }

    return files;
    }
    //——————————————————————————————————————————————————–
    function GetFileName(fileName) {
    var string = “”;
    var result = fileName.lastIndexOf(“.”);
    if (result == -1) {
    string = fileName;
    }
    else {
    string = fileName.substr(0, result);
    }
    return string;
    }
    //——————————————————————————————————————————————————–
    function GetSettings() {
    var set = eval(app.extractLabel(“Kas_” + gScriptName + gScriptVersion));
    if (set == undefined) {
    set = { selectedPdfPresetIndex : 0 };
    }

    return set;
    }
    //——————————————————————————————————————————————————–

    in reply to: find text and get the page it is on #60093

    I wrote this in desktop version of InDesign so that to demonstrate my approach. Alerts will not work in InDesign server.

    in reply to: find text and get the page it is on #60092

    Hi Simon,

    Here is a simple example:

    var doc = app.activeDocument;
    // clear find change text preferences before search
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
    // this is scripting equivalent of the 'Find What:' edit text field
    app.findTextPreferences.findWhat = “text”;
    // search it in the active document
    // you can also search it in almost everywhere: story, text frame, paragraph, line, word, etc
    var finds = doc.findText();
    if (finds.length > 0) { // something has been found
    // for the 1st found item display the name of the page where the 1st text frame (there can be several threaded frames) containing it is located
    alert(“Found ” + finds.length + ” items, the first of them is on page ” + finds[0].parentTextFrames[0].parentPage.name);
    }
    else { // found nothing
    alert(“Nothing has been found”);
    }
    // clear find change text preferences after search
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

    Hope this helps.
    Kasyan

    in reply to: Can InDesign be scripted to load shortcuts workspaces? #59872

    There's one more method: applyMenuCustomization (“namehere”); which applies the specified menu customization set.

    Actually, you can do by script almost everything you can do manually in InDesign. I recommend you to download an InDesign scripting reference by Jongware where you can find all information about the objects their properties and methods (commands).

    in reply to: Can InDesign be scripted to load shortcuts workspaces? #59827

    Oops! I'm sorry for the confusion. I still work mostly in CS3, but the applyShortcutSet method is available only in CS5. How could I miss it? It's just one line above the applyWorkspace which I mentioned in my previous post. Thank you for correcting me, John.

    in reply to: Can InDesign be scripted to load shortcuts workspaces? #59816

    You can apply a workspace like so:

    app.applyWorkspace(“Advanced”);

    However, as far as I know, it's impossible to load shortcuts by script.

    Kas

Viewing 15 posts - 46 through 60 (of 91 total)