Author Topic: Code Replacement: Return Nothing  (Read 1173 times)

Offline Josh Barber

  • Newcomer
  • *
  • Posts: 15
    • View Profile
    • www.joshbarber.com
Code Replacement: Return Nothing
« on: July 16, 2024, 10:21:02 AM »
Is it possible to make code replacement return nothing?

I have a set of scientific animal names and trying to generate a csv to upload into my DAM that has a number of taxonomical classifications and some common names.I've got the scientific name in the {subj} field and am using the text exporter to take of advantage of code replacement. The issue is some of these names I have no values for yet, and may never. For instance I have an column for "Other Common Names" (the 11th replacement) for which there are only a few values. Is there something I can do in photo mechanic to make a code return nothing for instance =Anaxyrus debilis insidior#11=, The Western Green Toad for which I have no other common names.

I definitely can think of a few work arounds using a space and find and replace in BBEdit but would love to do it in one step. Unsure if hotcodes can do this.

Offline ahoward

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 909
    • View Profile
Re: Code Replacement: Return Nothing
« Reply #1 on: July 16, 2024, 11:59:45 AM »
There is the "default replacement" option that gets used when it can't find a valid code replacement in one of your code replacement files. Unfortunately, something needs to be there for that to work. So what I did to achieve what you are looking for it put a variable in that field that returns nothing. Then, when Photo Mechanic can't identify a valid code replacement, it fills in that variable, and then when that variable gets evaluated, it just returns nothing. The exact variable you should use might vary for you, since I don't know what fields you use, but hopefully you'll be able to find one that works for you.

Offline Josh Barber

  • Newcomer
  • *
  • Posts: 15
    • View Profile
    • www.joshbarber.com
Re: Code Replacement: Return Nothing
« Reply #2 on: July 16, 2024, 12:15:29 PM »
Ooo that's a perfect workaround.

I forget how nesting codes and variables work. I'm creating the code replacement in excel using a formula. If I set up so that the replacement for codes where I have no value as a variable that will return nothing to begin with be evaluated and will that save having to set the default? Just asking because a default replacement has always scared me, having the delimiters show up with a code when I don't intend to is more visible.

Offline Max Lemesh

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: Code Replacement: Return Nothing
« Reply #3 on: July 16, 2024, 04:04:29 PM »
There is the "default replacement" option that gets used when it can't find a valid code replacement in one of your code replacement files. Unfortunately, something needs to be there for that to work. So what I did to achieve what you are looking for it put a variable in that field that returns nothing. Then, when Photo Mechanic can't identify a valid code replacement, it fills in that variable, and then when that variable gets evaluated, it just returns nothing. The exact variable you should use might vary for you, since I don't know what fields you use, but hopefully you'll be able to find one that works for you.

How would that look like in an example?

Offline ahoward

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 909
    • View Profile
Re: Code Replacement: Return Nothing
« Reply #4 on: July 16, 2024, 05:01:27 PM »
I forget how nesting codes and variables work. I'm creating the code replacement in excel using a formula. If I set up so that the replacement for codes where I have no value as a variable that will return nothing to begin with be evaluated and will that save having to set the default?
I'm not really sure I'm understanding the question, but I think so? That sounds like more work than just using the default replacement though. My best recommendation is to experiment with what I suggested and make sure it will work in your workflow and compare it to what you are suggesting.

Offline ahoward

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 909
    • View Profile
Re: Code Replacement: Return Nothing
« Reply #5 on: July 16, 2024, 05:02:54 PM »
There is the "default replacement" option that gets used when it can't find a valid code replacement in one of your code replacement files. Unfortunately, something needs to be there for that to work. So what I did to achieve what you are looking for it put a variable in that field that returns nothing. Then, when Photo Mechanic can't identify a valid code replacement, it fills in that variable, and then when that variable gets evaluated, it just returns nothing. The exact variable you should use might vary for you, since I don't know what fields you use, but hopefully you'll be able to find one that works for you.

How would that look like in an example?

You'd put a variable that returns nothing into the Default Replacement field in the Code Replacements window and then enter a code replacement that is not present in your code replacement file, and then it will fill in whatever you put in the "default replacement" field.

Offline Mick O (Camera Bits)

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 544
    • View Profile
    • Camera Bits
Re: Code Replacement: Return Nothing
« Reply #6 on: July 16, 2024, 05:20:04 PM »
I'm creating the code replacement in excel using a formula.

Just be aware that if your Excel formula generates an empty Code Replacement like this:

Code: [Select]
==
It will not evaluate as a Code to be replaced. So setting a default replacement in the Code Replacement setting dialog won't make that go away, and you'll end up with "==" in whatever field you're working in.  I'm not sure if that's a possibility given your Excel set-up, but I thought I'd mention it.

Mick O
Camera Bits

Offline Josh Barber

  • Newcomer
  • *
  • Posts: 15
    • View Profile
    • www.joshbarber.com
Re: Code Replacement: Return Nothing
« Reply #7 on: July 16, 2024, 06:49:56 PM »
Thanks for the help on this Andrew and Mick. I ended up using an excel formula that returned my "blank" variable—Image Supplier Id:{is}—if the cell I was referencing when generating my code replacement didn't have any data. The question I was trying to ask in the last post is if a variable returned as a replacement would evaluate to 'blank'.

I was storing the scientific name in IPTC subject code, so in text exporter I had for example ={subj}#11= which evaluated to "=Anaxyrus debilis insidior#11=" and replaced "{is}" which evaluated to blank in the csv I created with the text exporter.

My reluctance to use the default replacement feature is that I only want to get a blank replacement when I mean to, I have other applications of Code Replacement where I want it to be very visible if there isn't a replacement for a code (likely because of a typo or other error). And good to know about the limitation of nothing between the delimiters, helpful to think through if and when that might happen.

I'll probably switch to using one of the user/client variables for the blank variable in the future just in case I ever work with images from a source that uses Image Supplier ID