Category: Blog

Description and History of Code Replacements and Hot Codes

(This post is by Camera Bits’ founder, Dennis Walker. It is a technical explanation of a new feature in Photo Mechanic 6 called Hot Codes as well as an explanation of how the invention came about)

Code Replacements

Code replacements essentially are shorthand codes that have replacements (1 or more).  It is used a lot for sports photographers when they caption photos.  A user creates a “code replacement file” which is just a tab delimited text file with codes in the first column, and replacements in subsequent columns.

For example, this is a code “wc8” with two replacements:

wc8	Alex Ovechkin	Alex Ovechkin, Left wing for the Washington Capitals

The user “invokes” a code replacement using a special delimiter character they can set, for example ‘=’.  When the user types “=wc8=” then as soon as the closing delimiter is typed, this is instantly replaced with “Alex Ovechkin”.  To access the second replacement listing the position and team, the user can type “=wc8#2=” and this can extend to multiple variations of the replacement (third, fourth, etc.).

Obviously, this is hardly a unique idea (you can buy system-wide software that will at least simulate the first code replacement).


However, things start to get more complicated when you throw in Photo Mechanic “Variables”.  Variables are built-in names that access certain pieces of metadata.  Here are some examples.  Variables have curly braces surrounding the variable name.

{datesortdash} = 2017-09-22 (current date for sorting with dashes)
{serial} = 12345 (serial number of the camera that took the photo)
{f} = 2.8 (lens aperture of the photo)
{city} = Portland (IPTC City field)
{photog} = Dennis Walker (IPTC Creator field)
{filenamebase} = DJW_1234 (base filename without extension like JPG or NEF)
{model} = Nikon D5 (model name of camera that took the photo)
{rating} = 4 (star rating 1-5 given to photo by user, or 0)

What makes Photo Mechanic’s code replacements so powerful (and unlike any other software that we are aware of) is that variables can be used to create codes. For example, several large news organizations use this technique for major games like Super Bowl where they have multiple photographers and they need to properly assign credits to the photographers for each photo, and automatically so it is correct. They do this by creating a spreadsheet of the serial numbers for each camera used by each photographer (photographers typically have 2 or more cameras each). They also want to assign the photographer’s position (e.g. Staff or Stringer), the folder name where the photos should be copied, and the editor’s folder who is editing their photos (e.g. some organizations may have multiple photo editors, each handling multiple photographers that the editor is assigned to). For example, their spreadsheet may have the following 2 lines for a photographer (the spreadsheet is saved as a tab-delimited text file before being loaded into Photo Mechanic):

12345	Dennis Walker	Walker	Photo Nerd	A
67890	Dennis Walker	Walker	Photo Nerd	A

The first column is code (serial number), second column (1st replacement) is “full” name of photographer, third column (2nd replacement) is “last” name of photographer, fourth column (3rd replacement) is “title” of photographer, and fifth column (4th replacement) is “editor” folder name (e.g. A-D).

Photo Mechanic has an “Metadata (IPTC) Template” (aka “IPTC Stationery Pad” in PM 5 and earlier) which is a template of IPTC metadata that is applied to each photo as they are “ingested” (or copied) from the cameras either directly (tethered) or from a flash card inserted into a card reader. There are also the Ingest and Live Ingest dialogs which configure where photos are copied to (folder path and name), how the photos are optionally renamed, etc. So, we want the “Creator” to be “Dennis Walker”, and we want his position (Creator’s Job Title) to be “Photo Nerd”. In the Metadata (IPTC) Template we would then enter the following into those fields:

Creator:		={serial}=
Job Title:		={serial}#3=

The variable {serial} is evaluated to 12345 or 67890 depending on which of Dennis’ cameras took the photo, then this is used as a code and the first replacement is placed into the IPTC Creator field, and the third replacement is placed into the IPTC Job Title field.

Furthermore, in the Ingest dialog there is a path where the photos are to be copied. For photos taken by Dennis’ cameras, we would want this to look something like:


This can be accomplished automatically by placing the following into the Ingest destination folder path (which is itself relative to the user specified base ingest folder):


As you can see this gets rather ugly rather fast because of the syntax.

But another bigger problem is that sometimes a photographer uses a camera model that does not record its serial number in the file (or Photo Mechanic is unable to locate it). This breaks the whole workflow since all the codes are based-upon a single piece of metadata, the camera serial number.

Still, no other software that we are aware of has the sophistication of Photo Mechanic’s existing Code Replacements.

Hot Codes, The Invention

Hot Codes solve both the syntax complexity problem, as well as providing for alternate metadata sources for generating codes. Furthermore, if a code cannot be found, Hot Codes provide default replacements that are specific to the column being accessed.

Hot Codes are implemented by adding declarations at the top of a code replacement file that define the following:

  • Code Generators: Multiple code generators can be defined, each using different variable(s) and text.
  • Hot Code Names: Names given to each column title. Almost like creating a custom variable name.
  • Default Replacements: Default values for each column title if no code replacement is found for any of the code generators.

Code Generators are defined by inserting a line starting with “//==”, followed by a tab, then followed by a string that includes variable(s) and optional static text. Multiple code generators can be defined (which gets around the current limitation of Code Replacements only relying-upon a single piece of metadata when being invoked). Think of these code generators as “try this OR that”.

