Quantcast
Channel: Adobe Community : Popular Discussions - Lightroom SDK
Viewing all 53524 articles
Browse latest View live

Re-Loading/Initializing Plugins...

$
0
0

From what I can tell, whenever I re-load a plugin, it (*mostly*) cleans up after the old one, then reloads...

 

This is fine, except one item it does not clean up is any asynchronous tasks started by the plugin. And, since the new load has a different variable context, its hard to detect and stop a previously started task.

 

Or something like this.

 

Any light that could be shed would help make it clearer whats going on when a plugin re-loads/initializes. And, if my above statement is fairly accurate, then consider this a feature request to add Tasks to the list of things to cleanup when a plugin is re-loaded.

 

Rob


Mac Question: Anybody know how to get services or keyboard shortcuts to work in a plugin?

$
0
0

I have a plugin that really benefits from being able to press a single key to issue a multi-key sequence.

 

I'm doing this on WIndows using AutoHotKey, and it works great on Mac using QuickKeys, but I'd like to find a way to do it without requiring the user to purchase QuickKeys. I've been able to use Automator to define a script that issues the desired keystrokes, and tie it to the keyboard as a shortcut initiated service, and this works in Lightroom proper, but is disabled when using my plugin.

 

Any ideas?

 

Thanks,

Rob

Keyboard shortcuts for plugin menu items on Mac

$
0
0

To assign a keyboard shortcut to a plugin menu item on Mac, you need to prefix the menu title with three spaces:

 

Untitled.png

In the example above, I've typed "<space><space><space>Open".  Evidently, the SDK is inserting those three spaces to get the plugin menu title indented in the menu.

 

Thanks much to Louie Sherwin, who pointed this out to me.

Working with LRSocket, receiving

$
0
0

I'm trying to set up a communication between Lightroom and another process using LRSocket. I've worked out an LrSocket.bind with mode = "send" and that's all working fine but I cannot for the life of me get a receive working. Here's my Lua code:

 

 

Connection = {

}

function Connection.Listen( self, context )

 

        local running = true

 

        self.Listener = LrSocket.bind {

 

       functionContext = context,

            port = 4242,

            plugin = _PLUGIN,

            mode = "receive",

 

            onConnected = function( socket, port )

                 Debug.logn( "Listener connected on port " .. port )

            end,

 

            onMessage = function( socket, message )

                 Debug.logn( "Listener Got: " .. message );

            end,

 

            onClosed = function( socket )

                 Debug.logn( "Listener Closed on Port: " .. myPort )

                 running = false

            end,

 

            onError = function( socket, err )

                 if err == "timeout" then

                 end

            end,

 

  } -- bind

 

  while running do

  LrTasks.sleep( 1/2 ) -- seconds

  end

 

  self.Listener:close()

 

 

end

 

I've been testing with both telnet and a short python snippet shown below. Telnet fails to connect at all, the Python code connects and the onConnected callback is called but, although text is being sent, the onMessage callback doesn't get called. I wondered if anyone had managed to make this work at all or if anyone has any pointers on what might be going wrong.

 

import socket, select, sys, time

 

def Send( msg ):

 

    TCP_IP = 'localhost'

    TCP_PORT = 4242

    BUFFER_SIZE = 1024

    MESSAGE = "Hello, World!"

 

    print "Sending on port ",  TCP_PORT

 

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    s.settimeout(2)

    s.connect((TCP_IP, TCP_PORT))

    s.send(MESSAGE)

    print "Sent"

    s.close()

 

    time.sleep( 5 )

    print "Closed"

 

Send( "Test")

 

Many thanks.

LrFileUtils.delete not working on OSX

$
0
0

Hi,

 

