Copy link to clipboard
Copied
Hi everyone. How can i keep this Script from writing overtop of the Our Barcode Text frame i have being created? What it does is the first time i open the Documnet It places OUR Barcode text frame where it needs to be. Then I save the file close it. WHen i reopen the FIle (Any FIle) It places another Text Frame over top of it. I'm trying to get it to Make the Text frame and if it sees that its already made it will not create a new Frame.
#targetengine "Indesign CC2017"
app.addEventListener( "afterOpen" , dotFOnPageOne );
app.addEventListener( "afterOpen", doMLyer );
app.addEventListener( "beforeSave", doLLayer );
app.addEventListener( "beforeOpen", doULLayer );
function doULLayer(){
app.activeDocument.layers.item("OUR Barcode").locked = false;
}
function doLLayer(){
app.activeDocument.layers.item("OUR Barcode").locked = true;
}
function doMLyer(){
layers = app.documents[0].layers;
if (layers.item('OUR Barcode').isValid) {
layers.item('OUR Barcode').move (LocationOptions.AT_BEGINNING);
}
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CREATE NEW layer<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\
function doLyer(){
var _d = app.documents[0];
var _allStories = _d.stories;
for(var n=_allStories.length-1;n>=0;n--){
var _storyAllTextFrames = _allStories
.textContainers; for(var m=_storyAllTextFrames.length-1;m>=0;m--){
//If the contents of a text frame is an empty string:
if(_storyAllTextFrames
.contents === ""){ _storyAllTextFrames
.select(); //Convert frame to "Unassigned":
/* try{
app.scriptMenuActions.itemByID(11297).invoke();
}catch(e){}; */
};
};
};
//Trick to deselect the last selection
//Add a new textFrame, select and remove it:
var _tempTextFrame = _d.textFrames.add();
_tempTextFrame.select();
_tempTextFrame.remove();
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>NEW layer Color Settings<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\
function addlayer(doc, name){
try{
var layer = doc.layers.itemByName(name);
if(layer && layer.isValid) {
return layer;
} else {
var mylayer = doc.layers.add();
mylayer.name = name;
mylayer.layerColor = [100,50,100]
return mylayer;
}
} catch(e) {
}
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CREATE TEXT FRAME<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\
function addTextF(doc, layer, name){
// ************ how can I get the below to only allow me to select the **OUR Barcode** when its locked? ************* \\
app.generalPreferences.preventSelectingLockedItems = false;
var myBlendingSettings = { blendMode : BlendMode.NORMAL };
var myTransparencySettings = { blendingSettings : myBlendingSettings };
var tFR = doc.textFrames.itemByName(name);
if(tFR && tFR.isValid) {
tFR.remove();
}
var origUnit = app.scriptPreferences.measurementUnit;
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;
tFR = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Paper", fillTint: 100, transparencySettings : myTransparencySettings, geometricBounds: ['.504in','.21in','.376in','-.21in'] });
tFR.rotationAngle += -90;
// ************ Cant get the below to Fill my pictures Proportionally. ************* \\
/*
tFR.fit(FitOptions.FILL_PROPORTIONALLY);
tFR.resize(
CoordinateSpaces.innerCoordinates,
AnchorPoint.topLeftAnchor,
ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
[.40,.40]
);
tFR.fit(FitOptions.CENTER_CONTENT);
*/
tFR.locked=true;
app.scriptPreferences.measurementUnit = origUnit;
return tFR;
}
// VERTICAL geometricBounds: ['.65in','.062in','.23in','-.066'] });
/* HORIZONTAL geometricBounds: ['.333','.124','.46','-.296'] }); */
//geometricBounds: ['.333in','.21in','.20501in','-.296in'] });
// geometricBounds: ['.504in','.21in','.376in','-.21in'] });
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>MOVE TEXT FRAME TO layer<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\
function dotFOnPageOne(event){
var doc = event.target;
if(!(doc && doc.constructor.name == "Document")) {
return;
}
var mylyer = addlayer(doc, "OUR Barcode");
var tFR = addTextF(doc, mylyer, "OUR Barcode");
}
I got this to work. I just added an event listener to lock the Textbox before the document closes.
Copy link to clipboard
Copied
Is this the exact same question as in your yesterday's Help with my Text frame Script ?
If so, please delete this one or the older one.
Copy link to clipboard
Copied
No its Same Script different problem. I just noticed today it was adding that frame to every time i reopen a file.
Copy link to clipboard
Copied
Can you delete your comment so i can delete this post? I'm going simplify my question. Or if you can delete this post that will work too. Thanks
Copy link to clipboard
Copied
Sorry, I can't anymore ("No actions are available"). Ping a moderator with a personal message, that should do it.
And thanks for simplifying the problem! That should make it easier to answer.
Copy link to clipboard
Copied
ok thank you.
Copy link to clipboard
Copied
I got this to work. I just added an event listener to lock the Textbox before the document closes.