Lightroom: Smart-collection criterion "is empty" doesn't work with custom metadata fields

  • 1
  • Problem
  • Updated 2 years ago
  • (Edited)
The smart-collection criterion "is empty" doesn't work properly with custom metadata fields. It matches field values that are nil but not that are the empty string ("").  Tested with CC 2015.8 / OS X 10.12.3.

To reproduce the problem:

1. Create a plugin folder "isemptybug.lrdevplugin" containing the files below.

2. Create a new catalog.

3. Add the plugin to LR.

4. Import two photos.

5. Define a smart collection with the criterion "Field1 is empty". Notice that the smart collection contains both photos.

6. Select the two photos and run the plugin command Library > Is Empty Bug > Assign Fields. This sets the value of "field1" for the first photo to be nil and for the second photo to be the empty string ("").

7. Notice that the smart collection now contains just the first photo, whereas it should contain both.


Info.lua:
return {    
LrSdkVersion = 5.7,
    LrSdkMinimumVersion = 5.7, 
    LrToolkitIdentifier = 'com.johnrellis.isemptybug',
    LrPluginName = "Is Empty Bug",
    LrMetadataProvider = "MetadataDefinition.lua",
    LrLibraryMenuItems = {
        {title = "Assign Fields", file = "Assign.lua",
         enabledWhen = "photosSelected"}},
    VERSION = {major = 1, minor = 2, revision = 0, build = 0}}
MetadataDefinition.lua:
return {    
    metadataFieldsForPhotos = {
        {id = "field1",
         title = "Field1",
         dataType = "string", 
         browsable = false,
         searchable = true,
         readOnly = false}}}
Assign.lua:
local LrApplication = import "LrApplication"
local LrDialogs = import "LrDialogs"
local LrTasks = import "LrTasks"
local catalog = LrApplication.activeCatalog ()
LrTasks.startAsyncTask (function ()
    local photos = catalog:getTargetPhotos ()
    
    catalog:withWriteAccessDo ("Assign", function ()
        photos [1]:setPropertyForPlugin (_PLUGIN, "field1", nil)
        photos [2]:setPropertyForPlugin (_PLUGIN, "field1", "")
        end)
    local v1 = photos [1]:getPropertyForPlugin (_PLUGIN, "field1")
    local v2 = photos [2]:getPropertyForPlugin (_PLUGIN, "field1")
    local function f (v) return v == nil and "nil" or '"' .. v .. '"' end
    LrDialogs.message (f (v1) .. ", " .. f (v2))
    end)
Photo of John R. Ellis

John R. Ellis, Champion

  • 3863 Posts
  • 1018 Reply Likes

Posted 2 years ago

  • 1

Be the first to post a reply!