5 Replies Latest reply on Jan 20, 2014 5:20 PM by DawMatt

    withWriteAccessDo problems with Debug plugin

    Christof (Munich)

      Hi dear all,

       

      I am just starting writing Lightroom plugins (well, I had a first success 2 years ago but now I am starting again with more complicated stuff), and of course I do love the Debug plugin (Thanks again, John!) - but I am still struggling with some concepts and the limitations that might be imposed by it.

       

      Concretely, I run into the error "Attempt to access property "myPropertyName" that's not declared in Info.lua", when running my script using the Debug dialog. It works when I just run it from the Plugin Extras menu as a menu action.

       

      The code:

       

       

       

      LrTasks.startAsyncTask(Debug.showErrors(function(context)
          local catalog = LrApplication.activeCatalog()
          local selected = catalog:getTargetPhotos()

       

      ...

       

              for key, s in pairs(values) do
                  catalog:withWriteAccessDo("writing data", Debug.showErrors(function(context)
                      photo:setPropertyForPlugin(_PLUGIN, "myPropertyName", s)
                  end))
              end

       

       

      I found something in the Internet this being an indication of a race condition, so maybe this has something to do with one script wrapping / running the other? Or is there a way to get this running with the Debug script, and I am just not understanding the notion of background tasks/threads yet :-)?

       

      Thanks for your help!

      Christof

       

      (I am on LR 5)

        • 1. Re: withWriteAccessDo problems with Debug plugin
          johnrellis Most Valuable Participant

          Christof,

           

          Let's call the plugin you're debugging MyPlugin.  I think the problem is that you're invoking the Debug Script menu command from the Debug Script plugin but invoking a .lua file from MyPlugin.  When you do this, any references to the global variable _PLUGIN are actually referring to the Debug Script plugin, not to MyPlugin.   And thus, the .lua file can't access the properties of MyPlugin.

           

          This is a limitation of the SDK that I've neglected to document in the Debugging Toolkit.  The workaround is straightforward -- copy Debugscript.lua into the MyPlugin folder and add a menu command to MyPlugin that invokes Debugscript.   See steps 6-9 of "Debugging Export- and Publish-Service Plugins" from the documentation "Debugging Toolkit.docx".  

           

          Let me know if that addresses your problem.

          • 2. Re: withWriteAccessDo problems with Debug plugin
            Christof (Munich) Level 1

            Hi John,

             

            you are, of course!, right. When I do copy the DebugScript.lua into my own plugin directory, and add a menu action into my own Info.lua and start it from there, namespaces match and the action runs smoothly :-)

             

            The only quirk would be that I now have a Debug action in my code which I wouldn't want to ship - any chance to suppress the menu item when it is not the lrdevplugin folder?

             

            Cheers,

            Christof

            • 3. Re: withWriteAccessDo problems with Debug plugin
              johnrellis Most Valuable Participant
              The only quirk would be that I now have a Debug action in my code which I wouldn't want to ship - any chance to suppress the menu item when it is not the lrdevplugin folder?

              That is desirable, but I don't know how to do it.  I tried this:

                  LrExportMenuItems = {
                      _PLUGIN.path:sub (-12) == ".lrdevplugin" and
                          {title = "Debug Script", file = "DebugScript.lua"}}, 
              
              

              But unfortunately, you can't reference _PLUGIN (or "import" or "require" or other globals) from within Info.lua.

              • 4. Re: withWriteAccessDo problems with Debug plugin
                Christof (Munich) Level 1

                I found a solution for the menu item problem - the good old preprocessor approach :-)

                 

                This works nicely, I marked the Debug menu item in the Info.lua like this:

                    LrExportMenuItems = {
                        {
                            title = LOC"$$$/Myplugin/Keywords=Keywords",
                            file = "lookup.lua",
                        },
                -- #ifndef DISTRIBUTE_DEBUG 
                       {             title = "Debug",             file = "DebugScript.lua",         }, -- #endif
                },

                 

                and then took a preprocessor written in Java, which works with the Ant build file I use from the Elare framework.

                 

                The only step left was to enhance my build file with an additional step hooked in before the compile step:

                 

                <target name="precompile" depends="init">    
                     <taskdef name="javapc" classname="au.songdi.javapc.ant.JavaPCTask" classpath="javapc.jar"/>    
                     <javapc srcdir="${src}" destdir="${build}" commentmark="--"/>
                </target>

                 

                The advantage - the debug menu stays in the version served directly from the plugin source directory, which is where I edit and have the fastest development turnaround, but as the preprocessor will comment the lines, the menu item definition will not be part of the compiled Lightroom plugin.

                 

                The preprocessor is a bit quirky in that it does always convert all files in the directory (while I only needed the Info.lua to be processed), but it worked out of the box, making this a 20 minute job :-)

                 

                Message was edited by: Christof (better English, I hope)

                • 5. Re: withWriteAccessDo problems with Debug plugin
                  DawMatt Level 3

                  Thanks for taking the time to share the solution with us. That looks like the only viable workaround until they give us a way to inspect the plugin path from within Info.lua.

                   

                  Matt