Skip navigation
Minneapolis Glyn
Currently Being Moderated

Assertion Failed for catalog.createKeyword

Jul 8, 2012 5:40 PM

I am new to developing on the Lightroom SDK and am trying to build a script to add keywords to a catalog.  Here is the contents of the current script:

 

local LrApplication = import 'LrApplication'

local LrDialogs = import 'LrDialogs'

local catalog = LrApplication.activeCatalog()

 

 

GKMenuItem = {}

 

 

function GKMenuItem.runProcess()

          catalog:withWriteAccessDo("SetKeywords",GKMenuItem.setKeywords() )

 

 

end

 

 

function GKMenuItem.setKeywords()

          local test='Default'

          local catPhotos = catalog.targetPhotos

          local myKeyword = catalog.createKeyword( 'XYZA: test', {}, true, nil  )

 

 

          for _, photo in ipairs( catPhotos ) do

                    -- Loop through each of the photos.

                    -- photo.setKeyword(myKeyword)

 

 

                    LrDialogs.message(test)

          end

 

 

end

 

 

import 'LrTasks'.startAsyncTask( GKMenuItem.runProcess )

 

The problem I have is that I get an 'Assertion Failed!' message for the createKeyword statement whenever this is run.   I've tried a lot of variations without success.  Using Lightroom 3.6 on OSX Lion 10.7.4.

 

Any ideas would be appreciated!

 

Thanks

Glyn

 
Replies
  • Currently Being Moderated
    Jul 8, 2012 5:45 PM   in reply to Minneapolis Glyn

    catalog:createKeyword not catalog.createKeyword

     

    (colon, not dot)

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 8, 2012 6:05 PM   in reply to Minneapolis Glyn

    You are calling the function and passing it's result, what you should do is pass the function proper so with-write-access-do can call it.

     

    i.e.

     

    catalog:withWriteAccessDo( "SetKeywords", GKMenuItem.setKeywords )

     

    instead of

     

    catalog:withWriteAccessDo( "SetKeywords", GKMenuItem.setKeywords() )

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 8, 2012 7:43 PM   in reply to Minneapolis Glyn

    Cool. functions are great in lua - despite passing to a different context, they always execute in the context where they live - read: lua closures.

     

    Enjoy,

    Rob

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points