I'm trying to delete files on OSX. My commands work fine on Win, but I'm not able to delete any files on the mac. First I tried wildcard delete (/abc/*.png) which is not working. Also single file delete or moveToTrash is not working:

 

for filePath in LrFileUtils.files( path ) do
  

   myLogger:trace("filepath = " .. filePath )  --> shows correct path like /tmp/test

 

  local success, reason = LrFileUtils.moveToTrash( filepath)

   if not success then
   myLogger:trace("delete command = " .. filepath )

   myLogger:trace(reason) -> no message if .delete, moveToTrash gives "file not exists"

   end
 
end

 

Also not working:

 

if LrFileUtils.exists(filepath ) then  --> plugin exit without reason
   myLogger:trace( "file eexists" .. filePath)

end

 

Any ideas?

History Panel - access history in SDK

$
0
0

Is there any way to access history information through the SDK?  I'm specifically looking for what (if any) presets were applied to an image, along with the other incremental changes made. 

 

I'm hoping to do this without exiting the app and using SQLite and C# to hack into the lrcat (not exactly a stable way of doing it).

 

If there isn't a way, is there a way to add it as a feature request?

How to load a preset / LrTemplate file into a table variable

$
0
0

Lightroom stores it's settings in preset file called xxx.lrtemplate.

Question: how to load such a file into a local table variable.

 

I know I can load a file with LrFileUtils.readFile ( path), but then it is just string.

But how can I load it in a table variable?

For example how to load a keyword lrtemplate file into a table variable

s = {
       id = "0427FE55-2BD3-4DF3-A68B-336D39F4AB9B",
       internalName = "Family",
      title = "Family",
      type = "KeywordSet",
      value = {
           shortcut1title = "John",
           shortcut2title = "Suzan",
           shortcut3title = "Peter",
           shortcut4title = "",
           shortcut5title = "",
           shortcut6title = "",
           shortcut7title = "",
           shortcut8title = "",
           shortcut9title = "",
      },
      version = 0,
}

Here is a function to read preview images from active catalog

$
0
0

--- Get a preview image corresponding to specified photo, at the specified level, if possible.

--

--  @param photo (LrPhoto or table of param, required)     specified photo or table of named parameters same as below including photo=lr-photo:

--  @param photoPath (string, optional)     photo-path if available, otherwise will be pulled from raw-metadata.

--  @param previewFile (string, default=unique-temp-path)     target path to store jpeg - if non-vil value passed and file is pre-existing, it will be overwritten.

--  @param level (number, required)      appx sizes + intended use:

--      <br>     1 - 80x60     small thumb

--      <br>     2 - 160x120   medium thumb

--      <br>     3 - 320x240   large thumb

--      <br>     4 - 640x480   small image

--      <br>     5 - 1280x960  medium image

--      <br>     6 - 2560x1920 large image

--      <br>     7 - 1:1       full-res

--  @param minLevel (number, default=1) minimum acceptable level.

--

--  @usage file, errm, level = cat:getPreview{ photo=catalog:getTargetPhoto(), level=5 }

--  @usage file, errm, level = cat:getPreview( catalog:getTargetPhoto(), nil, nil, 5 )

--

--  @return file (string, or nil) path to file containing requested preview (may be the same as preview-file passed in).

--  @return errm (string, or nil) error message if unable to obtain requested preview (includes path(s)).

--  @return level (number, or nil) actual level read, which may be different than requested level if min-level passed in.

--

function Catalog:getPreview( photo, photoPath, previewFile, level, minLevel )

    if photo == nil then

        app:callingError( "no photo" )

    end

    if not photo.catalog then -- not lr-photo

        photoPath = photo.photoPath

        previewFile = photo.previewFile

        -- assert( photo.level, "no level in param table" )

        level = photo.level

        minLevel = photo.minLevel

        photo = photo.photo

        -- assert( photo and photo.catalog, "no lr-photo in param table" )

    end

    if level == nil then

        app:callingError( "no level" )

    end

    if level > 7 then

        app:logWarning( "Max level is 7" )

        level = 7

    end

    if photoPath == nil then

        photoPath = photo:getRawMetadata( 'path' )

    end

    local photoFilename = LrPathUtils.leafName( photoPath )

    local _previewFile

    if previewFile == nil then

        _previewFile = LrPathUtils.child( LrPathUtils.getStandardFilePath( 'temp' ), str:fmt( "^1.lrPreview.jpg", photoFilename ) ) -- include extension, since there are separate previews for each file-type.

    else

        if fso:existsAsFile( previewFile ) then

            app:logVerbose( "preview path passed is to existing file to be overwritten" )

        end

        _previewFile = previewFile

    end

 

    local imageId

    local s = tostring( photo ) -- THIS IS WHAT ALLOWS IT TO WORK DESPITE LOCKED DATABASE (id is output by to-string method).

    local p1, p2 = s:find( 'id "' )

    if p1 then

        s = s:sub( p2 + 1 )

        p1, p2 = s:find( '" )' )

        if p1 then

            imageId = s:sub( 1, p1-1 )

        end

    end

    if imageId == nil then

        return nil, "bad id"

    end

 

    local cp = catalog:getPath()

    local fn = LrPathUtils.leafName( cp )

    local n = LrPathUtils.removeExtension( fn )

    local cd = LrPathUtils.parent( cp )

    local pn = n .. " Previews.lrdata"

    local d = LrPathUtils.child( cd, pn )

    local pdb = LrPathUtils.child( d, 'previews.db' )

    assert( fso:existsAsFile( pdb ), "nope" )

    --Debug.pause( pdb )

    local exe = app:getPref( 'sqlite3' )

    if not str:is( exe ) then

        if WIN_ENV then

            exe = LrPathUtils.child( _PLUGIN.path, "sqlite3.exe" )

        else

            exe = LrPathUtils.child( _PLUGIN.path, "sqlite3" )

        end

        app:logVerbose( "Using sqlite executable included with plugin: ^1", exe )

    else

        app:logVerbose( "Using custom sqlite executable: ^1", exe )

    end

    local param = '"' .. pdb .. '"'

    local targ = str:fmt( "select uuid, digest from ImageCacheEntry where imageId=^1", imageId )

    local r1, r2, r3 = app:executeCommand( exe, param, { targ }, nil, 'del' )

    local uuid -- of preview

    local digest -- of preview

    if r1 then

        if r3 then

            local c = str:split( r3, '|' )

            if #c >= 2 then

                -- good

                uuid = c[1]

                digest = c[2]

            else

                return nil, "bad split"

            end

        else

            return nil, "no content"

        end

    else

        return nil, r2

    end

 

    local previewSubdir = str:getFirstChar( uuid )

    local pDir = LrPathUtils.child( d, previewSubdir )

    if fso:existsAsDir( pDir ) then

        -- good

    else

        return nil, "preview letter dir does not exist: " .. pDir

    end

    previewSubdir = uuid:sub( 1, 4 )

    pDir = LrPathUtils.child( pDir, previewSubdir )

    if fso:existsAsDir( pDir ) then

        -- good

    else

        return nil, "preview 4-some dir does not exist: " .. pDir

    end

    local previewFilename = uuid .. '-' .. digest .. ".lrprev"

 

    local previewPath = LrPathUtils.child( pDir, previewFilename )

    if fso:existsAsFile( previewPath ) then

        app:logVerbose( "Found preview file at ^1", previewPath )

    else

        return nil, str:fmt( "No preview file corresponding to ^1 at ^2", photo:getRawMetadata( 'photoPath' ), previewPath )

    end

 

    -- this could be modified to return image data instead of file if need be.

    local content

    local function getImageFile()

        local p1, p2 = content:find( "level_" .. str:to( level ) )

        if p1 then

            local start = p2 + 2 -- jump over level_n\0

            local p3 = content:find( "AgHg", start )

            local stop

            if p3 then

                stop = start + p3 - 1

            else

                stop = content:len() - 1

            end

            local data = content:sub( start, stop )

            if previewFile ~= nil then -- user passed file

                app:logVerbose( "Writing preview into user file: ^1", _previewFile )

            else

                -- rename file to include level.

                local base = LrPathUtils.removeExtension( _previewFile ) .. '_' .. level

                _previewFile = base .. ".jpg"

                app:logVerbose( "Writing preview into default-named file: ^1", _previewFile )

            end

            local s, m = fso:writeFile( _previewFile, data )

            if s then

                app:logVerbose( "Wrote preview file: ^1", _previewFile )

                return _previewFile

            else

                return nil, m

            end

        else

            return nil -- no real error, just no preview at that level.

        end

    end   

 

    minLevel = minLevel or 1

 

    local status

    status, content = LrTasks.pcall( LrFileUtils.readFile, previewPath )

    if status and content then

        repeat

            local file, errm = getImageFile() -- at level

            if file then

                return file, nil, level

            elseif errm then

                return nil, errm

            elseif level > minLevel then

                level = level - 1

            else

                return nil, str:fmt( "No preview for ^1 at any acceptable level", photoPath )

            end

        until level <= 0

        return nil, str:fmt( "Unable to obtain preview for ^1", photoPath )

    else

        return nil, str:fmt( "Unable to read preview source file at ^1, error message: ^2", previewPath, content )

    end   

end

 

This function is working great so far, but as of 2011-09-29 it has not been rigorously tested, so it may have a bug or two...

It is based on the elare plugin framework available here (including source code): https://www.assembla.com/spaces/lrdevplugin/

 

You will need sqlite3 executable from here: http://www.sqlite.org/sqlite.html

- put it in lr(dev)plugin dir

 

Note: view-factory's picture component will accept a path as resource id, so to use:

 

local pictureFile, errm = cat:getPreview( photo, nil, nil, 4 )

if pictureFile then

   items[#items + 1] = vf:picture {

       value = pictureFile,

    }

end

 

Note: the above code is intended for "sample/example" only -

 

MUST DO:

- Handle portrait orientation properly...

 

MAYBE DO:

- Handle AdobeRGB profile assignment - not needed for thumbs, but maybe for the biggies...

- Optimize for multi-photo use.

- Change detection for sake of caching for repeated access (like scrolling thumbnails).

 

@2011-10-04, the code at Assembla.com (see link above) takes care of all these things, and then some...;-)

 

Rob


What is 'brightnessValue' (formatted metadata)?

$
0
0

From API doc:

 

* aperture: (string) The aperture (for example, "f/2.8")

* brightnessValue: (string) The brightness value (HELP: need an example)

* exposureBias: (string) The exposure bias/compensation (for example, "-2/3 EV")

 

I could use an example too, and/or an explanation.

 

Anybody?

 

Thanks,

Rob

keyboard shortcuts

$
0
0

I'd like to do things like change focus for items in an LrView and also expand specific popup menus using certain keypresses (for example, by overriding default behaviors on the cursor buttons). How doable is that under the Lightroom SDK? I've looked over the documentation and seen little if any mention of this subject.

How to remove entries from LrPrefs

$
0
0

Hi,

 

how can I remove entries (key/value) from the table returned by LrPrefs.prefsForPlugin()?

I tried several things (like setting value to nil, removing the plugin) but the entries are still present. Now the prefs-table is poluted with entries from testing.

 

Kind regards,

Tim

SDK FTP plugin fails on 2.0

$
0
0
Hello -

The FTP plugin from the SDK fails to upload from 2.0. If I try a SFTP upload, I get this error:

Cannot upload because Lightroom could not create the destination directory.

I get this error if there is a subdirectory to create or not. It happens if there is a trailing slash or not.

If I try a FTP tranfer, passive or enhanced passive, I get this error:

Unable to upload because Lightroom cannot ascertain if the target destination exists.

If I hit Browse in the FTP settings it connects properly to the server and gives me directory listings. The same exact settings work fine in 1.4.1. I have upgraded the plugin to the one that comes with the 2.0 SDK. Anyone have any ideas?

Thanks,
otto

?:0: attempt to call upvalue '?' (a nil value)

$
0
0

I can't seem to get rid of this error (' ?:0: attempt to call upvalue '?' (a nil value) ').  What is "?:0:" ?

 

Thanks in advance for any help!

 

script:

 

local LrApplication = import 'LrApplication'
local LrDialogs = import 'LrDialogs'
local LrFileUtils = import 'LrFileUtils'
local catalog = LrApplication.activeCatalog()
local LrTasks = import 'LrTasks'

 


    function searchNtag()
        local targPhotos = catalog.getAllPhotos()
        for _, photo in ipairs(targPhotos) do
            local status = photo:getPropertyForPlugin('com.jonathonlefaive.tagstatus', 'tagboolean')
            if status then
                if status == nil then
                    local location = photo:getRawMetadata('path')
                    if LrFileUtils.isDeletable(location) == true then
                        photo:setPropertyForPlugin('com.jonathonlefaive.tagstatus', 'tagboolean', false, 2)
                    else
                        photo:setPropertyForPlugin('com.jonathonlefaive.tagstatus', 'tagboolean', true, 2)
                    end
                end
            end
        end
    end

 

function task()
    catalog.withPrivateWriteAccessDo(searchNtag)
end

 

LrTasks.startAsyncTask(task)

LrExportMenuItems = { title = 'My &Plugin', file = 'somefile.lua' }

$
0
0

In adobe Guide we can see :

 

In Windows, the title string can include an ampersand (&) character in the name to make the following
character a keyboard shortcut or accelerator that invokes that item. (This feature is not available in Mac OS;
on that platform, the & character is automatically removed if present.)
For example, suppose the table returned by your Info.lua file contains this item:
LrExportMenuItems = { title = 'My &Plugin', file = 'somefile.lua' }
This would create a command in the File > Plug-in Extras menu with the label “My Plugin”. The command
would execute the script found in somefile.lua.

 

I have windows XP, i make several test and .... no shortcut, any idea

 

Thanks

 

Cadret

Looking for tutorial on how to see LrLogger logs

$
0
0

Hi

im new to Lightroom sdk , i wad reading the documents about he LrLogger , and its says i need to get MS debug tools to watch logs

is it the only way ? if it is , where i can find short tutrial on how to see logs ?

Thanks


Disable SmartCollection

$
0
0

Hi All,

 

     How to disable SmartCollection.

 

 

Thanks

Executing a hashing algorithm

$
0
0

Hey all,

 

I'm writing a Lightroom plugin that needs to execute a SHA-256 hash algorithm on the photos prior to performing other actions on them.

 

Lightroom namespace provides LrMD5, but doesn't provide SHA256. I found the following implementation of the algorithm in Lua, but if I try to require the script, I get a "Could no load toolkit script" error.

 

Any suggestions?

What is root-pixels.db used for?

$
0
0

I mostly understand previews.db, but root-pixels.db is still a mystery - any ideas?

 

I mean it seems like redundent info from previews.db, plus jpegData which only has like 10 bytes of data - hmm...

LR 5 SDK now available

LrCatalog:withPrivateWriteAccessDo blocked by another write access call

$
0
0

Hi!

 

I recently downloaded the trial version of lightroom 6/CC (Windows version). I started developing my own plugin and got quite far until the point where I was starting to write data back to the catalog. Then I ran into "LrCatalog:withPrivateWriteAccessDo: could not execute action... It was blocked by another write access call, and no timeout parameters were provided"

 

I tried all kinds of things, but couldn't get around this (also read other posts on this and other sites). Even the minimal script below fails.

 

local LrApplication = import 'LrApplication'

local LrDialogs = import 'LrDialogs'

 

curCatalog = LrApplication.activeCatalog();

 

exres = curCatalog:withPrivateWriteAccessDo(function()

 

end)

 

Same happens for a few other plugins I downloaded and also with withWriteAccessDo.

 

Is the trial version limited in this or is it a bug in the latest version?

Can you confirm that your (purchased) version Lr 6 CC or standalone can run this script?

 

Thanks in advance!

Rasmus

Viewing all 53524 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>