John_R_Ellis's profile
Champion

Champion

 • 

6K Messages

 • 

103.7K Points

Tue, Nov 18, 2014 9:53 PM

Closed

Acknowledged

Lightroom SDK: folder:getChildren() incorrectly returning 0 return values

On one of my catalogs, folder:getChildren() is returning 0 return values for a particular folder (that is, it is executing a "return;" statement, with no value):

I've optimized the catalog to no effect.

If I hide the root folder "/", then the method works correctly.

This may be related to these topics (or it may not):
http://feedback.photoshop.com/photosh...
http://feedback.photoshop.com/photosh...

Official Solution

44 Messages

 • 

620 Points

7 y ago

Try getting the first sub-folder by path and then using that folder. That worked for me. So...

local root = catalog:getFolders()[1]
local rootName = root:getName()

local subFolder = root:getChildren()[1]
local subFolderName = subFolder:getName()

local subFolderByPath = catalog:getFolderByPath(subFolder:getPath())

local subSubFolder = subFolderByPath:getChildren()[1]
local subSubFolderName = subSubFolder:getName()

44 Messages

 • 

620 Points

7 y ago

I couldn't reproduce this problem. I actually did think I saw the behavior once, but then I could not reproduce so I think I may have just had a bug in my test code.

Can you try breaking out the calls into multiple lines like this:

local root = catalog:getFolders()[1]
local rootName = root:getName()

local subFolder = root:getChildren()[1]
local subFolderName = subFolder:getName()

local subSubFolder = subFolder:getChildren()[1]
local subSubFolderName = subSubFolder:getName()

and let me know if you still are seeing an issue...?

Thanks,

-paul

Champion

 • 

6K Messages

 • 

103.7K Points

7 y ago

With the root folder "/" showing, the expression subFolder:getChildren()[1] gets "attempt to index a nil value". Here's the log from my debugger session showing each of the assignments and resulting value:

14/11/18 14:54:50com.johnrellis.logger TRACE Eval: root = catalog:getFolders()[1]

14/11/18 14:54:57com.johnrellis.logger TRACE Eval: root
LrFolder

14/11/18 14:55:04com.johnrellis.logger TRACE Eval: rootName = root:getName()

14/11/18 14:55:09com.johnrellis.logger TRACE Eval: rootName
"/"

14/11/18 14:55:24com.johnrellis.logger TRACE Eval: subFolder = root:getChildren()[1]

14/11/18 14:55:31com.johnrellis.logger TRACE Eval: subFolder
LrFolder

14/11/18 14:55:40com.johnrellis.logger TRACE Eval: subFolderName = subFolder:getName()

14/11/18 14:55:45com.johnrellis.logger TRACE Eval: subFolderName
"Users"

14/11/18 14:57:14com.johnrellis.logger TRACE Eval: subFolderName
"Users"

14/11/18 15:01:55com.johnrellis.logger TRACE Eval: LrTasks.pcall (function () return subFolder:getChildren()[1] end)
false
"[string \"return function (catalog, LrApplication, Lr...\"]:1: attempt to index a nil value"

Champion

 • 

6K Messages

 • 

103.7K Points

7 y ago

Also, I just created a brand new catalog with about 50 test pics, and the problem occurs on that catalog too. (LR 5.6, OS X 10.9.5)

44 Messages

 • 

620 Points

7 y ago

Okay, I could reproduce on mac only. Windows seems fine. I'll file a bug for this. Thanks for the post.

-paul

Champion

 • 

6K Messages

 • 

103.7K Points

7 y ago

That works. Thanks much.