//==	{serial}
//==	{fbas:0,3}
//==	{fbas:1,3}
//==	{model}

NOTE: The “//” at the beginning of a line indicates a “comment” which means that the code replacement loader prior to Photo Mechanic 6 ignores these lines. This syntax allows us to add Hot Code definitions to code replacement files and make them still be backwards compatible with earlier versions of Photo Mechanic since they are treated as comments. The Hot Code loader logic pays specific attention to lines that are normally comments but are followed by two special characters like above.

The variable {fbas} is a shorthand for {filenamebase} (all variables have a 4 character or less shorthand version). The syntax “:0,3” after the variable name is a substring extraction, meaning start at position 0 (first character) and then grab the next three characters. Likewise, “:1,3” means grab three characters starting at position 1 (second character). The reason for this is that cameras typically generate filenames like either “DJW_1234” or “_DJW1234” depending on whether the camera is in sRGB color space (first variation) or AdobeRGB color space (second variation). This is a standard Exif specification which most camera manufacturers follow. We just want the “DJW” part which we will get by one of these two code {fbas} code generators.

Hot Code Names are like the column headers that one would traditionally add for a spreadsheet to identify the values in that column. If we want the first code replacement, which is the full name of the photographer, we can just call that “full”. The second column, which is just the last name (or nickname) of the photographer, we can call that “last”. The third column, which is the photographers job title, we can call that “title”. And the fourth column, which is the folder name for the assigned editor (e.g. A-D) we can call that “editor”.

Therefore, we add a single line to the hot code replacement file to define our “Hot Codes Names” (NOTE the “first” column mentioned above is actually the “second” column if this were treated as a spreadsheet):

//##	full	last	title	editor

Now, we add some default values in case a photo is ingested that has no code for any of the various code generators. Unlike regular Code Replacements, which has only a single default string for all non-existent codes looked-up, Hot Codes has a default value for each of the Hot Code Names. So, for the “full” name of a photographer that is placed in the Creator field of IPTC, we may want to say “Unknown” if no code is found. For the “last” name of the photographer used as part of the folder name path, perhaps we create a folder “Other” when no code is found. For the photographer “title” used for Job Title field of IPTC, maybe we just leave that blank as a default. And for the folder name perhaps we use “all” for the default.

//??	Unknown	Other		E

Therefore, if a photo is ingested and no code generator creates a code that we have a replacement for, the photo credit (IPTC Creator) will be “Unknown” with a blank Creator Job Title, and the photo will be copied into “/Photos/E/Other”.

After these declarations for Hot Code, the user can add their normal code replacements, but now users can be identified by filename or model in addition to the serial number of the camera. For example, the following code replacement will be used based on a base filename “DJW_****” or “_DJW****”.

DJW	Dennis Walker	Walker	Photo Nerd	A

And the following code replacement will be used if Dennis is the only one use using a Nikon D5:

ILCE-9	Dennis Walker	Walker	Photo Nerd	A

Hot Codes are “invoked” by their Name enclosed in ‘[’ and ‘]’ characters. For example, to access the last name of the photographer, one can simply use “[last]” instead of something cryptic like “={serial}#2=”.

By using the features of Hot Codes, organizations can more easily manage complex workflows. This is especially apparent for configuration of the dialogs in Photo Mechanic. For example, in the IPTC Stationery Pad, they can now simply enter the following text into the dialog fields instead of the above examples:

Creator:	[full]
Job Title:	[title]

And in the Ingest dialog for the folder path, it becomes:


Not only are Hot Codes much more powerful than basic Code Replacements, they are much simpler to configure and therefore less error prone.

Alternate Default Chains

The default values for Hot Codes do not have to be static text, they can include variables. For example, if a code replacement can’t be found for a photo for the [full] hot code, which is used for the IPTC Creator field, we could try to lookup an alternate user-defined value stored in the Exif. For example, some cameras can write an optional “comment” to the photos. Some photographers put their name there. So why not use that as a backup, if it is defined, before using the static text “Unknown”? Easy enough: Photo Mechanic has a variable called {comment} (or {cmnt}) that extracts this field from a photo. When the “pipe” symbol ‘|’ is used after a variable as part of a default value, Photo Mechanic will evaluate the variable and if the variable returns an empty string, then Photo Mechanic will continue to the next alternate (these pipe symbols can be chained).

For example:

//??	{cmnt}|Unknown	Other		all

Hot Codes in Code Replacements

Just like variables (enclosed in ‘{‘ and ‘}’ pairs) are used for Hot Codes code generators, a hot code (enclosed in ‘[’ and ‘]’ pairs) can be used like a variable inside of a code lookup. For example, if there are several codes defined like “backupWalker” (for various “last” names of photographers), and each has a replacement that is a folder path to a backup for that photographer, then it is possible to use something like the following to generate such codes:


And then the full code replacement (to a folder path) might be something like:

backupWalker	~dennis/Pictures/{datesortdash}

When used as a secondary live ingest path, for example, Walker could have a copy of all his photos from his various cameras (and only his cameras) placed into this path for that day:

Prev. post
No Facebook Uploading For You
< Back to grid
Next. post
Your Latest #WorkflowWednesday Tip Roundup