Forum Replies Created
-
AuthorPosts
-
Oleh Melnyk
Memberapp.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 nameOleh Melnyk
Memberline 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
Oleh Melnyk
MemberOleh 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/57ef6cc65801329c22ec3c91b53cfe01Oleh Melnyk
MemberHow you mark your addresses? Do they have some Character/Paragraph style applied?
Oleh Melnyk
Memberlooks like this is InDesign bug – sometimes it works, sometimes it doesn’t, and then – random results all the time
Oleh Melnyk
Membercheck this script version with my InDesign test files – https://www.dropbox.com/s/nrb6me33sbtn9wg/MoveObjects2Layer.zip?dl=0
Oleh Melnyk
MemberHere’s initial version of the script:
https://www.dropbox.com/s/p788kiqhscyb5o5/Google%20Maps%20-%20get%20map%20URL.jsx?dl=0WARNING: 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 panelKnown issues:
– if there are more than one instances of the same address – the second and all other instances will cause a script errorOleh Melnyk
MemberWeird! 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=0Oleh Melnyk
MemberKai, 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
Oleh Melnyk
MemberWell, 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 documentOleh Melnyk
MemberOk, 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=0Oleh Melnyk
MemberAaron, do all objects are text frames?
It would be easier if you could share your .indd fileOleh Melnyk
MemberStrange, 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)
Oleh Melnyk
Memberthere 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 oftry 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
-
AuthorPosts
