Page 1 of 1

Set value for a custom column

Posted: 14 Jan 2016 10:13
by touchstone_81
Hi,
I have added an extra column(Extra 1) and named it as 'AltName'.

I would like to populate this 'AltName' column with a string that is part of the selected file name(without the extension).

example:
Filename = My Vendor v7.2 assembly modification.docx Altname = assembly modification
Filename = My Vendor v7.2 parts picker.docx Altname = parts picker

the 'My Vendor' is always a constant and v7.2 is version number that is variable. I would like to extract the portion of the string following the versionnumber and set it as value of 'AltName' column as shown in the example above.
The idea is to select all files in a folder and then set the 'altname' column value via code.

Could somebody give me some pointers on how this could be achieved?

Re: Set value to Extra Column1

Posted: 14 Jan 2016 10:19
by highend
You need a custom column

How to set one up:
From (http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=11375)
1. Went to Tools / Configuration and choose "Custom Columns"
2. Selected an "Undefined" column and edited it
3. Entered a name then choose the type "Script"
4. Pasted the script (line) that highend so graciously posted
Code:
...

5. Important: Choose the item type "Files and Folders"
6. Saved it
7. Back in main window, right clicked on empty column area and choose "Add column"
8. Right clicked newly added column, selected "Select custom column", then choose the one create in step 4
Regarding the script for it:

Code: Select all

if (regexmatches("<cc_base>", "my constant")) {
    return regexreplace("<cc_base>", "^(.*?v[0-9.\s]+)(.*)", "$2");
}

Re: Set value to Extra Column1

Posted: 14 Jan 2016 10:34
by touchstone_81
Hi @Highend thanks for your reply.

as per your instructions I added a 'custom column' from the 'tools - configuration' menu and set the type to script and entered some dummy text as a placeholder for the script.

example:
Filename = My Vendor v7.2 assembly modification.docx
Altname = assembly modification

Filename = My Vendor v7.2 parts picker.docx
Altname = parts picker

Re: Set value to Extra Column1

Posted: 14 Jan 2016 10:39
by highend
The script you need for the cc:

Code: Select all

if (regexmatches("<cc_base>", "my constant")) {
    return regexreplace("<cc_base>", "^(.*?v[0-9.\s]+)(.*)", "$2");
}

Re: Set value to Extra Column1

Posted: 14 Jan 2016 10:45
by touchstone_81
hi @Highend you are awesome !....it worked :).
just 2 lines of code, great stuff.

Re: Set value to Extra Column1

Posted: 15 Jan 2016 10:28
by touchstone_81
Hi
have a follow-up question.
I realized that the custom column script will run everytime regardless of whether a value has already been set or not.

Is there a way to prevent it from running if a value is already present in the custom column cell.

logic along these lines

if(customcolumncell is null){run script} else {do nothing}

Re: Set value to Extra Column1

Posted: 15 Jan 2016 10:36
by highend
No, this can't be done

2 alternatives:

1. In the configure custom column configuration window
Set Trigger to "List" instead of "Browse"
In this case it will limit the "work" to get the values only from the current visible items instead for all list items

2. Write a script that stores all values in the tag.dat database (in an extra column) "once"
and read the values from there instead of always "recalculating" every entry
Pro: Faster / Con: When you rename a file you need to update the tag.dat database
http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=11375
That's a link how something like this can be done

Re: Set value to Extra Column1

Posted: 15 Jan 2016 10:42
by touchstone_81
ah i feared as much :)...anyway I will check that link, thanks again Highend.

Re: Set value for a custom column

Posted: 15 Jan 2016 11:28
by highend
Btw, I've renamed the thread :)