Copy link to clipboard
Copied
Right now I have the Text variable where it will add to the document. And i have it set to a shortcut so that way if i need it i can add it My question is. How can i make it apply to the text i have selected?
var doc = app.activeDocument;
var tvLn = doc.textVariables.item("L#Date");
!tvLn.isValid && tvLn = doc.textVariables.add({name:"L#Date", variableType:VariableTypes.CUSTOM_TEXT_TYPE});
tvLn.variableOptions.contents = String( getLDate() );
function getLDate() {
var date = new Date();
var month = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
var formatDate = ("/" + date.getFullYear()).substr(-2);
return month[date.getMonth()] +"/" + formatDate;
}
Hi,
if you want to simulate the menu in the UI where selected text is exchanged with the text variable you could use this:
var doc = app.documents[0];
var selection = app.selection[0];
var selectedText = selection.texts[0];
var tvLn = doc.textVariables.item("L#Date");
if(tvLn.isValid)
{
selection.textVariableInstances.add
(
undefined,
undefined,
{ associatedTextVariable: tvLn }
);
if(selectedText.insertionPoints.length > 1)
{
selectedText.remove();
};
};
Rega
...Copy link to clipboard
Copied
Hi,
if you want to simulate the menu in the UI where selected text is exchanged with the text variable you could use this:
var doc = app.documents[0];
var selection = app.selection[0];
var selectedText = selection.texts[0];
var tvLn = doc.textVariables.item("L#Date");
if(tvLn.isValid)
{
selection.textVariableInstances.add
(
undefined,
undefined,
{ associatedTextVariable: tvLn }
);
if(selectedText.insertionPoints.length > 1)
{
selectedText.remove();
};
};
Regards,
Uwe
Copy link to clipboard
Copied
Thank you works like a charm.