Copy link to clipboard
Copied
Hi gang,
What do you know about the Script Label panel?
It appears to not do anything.
One resource suggests it stopped after CS4.
I can find no example script that uses it.
This forum has topics that ultimately prove to be about renaming the layers panel object name; not about Script Labels.
Does anyone have an example of a working script that employs a labeled frame object?
I have searched and searched and cannot locate any examples.
Thanks Mike and Robert,
After tinkering with your examples, I simplified it for the sake of making a simple demonstration of what it does.
doc = app.documents[0];
for(var p = 0; p < doc.pages.length; p++){
var pageItems = doc.pages[p].allPageItems;
for(var i = 0; i < pageItems.length; i++){
if(pageItems[i].label == "QR-Code"){
app.select(pageItems[i]);
}
}
}
I am going to use it in my teaching examples.
Copy link to clipboard
Copied
Hello @Mike Witherell,
Here's an example on how the Scripts Lable is used...
This is part of a Data Merge process where we create the text frame, apply the Scripts Label "PDF_Name", assign the data source then create the merged document.
Below is a working script that's used to export single page pdfs uniquely named by the contents of the text frame with the Scripts Label "PDF_Name" applied.
doc = app.documents[0];
var PDF_Folder = Folder(doc.filePath + '/PDF');
var export_preset = app.pdfExportPresets.item("[High Quality Print]");
if (!(export_preset.isValid)){
alert("The pdf export preset does not exist.");
exit();
}
if (!PDF_Folder.exists) {
PDF_Folder.create();
}
for(var p = 0; p < doc.pages.length; p++){
var pageItems = doc.pages[p].allPageItems;
var PDF_Name = null;
for(var i = 0; i < pageItems.length; i++){
if(pageItems[i].label == "PDF_Name"){
var PDF_Name = pageItems[i].contents;
break;
}
}
if(PDF_Name == null) {
alert ('Error!\nThe Script Label "PDF_Name" is not applied to page ' + doc.pages[p].name + ', not labeled incorrectly or has no content.');
exit();
}
if(PDF_Name != null) {
app.pdfExportPreferences.pageRange = doc.pages[p].name;
doc.exportFile(ExportFormat.PDF_TYPE, File(PDF_Folder + "/" + PDF_Name + ".pdf"), false, export_preset);
}
}
alert("Done exporting Pdf's!");
Regards,
Mike
Copy link to clipboard
Copied
Here's an example where we can loop through the pages targeting the frames with the Scripts Label "QR_Code", creating the QR codes from the clipboard contents.
doc = app.documents[0];
function GetClipboard(){
var clipboard;
if(File.fs == "Macintosh"){
var script = 'tell application "Finder"\nset clip to the clipboard\nend tell\nreturn clip';
clipboard = app.doScript (script,ScriptLanguage.APPLESCRIPT_LANGUAGE);
} else {
var script = 'Set objHTML = CreateObject("htmlfile")\r'+
'returnValue = objHTML.ParentWindow.ClipboardData.GetData("text")';
clipboard = app.doScript(script,ScriptLanguage.VISUAL_BASIC);
}
return clipboard;
}
myClipboardContents = GetClipboard();
try { QR_Code = myClipboardContents; } catch(e){}
//create QR code///////////////
for(var p = 0; p < doc.pages.length; p++){
var pageItems = doc.pages[p].allPageItems;
for(var i = 0; i < pageItems.length; i++){
if(pageItems[i].label == "QR_Code"){
app.select(pageItems[i]);
app.selection[0].createHyperlinkQRCode(QR_Code);
}
}
}
app.select(NothingEnum.NOTHING);
Regards,
Mike
Copy link to clipboard
Copied
Not sure about JS - but in VB you can set / retrieve "visible" label - the one you can add / modify through the Script Label panel - or have as many as you need hidden ones.
Not sure if my VB code will be of any help to you - but in one of my tools, to build catalogs, DataMerge on steroids 😉 - I'm using labels to control relationships between different objects sizes & locations - so instead of hard coding settings in the script's code - user can set options himself dynamically.
So overall, labels can be quite useful.
Copy link to clipboard
Copied
Thanks Mike and Robert,
After tinkering with your examples, I simplified it for the sake of making a simple demonstration of what it does.
doc = app.documents[0];
for(var p = 0; p < doc.pages.length; p++){
var pageItems = doc.pages[p].allPageItems;
for(var i = 0; i < pageItems.length; i++){
if(pageItems[i].label == "QR-Code"){
app.select(pageItems[i]);
}
}
}
I am going to use it in my teaching examples.
Copy link to clipboard
Copied
My couple of cents:
Labels are a way to tell a script which exact objects to process. For example, the user may create a template and label (manually in the panel) the graphic frame as ‘image’ and the text frame underneath it as ‘caption’. The script may create documents from the template and insert images and captions reading data, say, from an Excel file.
These labels are visible to and editable by the user. But only one label can be used per object.
Alternatively, we can use insert/extractLabel methods to insert/extract to one object as many labels as we want using key-value pairs, but these are invisible to the user.
— Kas