Skip to main content
January 18, 2014
Answered

withWriteAccessDo problems with Debug plugin

  • January 18, 2014
  • 1 reply
  • 1672 views

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)

This topic has been closed for replies.
Correct answer johnrellis

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.

1 reply

johnrellis
johnrellisCorrect answer
Legend
January 18, 2014

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.

January 18, 2014

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

johnrellis
Legend
January 20, 2014
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.