Copy link to clipboard
Copied
Hey guys,
Could you please modify the script below to make it work across multiple docs? There are actually two scripts in this code (the second one starts at "function main() {" line). Would it be possible to merge them, so that it work in one go?
function main() {
var doc = app.activeDocument;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.pointSize = "6.5";
app.findGrepPreferences.tracking = 0;
app.findGrepPreferences.fillColor=app.swatches.item("Paper");
var found = doc.findGrep();
for (var i = 0; i < found.length; i++)
for (var j = 0; j < found[i].parentTextFrames.length; j++) {
var frame = found[i].parentTextFrames[j];
if (frame.isValid) {
frame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.CENTER_POINT;
frame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.WIDTH_ONLY;
}
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Autosizing');
function main() {
var doc = app.activeDocument;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.pointSize = "8.5";
app.findGrepPreferences.leading = "11";
var found = doc.findGrep();
for (var i = 0; i < found.length; i++)
for (var j = 0; j < found[i].parentTextFrames.length; j++) {
var frame = found[i].parentTextFrames[j];
if (frame.isValid) {
frame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.LEFT_CENTER_POINT;
frame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.WIDTH_ONLY;
}
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Autosizing');
Thanks in advace,
Rogerio
Copy link to clipboard
Copied
This one as well pls (same request). Thx!
function main() {
var doc = app.activeDocument;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.findObjectPreferences = NothingEnum.NOTHING;
app.changeObjectPreferences.insetSpacing = [ 8,10,8,10 ];
app.findObjectPreferences.insetSpacing = [ 8,10,8,10 ];
var found = doc.findObject();
for (var i = 0; i < found.length; i++)
found[i].texts[0].alignToBaseline = false;
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Unapply Baseline Grid To Target Frames');
function main() {
var doc = app.activeDocument;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.findObjectPreferences = NothingEnum.NOTHING;
app.changeObjectPreferences.insetSpacing = [ 5,5,5,5 ];
app.findObjectPreferences.insetSpacing = [ 5,5,5,5 ];
var found = doc.findObject();
for (var i = 0; i < found.length; i++)
found[i].texts[0].alignToBaseline = false;
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Unapply Baseline Grid To Target Frames');
Copy link to clipboard
Copied
For the next two, try the following
function setBaseLine(txtList){
for (var i = 0; i < txtList.length; i++)
txtList[i].texts[0].alignToBaseline = false;
}
function main() {
for (var i = 0; i < app.documents.length; i++) {
var doc = app.documents[i]
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
app.changeObjectPreferences = NothingEnum.NOTHING;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.changeObjectPreferences.insetSpacing = [ 8,10,8,10 ];
app.findObjectPreferences.insetSpacing = [ 8,10,8,10 ];
var found = doc.findObject();
setBaseLine(found)
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
app.changeObjectPreferences = NothingEnum.NOTHING;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.changeObjectPreferences.insetSpacing = [ 5,5,5,5 ];
app.findObjectPreferences.insetSpacing = [ 5,5,5,5 ];
var found = doc.findObject();
setBaseLine(found)
}
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
app.changeObjectPreferences = NothingEnum.NOTHING;
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Unapply Baseline Grid To Target Frames');
-Manan
Copy link to clipboard
Copied
Hi @Manan Joshi, thanks for the help! 🙂
I tested the above script, but not luck - it doesn't work across multiple documents.
I'm attaching two indd files here. Could you please give them a try?
Thanks,
Rogerio
Copy link to clipboard
Copied
Hi @Rogerio5C09,
Two things, one there was a bug in the code that we were setting the inset in mm but did not set the unit explicitly so it would have caused issues. Secondly there seem to be a bug in findObject method where it targets only the active document. This has been reported by @m1b in the following thread as well
If the api behaved fine the following code would do the trick
function setBaseLine(txtList){
for (var i = 0; i < txtList.length; i++)
txtList[i].texts[0].alignToBaseline = false;
}
function main() {
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS
for (var i = 0; i < app.documents.length; i++) {
var doc = app.documents[i]
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.findObjectPreferences.insetSpacing = [ 8,10,8,10 ];
var found = doc.findObject();
setBaseLine(found)
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.findObjectPreferences.insetSpacing = [ 5,5,5,5 ];
var found = doc.findObject();
setBaseLine(found)
}
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
};
main()
Seems we will have to log a bug with Adobe. We will carry the discussion on the bug in the thread I linked above.
-Manan
Copy link to clipboard
Copied
Thanks @Manan Joshi! I haven't had a chance to give it a try yet, but looks promising 🙂
Copy link to clipboard
Copied
Hi @Rogerio5C09,
Based on the discussion on the other thread, I have made a new version of the script which sets the activeDocument explicitly which can bypass the bug we are discussing. This seems to work for me
function setBaseLine(txtList){
for (var i = 0; i < txtList.length; i++)
txtList[i].texts[0].alignToBaseline = false;
}
function main() {
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS
for (var i = 0; i < app.documents.length; i++) {
app.activeDocument = app.documents[i]
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.findObjectPreferences.insetSpacing = [ 8,10,8,10 ];
var found = app.activeDocument.findObject();
setBaseLine(found)
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
app.findChangeObjectOptions.objectType = ObjectTypes.TEXT_FRAMES_TYPE;
app.findObjectPreferences.insetSpacing = [ 5,5,5,5 ];
var found = app.activeDocument.findObject();
setBaseLine(found)
}
app.findChangeObjectOptions = NothingEnum.NOTHING;
app.findObjectPreferences = NothingEnum.NOTHING;
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Unapply Baseline Grid To Target Frames');
-Manan
Copy link to clipboard
Copied
Hi @Manan Joshi, I gave it a try with 15 open docs, but no luck - the script is lopping over a few documents and then stops unexpectedly. Is there any way to make it loop over all the open documents? Thx!
Copy link to clipboard
Copied
Ok, so the few documents which you say got processed, did they get processed fine? Does it fail on a particular document? It could be that the code is crashing for some document. Try and figure out if it always fails on a particular document or set of documents
-Manan
Copy link to clipboard
Copied
dunno - I was tinkering with this but not quite right
This not my wheelhouse at all - but if it gives an idea then great.
Although this approach is probably more involved it might not be as efficient as using the findObject() method, wondering if this is a possible workaround.
function findObjects(doc) {
var objects = [];
// Iterate through all the page items in the document
for (var p = 0; p < doc.pages.length; p++) {
var page = doc.pages[p];
// Iterate through all the page items on the page
for (var i = 0; i < page.pageItems.length; i++) {
var item = page.pageItems[i];
// Perform your search criteria here
if (item instanceof TextFrame && item.fillColor === app.swatches.item("Paper")) {
objects.push(item);
}
}
}
return objects;
}
function main() {
for (var i = 0; i < app.documents.length; i++) {
var doc = app.documents[i];
// Call the custom findObjects() function to get the objects
var found = findObjects(doc);
// Process the found objects
for (var j = 0; j < found.length; j++) {
var obj = found[j];
// Perform further actions on the found objects
// ...
}
}
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Custom Object Search');
Copy link to clipboard
Copied
Hey @Eugene Tyson, thanks for that! I will give it a shoot and let you know. Have you tried to use this code with the two INDDs I shared with Manan already? Just wondering 🙂
Copy link to clipboard
Copied
Nope. I have not.
Copy link to clipboard
Copied
You don't have to iterate through pages and then objects on each page - you can just iterate through pageItems() collection of the document.
But it still won't give you access to all items - those that are anchored - including tables - or grouped - in this case you need to iterate through allPageItems collection.
Copy link to clipboard
Copied
For the first two try the following code
function setAutoSizing(txtList){
for (var i = 0; i < txtList.length; i++){
for (var j = 0; j < txtList[i].parentTextFrames.length; j++) {
var frame = txtList[i].parentTextFrames[j];
if (frame.isValid) {
frame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.CENTER_POINT;
frame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.WIDTH_ONLY;
}
}
}
}
function main() {
for (var i = 0; i < app.documents.length; i++) {
var doc = app.documents[i]
app.findGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.pointSize = "6.5";
app.findGrepPreferences.tracking = 0;
app.findGrepPreferences.fillColor=app.swatches.item("Paper");
var found = doc.findGrep();
setAutoSizing(found)
app.findGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.pointSize = "8.5";
app.findGrepPreferences.leading = "11";
found = doc.findGrep();
setAutoSizing(found)
app.findGrepPreferences = NothingEnum.NOTHING;
}
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Autosizing');
-Manan
Copy link to clipboard
Copied
This one worked just as expected! Thx! 🙂
Copy link to clipboard
Copied
You should create an object style and use a script to apply it to your objects. Then all you need to do is change the style.