6 Replies Latest reply on Dec 2, 2013 2:52 AM by areohbee

    create a preset in lua module

    dhmc05 Level 1

      I want to experiment with applying develop adjustments from a plug-in.  noticed the photo:applyDevelopPreset( preset, plugin ) function.

       

      Question:

      Is there a way to create a preset on the fly within the plug-in, for example a preset for  setting the Exposure2012 to +10.

       

      A little piece of code would be appreciated much!

        • 1. Re: create a preset in lua module
          areohbee Level 5

          preset = LrApplication.addDevelopPresetForPlugin( _PLUGIN, "My Groovy Preset", { Exposure2012 = .3 } ) -- no catalog write access required.

          photo:applyDevelopPreset( preset, _PLUGIN ) -- catalog write access required.

           

          Note: develop preset will be applied at Lr's leisure in the background (after returning from catalog write access method), so if you are depending on preset settling in, you need to add some logic after applying.

           

          Beware: assuring auto-toned values have settled, so you can make adjustments to auto-toned values, is particularly problematic. There are similar problems with auto/custom white-balance, lens corrections, ...

          • 2. Re: create a preset in lua module
            dhmc05 Level 1

            Rob, THANK YOU!!!!!!!!!

             

            Great,this is awesome!

            • 3. Re: create a preset in lua module
              pisu86

              Hi guys im working on my first plugin, excuse me my poor knowlage. i use code

              "

              local function setPreset () 

               

               

                local LrApplication = import 'LrApplication'

                local catalog = LrApplication.activeCatalog()

                catalog:withWriteAccessDo( 'setPreset', function()

               

               

                 

                 local preset = LrApplication.addDevelopPresetForPlugin( _PLUGIN, "___Dummy___", { Exposure2012 = 1.2 } )

                 photo:applyDevelopPreset(preset, _PLUGIN)

                end)

               

              end

               

              "

              i recive error :

              attemp to index global 'catalog' a nil value.

               

              why is that happening?

              • 4. Re: create a preset in lua module
                johnrellis Most Valuable Participant

                Is that the complete script you're executing, or is it an excerpt?  The error you're getting, "attemp to index global 'catalog' a nil value", wouldn't arise from the code fragment you posted.   Without seeing a complete script, it's hard to know what's going on.

                • 5. Re: create a preset in lua module
                  pisu86 Level 1

                  thank you for your response John

                  yes, thats all i have, What else i should include in code? sorry for beeing nooby

                  • 6. Re: create a preset in lua module
                    areohbee Level 5

                    If you were expecting catalog to be available upon return from the function posted - it won't be: function's locals are out of scope in context external to the function where they're declared, so catalog will be expected in the global environment instead (everywhere but inside that function), but it's not - thus the error, probably.

                     

                    -- in other words:

                    local catalog

                    local function yada()

                      catalog = LrApplication.activeCatalog()

                    end

                    yada()

                    LrDialogs.message( tostring( catalog ) )

                    -- works, whereas

                    local function yada()

                      local catalog = LrApplication.activeCatalog()

                    end

                    yada()

                    LrDialogs.message( tostring( catalog ) )

                    -- will give the error you're getting

                     

                    Either that, or there was a typo somewhere...

                     

                    PS - you may want to spend some more time reading that lua manual .