Filename writing from regex

I’m using a rules filter to grab files from one folder that have Congress bioguide IDs (like A000378) at the beginning of them and a human readable name after them, this works great.

After processing, I’d like to write the files out to just the bioguide ID as the filename so they’re predictable when generating urls and not having to worry about names / nicknames.

Is there a way to set custom filename tokens based on the previous rules filter? Or appling the matches from regex groups when writing names would also work.

Looks like I can do it with a bit of regex in JS before a write files step: Write Images & Rename

This is possible!

You can do it with a JavaScript node, with the contents as such:

function processAsset(document, jsnode, asset) {
    var currentName = asset.outputFileName() + ""; // make sure it's a js string.
    
    // Apply a regex to the name.
    currentName = currentName.replace(/t/g, "X");
    asset.setOutputFileName(currentName);

    // Just another example here, of setting values to be used in the token fields.
    asset.setUserValue_forKey("FOO", "myKey");

    return true;
}

So that’ll rename the file name, replacing all ‘t’ characters with a capital X.

Then we also add a little “userValue” of “FOO” for the key of “myKey”. That value is then referenced later on in the write node like so:

I hope that makes sense. I’ve basically shown two different ways to assign values to the file name.

Ah, those user values are useful too! Thanks for both methods.