• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problem writing exif to custom metadata field with catalog:withPrivateWriteAccessDo

Explorer ,
Jun 14, 2017 Jun 14, 2017

Copy link to clipboard

Copied

I'm writing a LR Plugin that accesses proprietary fuji exif using exiftool.  I have successfully read the metadata and saved it into appropriate variables.  I'm now trying to write it to the custom metadata fields my plugin has defined and created.  It's not working, though.  Here's the function to write the metadata.  It is called from within a LrTasks.startAsyncTask() function.

------- Write the relevant fuji exif to LR metadata -----------

function writeMetadata(objCat, tblImagesExif)

  local arrPhotos = {}  --array to hold LR photo objects

  --get image list as an array of LR photo objects

  arrPhotos = objCat:getMultipleSelectedOrAllPhotos()

  str = objCat:withPrivateWriteAccessDo(

    function(context)

      for k,v in pairs(arrPhotos) do

        for i,image in pairs(tblImagesExif) do

          if image.filePath == v:getRawMetadata("path") then

          

            if image.ISO ~= nil then

              v:setPropertyForPlugin(_PLUGIN, "ISO", image.ISO)

            end

            if image.drMode ~= nil then

              v:setPropertyForPlugin(_PLUGIN, "DR_Mode", image.drMode)

            end

            if image.dr ~= nil then

              v:setPropertyForPlugin(_PLUGIN, "DR", image.dr)

            end

            if image.filmSim ~= nil then

              v:setPropertyForPlugin(_PLUGIN, "FilmSimulation", image.filmSim)

            end

          

            break --break out of the for loop as a match has been found

          end --end if

        end --end for

      end --end for

    end --end function

  )

  LrDialogs.message(str)

end

Some notes - objCat and tblImagesExif are populated with the correct values, and objCat:getMultipleSelectedOrAllPhotos() returns a valid list of photos. I've put debugging break points in at

str = objCat:withPrivateWriteAccessDo(

and

function(context)

It stops at the first one twice (str=nil and then str="executed") and never stops at the second one.

Any ideas?

TOPICS
SDK

Views

564

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 14, 2017 Jun 14, 2017

Copy link to clipboard

Copied

I don't see anything obviously wrong.  But when you say you set a breakpoint at "function(context)" and it never stops there, that's because Lau doesn't recognize that line as "executable".   Lua's debugging hook doesn't make it easier for a debugger like ZeroBrane to recognize which lines are executable and which aren't, so ZeroBrane lets you set a breakpoint there but it will never be taken. Set a break on the following line.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2017 Jun 15, 2017

Copy link to clipboard

Copied

Sorry, I should have added that I set breakpoints inside each block of the function(context).  It didn't stop at any of them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2017 Jun 15, 2017

Copy link to clipboard

Copied

To get breaks and stepping to work in the callback function of withPrivateWriteAccessDo(), you have to add a call to LrMobdebug.on() at the beginning of the function.  In general, you need to do so for any callback function passed to the SDK API.  If you don't, then breaks and stepping may not work in that function.

The reason is that under the covers, there are a number of APIs where LR executes the callback in a new task (a "coroutine" in standard Lua terminology).   The debugging features have to be enabled in every task you want to debug. (This is a limitation of the core Lua debugging hooks provided by LR.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 15, 2017 Jun 15, 2017

Copy link to clipboard

Copied

Thanks John, that got the debugging going inside the callback function.  So now the first 'if' in that function never evaluates as true, and the debugging watch for 'v:getRawMetadata("path")' shows the following error:

Yielding is not allowed within a C or metamethod call

Any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2017 Jun 15, 2017

Copy link to clipboard

Copied

Yielding is not allowed within a C or metamethod call

This error occurs when the plugin calls an API method that must be executed within an asynchronous task (not the main task).  I think you're getting this error on the debugging watch because ZeroBrane is executing getRawMetadata() within the main task, not an asynchronous task.  (ZeroBrane isn't aware of such LR-specific constraints.)

I think if you want to monitor that, you'll have to first assign the expression to a local variable, and then watch the variable, forcing getRawMetadata() to executed in the current async task.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

LATEST

Thanks John.  That got the debugger working in that block.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines