Back

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

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 41 total)
  • Author
    Posts
  • in reply to: Script to import partial filename #14323304
    Oleh Melnyk
    Member

    app.activeDocument.name[2] // should return 3rd character of the file name (zero-based index)
    app.activeDocument.name[4] // should return 5th character of the file name

    in reply to: Script to import partial filename #112796
    Oleh Melnyk
    Member

    line 35 – change:
    if (confirm(“Do you want to replace ” + foundContents + ” with ” + fileNameVariable, false, “Replace?”)) {

    to:
    if (foundContents !== changeTo && confirm(“Do you want to replace ” + foundContents + ” with ” + fileNameVariable, false, “Replace?”)) {

    https://gist.github.com/olehmelnyk/57ef6cc65801329c22ec3c91b53cfe01

    in reply to: Script to import partial filename #112752
    Oleh Melnyk
    Member
    in reply to: Script to import partial filename #112724
    Oleh Melnyk
    Member

    @scott-rudy I’m not sure I understood what you want to achieve with the script, but try this:
    https://gist.github.com/olehmelnyk/57ef6cc65801329c22ec3c91b53cfe01

    in reply to: Street Address Hyperlink #103539
    Oleh Melnyk
    Member

    How you mark your addresses? Do they have some Character/Paragraph style applied?

    in reply to: Object Style to New Layer #103559
    Oleh Melnyk
    Member

    looks like this is InDesign bug – sometimes it works, sometimes it doesn’t, and then – random results all the time

    in reply to: Object Style to New Layer #103551
    Oleh Melnyk
    Member

    check this script version with my InDesign test files – https://www.dropbox.com/s/nrb6me33sbtn9wg/MoveObjects2Layer.zip?dl=0

    in reply to: Street Address Hyperlink #103541
    Oleh Melnyk
    Member

    Here’s initial version of the script:
    https://www.dropbox.com/s/p788kiqhscyb5o5/Google%20Maps%20-%20get%20map%20URL.jsx?dl=0

    WARNING: this script is in early stage and might not work properly, so save before using this script!

    Usage:
    – Create character style named “Address”
    – Apply it to text that contains address you want to point to
    – Run this script
    – Check Hyperlinks panel

    Known issues:
    – if there are more than one instances of the same address – the second and all other instances will cause a script error

    in reply to: Object Style to New Layer #103538
    Oleh Melnyk
    Member

    Weird! I got an opposite issue while iterating backward.

    I added “proceed until you bleed” while-loop that tries to move objects to the desired layer (1000 tries) – now it should work, lol
    https://www.dropbox.com/s/r4dj5qktplewm7p/Move%20Object%20with%20Selected%20ObjectStyle%20to%20Layer%20v3.jsx?dl=0

    in reply to: Object Style to New Layer #103535
    Oleh Melnyk
    Member

    Kai, when I loop backward, I got the same problem Aaron has – some object moves to a new layer and some don’t so I have to run the script multiple times… ?
    I don’t think loop backward can solve this problem since script didn’t store order, page number, or folder then move the object to new page/folder/whatever might matters for loop order – script just iterate over every element in opened document, check if object has applied object style, and if that object is not in the desired layer – script just moves object to new layer…

    New version should work with locked layers/objects https://www.dropbox.com/s/knh502mk9uxjipg/Move%20Object%20with%20Selected%20ObjectStyle%20to%20Layer%20v2.jsx?dl=0

    in reply to: Object Style to New Layer #103523
    Oleh Melnyk
    Member

    Well, I have no idea what might cause this problem. In file you sent me – everything works once I rename, or just open and close “Layer options” dialog (all text frames moves to ‘Index’ layer).
    Maybe your InDesign file is corrupted?
    Have you tried to save it as .idml (for CS4 and later versions), then open this .idml file – this might help to fix some errors.
    Have you tried a new script version?
    Otherwise, it’s hard to guess – need try script with real InDesign document

    in reply to: Object Style to New Layer #103520
    Oleh Melnyk
    Member

    Ok, this is weird! Looks like the problem is not with the script but with InDesign file, or to be more precise – with the layer name. Looks like “Index” is some sort of reserved word in InDesign, so all you need is to rename a layer, or at least – double-click on the layer name, so “Layer options” dialog opens – once it open, you can close this dialog and script should work ok… – Just try and let me know if it works!

    Meanwhile, I made some changes to initial script, so the new version should now work with all objects, not just text frames + now you can undo what script made in just one step.
    https://www.dropbox.com/s/uc8vmq878xwh4gf/Move%20Object%20with%20Selected%20ObjectStyle%20to%20Layer.jsx?dl=0

    in reply to: Object Style to New Layer #103508
    Oleh Melnyk
    Member

    Aaron, do all objects are text frames?
    It would be easier if you could share your .indd file

    in reply to: Script to import partial filename #92570
    Oleh Melnyk
    Member

    Strange, how the variable can be changed if “No documents are open” and script should execute after save?
    But I don’t know your workflow, maybe I am missing something…

    As for “if(app.eventListeners.length > 0)” – length should be 0 – we check if there are 2 event listeners – if so – we remove the old ones and then add 2 new listeners… After you changed it to 2 – there might be 2-4 listeners (2 old and 2 new), but if it works – let it be, lol

    No donation page, at least for now (still can’t accept PayPal in my country)

    in reply to: Script to import partial filename #92529
    Oleh Melnyk
    Member

    there are a lot of things that might cause the problems:
    1) you are getting SlugArea variable from the file name, but you are getting this BEFORE file is saved (so there might be wrong file name)
    2) you are trying to save document while script are working (getting and setting SlugArea variable) so saving is locked, which might cause the problem
    3) you create 2 new event handlers every time you run the script, and they ALL keep working till you remove them manually or till you restart InDesign (!!!) – so if you, for example, started script 5 times – on each “Save” or “Save As” 5 event handlers try to execute…at the same time…
    4) maybe something else I am not aware of

    try this:


    #target indesign;
    #targetengine “mysession”;

    // https://creativepro.com/topic/script-to-import-partial-filename#post-92526

    // every time you run the script you add 2 new event handlers - we need to remove the old ones
    try{
    if(app.eventListeners.length > 0){
    app.removeEventListener("afterSave", myHandler);
    app.removeEventListener("afterSaveAs", myHandler);
    }
    }catch(e){
    $.writeln(e);
    }

    // create "SlugArea" text variable (if it missing)
    if(!app.activeDocument.textVariables.item("SlugArea").isValid){
    app.activeDocument.textVariables.add({ variableType: VariableTypes.CUSTOM_TEXT_TYPE, name: "SlugArea"});
    }

    // set default value if varible is empty
    if(app.activeDocument.textVariables.item("SlugArea").isValid && app.activeDocument.textVariables.item("SlugArea").variableOptions.contents.length == 0){
    app.activeDocument.textVariables.item("SlugArea").variableOptions.contents = "SlugArea (default value)";
    }

    var myHandler = function(ev){
    var fileNameVariable = app.activeDocument.name.match(/[A-Z]{2,5}(?=)/)[0];

    // if we found what we were looking for
    if(typeof fileNameVariable == "string" && fileNameVariable.length > 2) {
    // set proper value for text variable...
    app.activeDocument.textVariables.item("SlugArea").variableOptions.contents = fileNameVariable;
    }
    }

    // since we generate SlugArea varibale from the file name - we need to do that AFTER file is saved, and its name was changed...
    app.eventListeners.add("afterSave", myHandler);
    app.eventListeners.add("afterSaveAs", myHandler);

    but you will have to re-save document (Ctrl + S / Cmd + S) manually after slug area is set

Viewing 15 posts - 1 through 15 (of 41 total)