I'm trying to improve a Standard Function where I set the label of items to Purple.
So far I have:
Properties SETLABEL="Purple"
I'd like to use this logic:
If an item does not have the label of Purple then set the item's label to Purple.
I'm trying to improve a Standard Function where I set the label of items to Purple.
So far I have:
Properties SETLABEL="Purple"
I'd like to use this logic:
If an item does not have the label of Purple then set the item's label to Purple.
What would be the problem to assign the label even if it's already been assigned?
Just performance and speed reasons.
I'm not sure that testing for label existence will be better performance wise.
Anyway, you can put this into a script button (or use the button below):
function OnClick(clickData)
{
var labelToAssign = "Purple";
DOpus.ClearOutput();
// --------------------------------------------------------
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
// --------------------------------------------------------
cmd.RunCommand("Set VIEW=Details");
// --------------------------------------------------------
DOpus.Output("Selected items in " + clickData.func.sourcetab.path + ":");
if (clickData.func.sourcetab.selected.count == 0)
{
DOpus.Output("Nothing selected");
return;
}
var assignCmd = DOpus.Create.Command();
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext()) {
var item = eSel.item();
var labels = item.Labels();
var labelExists = false;
for (var e = new Enumerator(labels); !e.atEnd(); e.moveNext()) {
DOpus.Output("Item " + item.realpath + ": has label '" + e.item() + "'");
if (e.item() == labelToAssign) {
labelExists = true;
break;
}
}
if (!labelExists) {
DOpus.Output("Label is not set : need to assign it");
assignCmd.AddFile(item);
}
}
// If files need label to be assigned
if (assignCmd.filecount > 0) {
assignCmd.RunCommand('Properties SETLABEL="' + labelToAssign + '"');
}
return;
}
SetLabelButton.dcf (2.9 KB)
EDIT: You'd want to remove (or comment) the DOpus.Output
lines if you're to execute on a high number of files, because, for sure, this will impact performance (especially the ones in the loops in the middle of the function).
EDIT2:
On second thought, if you don't mind loosing selection, there is a simpler solution.
Just make a button with these Opus commands:
Select DESELECT FILTERDEF label match Purple nowild
Properties SETLABEL="Purple"
It will deselect everything that doesn't have the label then will apply on what's still selected.