local LrApplication = import 'LrApplication' -- Import LR namespace which provides access to active catalog local LrDialogs = import 'LrDialogs' -- Import LR namespace for user dialog functions local LrTasks = import 'LrTasks' -- Import functions for starting async tasks local LrMobdebug = import 'LrMobdebug' -- Import LR/ZeroBrane debug module LrMobdebug.start() -- Connect with the ZBS debugger server. LrTasks.startAsyncTask (function() -- Certain functions in LR which access the catalog need to be wrapped in an asyncTask. LrMobdebug.on() -- Make this coroutine known to ZBS catalog = LrApplication.activeCatalog() -- Get the active LR catalog. selectedPhoto = catalog:getTargetPhoto() -- Get the photo currently selected by the user. (type: LrPhoto) shutterspeed = selectedPhoto:getRawMetadata("shutterSpeed") -- Receive raw (value-only) metadata from the photo, for shutter speed shutterspeedFormatted = selectedPhoto:getFormattedMetadata("shutterSpeed") -- Receive formatted metadata, fit for printing to the user aperture = selectedPhoto:getRawMetadata("aperture") -- Receive aperture metadata from photo apertureFormatted = selectedPhoto:getFormattedMetadata("aperture") -- Formatted version, fit for printing iso = selectedPhoto:getRawMetadata("isoSpeedRating") -- Receive ISO speed rating from photo temp = 100*aperture^2/(shutterspeed*iso) -- First part of calculation of exposure value exposureValue = math.log10(temp) / math.log10(2) -- take log 10, then change to log base 2 (log base 2 is n/a in Lua math library) exposureValue = round(exposureValue,2) -- Round to 2 decimal places LrDialogs.message ("Shutter speed: " .. shutterspeedFormatted .. ", aperture: " .. apertureFormatted .. ", ISO: " ..iso.. "\nThe exposure value of this photo is "..tostring(exposureValue)..".") -- Output information to user. end) -- end of startAsyncTask function round(num, idp) -- Helper function to round value to decimal places local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end