Author Topic: Custom Variables  (Read 4947 times)

Offline IanGoldstein

  • Member
  • **
  • Posts: 98
    • View Profile
Custom Variables
« on: June 27, 2007, 10:26:41 AM »
What seems to be a very useful trick is to utilize code replacement along with variables in order to display alternate text for a variable. For example, with the following code replacements defined...

    tag0
    tag1     Tagged

...I can use \tag{tag}\ and have the word "Tagged" display in a Slideshow caption for any tagged images. Using only the {tag} variable, I can only show a 0 or 1. (Please note, there must be a tab and space following the "tag0" in order for this to work.)

This allows me to create "pseudo-variables" which I can use in any field where both variables and code replacement is allowed. It seems to work well for Info Text, slideshow captions, IPTC fields, etc. Using this technique I have been able to create such custom variables to display stars ("*") in slideshow captions, display P/A/M/S camera program modes (P,Av,Tv,M for Canon folk :)), display exposure/flash compensation when it is non-zero and not display it when it is zero, etc. I'm sure there are others using this trick.

However, what I'd like to suggest is official support for such "custom variables". It would be much nicer to be able to...
  (1) define a default value for unknown lookup values;
  (2) enter {mycustomvar} rather than to have to resort to complex expressions as we do now; and
  (3) share such custom variables easily in the manner in which code replacements can be shared.

It would be ideal if we could use the same {variable} syntax to reference these custom variables. However, not knowing the parsing procedures used for handling code replacement and variable substitution in text fields, I don't know if that is practical.

As far as implementation in PM, it could be as simple as allowing us to define "Custom Variable" files much like we do with the "Set Code Replacements" option under the "Edit" menu. Files could be added, removed and/or editted and would be nearly identical to current code replacement files. However, the first line in the file could be of the form:

    variable_name    lookup_value     default_value

When {variable_name} is encountered in a text field the lookup_value is expanded (i.e. variable substitution) and the remaining lines of the file are searched for the replacement text. If it is not found, the default_value is used (after variable substitution). The default value should be optional, and if not provided should be treated as an empty string ("").

As an example, this custom variable file would define a variable called "shortmode" that would show "P", "A", "S" or "M" for the basic program modes, and the full mode name for all other modes...

    shortmode           {mode}     {mode}
    Normal              P
    Aperture Priority   A
    Shutter Priority    S
    Manual              M

A slightly more complex version of this would even let me show Nikon/Canon specific modes...

    shortmode                            {make}{mode}     {mode}
    NIKON CORPORATIONNormal              P
    NIKON CORPORATIONAperture Priority   A
    NIKON CORPORATIONShutter Priority    S
    NIKON CORPORATIONManual              M
    CanonNormal                          P
    CanonAperture Priority               Av
    CanonShutter Priority                Tv
    CanonManual                          M

-Ian
« Last Edit: August 13, 2007, 01:23:59 PM by IanGoldstein »