Copy link to clipboard
Copied
I am trying to figure out how to alter the script I have for converting all text variables to text into one that excludes any text variables on a locked layer. So far I've had no luck! The script below does expand all text variables, even those on a locked layer. Help?
Main();
function Main() {
for (i = 0; i < app.activeDocument.layers.length; i++) {
if(app.activeDocument.layers.visible == true && app.activeDocument.layers.locked == false) {
app.activeDocument.activeLayer = app.activeDocument.layers;
app.documents[0].stories.everyItem().textVariableInstances.everyItem().convertToText();
};
};
}
Hi,
Your code is checking layer's property one by one but finally all doc's stories are the target, so...
better iterate through textFrames and check its itemLayer 'locked/visible' property.
Something like:
var
mDoc = app.activeDocument,
mFrames = mDoc.textFrames.everyItem().getElements(),
cFrame;
while (cFrame = mFrames.pop())
if (cFrame.itemLayer.visible && !cFrame.itemLayer.locked)
cFrame.textVariableInstances.everyItem().convertToText();
Jarek
PS. Notice that only
...Copy link to clipboard
Copied
Hi,
Your code is checking layer's property one by one but finally all doc's stories are the target, so...
better iterate through textFrames and check its itemLayer 'locked/visible' property.
Something like:
var
mDoc = app.activeDocument,
mFrames = mDoc.textFrames.everyItem().getElements(),
cFrame;
while (cFrame = mFrames.pop())
if (cFrame.itemLayer.visible && !cFrame.itemLayer.locked)
cFrame.textVariableInstances.everyItem().convertToText();
Jarek
PS. Notice that only 1st level textFrames are targeted - code ignores textFrames inside other objects (groups, other textFrames, etc)
Copy link to clipboard
Copied
Wonderful. That works like a charm!
Copy link to clipboard
Copied
Hi,
As Jarek said, in your case, you're just … lucky!
(^/)
Copy link to clipboard
Copied
With this, imho, you'll continue to be … lucky! … and others too!
app.findGrepPreferences = null;
//----------------------------------------------------------------------
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
//----------------------------------------------------------------------
app.findGrepPreferences.findWhat = "~v";
myFound = app.activeDocument.findGrep();
var F = myFound.length;
while ( F-- ) myFound
.textVariableInstances.everyItem().convertToText(); app.findGrepPreferences = null;
(^/)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now