• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

catalog:getKeywords() seem to return a table of tables?

Community Beginner ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

Hi,

 

I'm unfamiliar with Lua and have just started hacking with Lightroom to automate some keywording. Apologies for possibly familiar 'code resuse', but I thought the result of this script would be a list of arKeyword rather than table 

 

LrTasks.startAsyncTask( function()
	local all_keywords=catalog:getKeywords()
	if #all_keywords == 0 then return end
	lrItem  = 1
	varFileName = ""
	varFileNames = {}
	local ProgressScope = ProgressScope({title = "My progress bar title" ,caption = "My progress bar caption",})
	for j, a_keyword in ipairs(all_keywords) do
           varFileName =  varFileName .. type(a_keyword) .. ", "
           lrItem = lrItem + 1
	   ProgressScope:setPortionComplete(lrItem/#all_keywords)
	   ProgressScope:setCaption( lrItem .. "/" .. #all_keywords .. '  ' .. j)
	end
	ProgressScope:done()

	local f = LrView.osFactory()
	local c =
		f:row{
		bind_to_object = props,
			f:column {
				f:edit_field { value = varFileName, width_in_chars = 80, height_in_lines = 10 },
			},
		}
	dialogValue = LrDialogs.presentModalDialog(
		{
			title = "Filenames" ,
			contents = c,
		}
	)
end)

 

but it actually generates: Screenshot 2024-08-02 at 13.28.40.png

 

I'm obviously doing something stupid, but what? Thank you!

TOPICS
macOS , SDK

Views

115

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 02, 2024 Aug 02, 2024

"I'm not sure I totally understand why it failed but I've now learnt that I need to use :getName() rather than .getName() to get the name"

 

If you have an LrKeyword object stored in the variable k, then the expression k:getName() is equivalent to k.getName(k). A common mistake is to write k.getName(), in which case you'll get the error "assertion failed!", because no argument has been supplied to the getName() function.

Votes

Translate

Translate
Community Beginner ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

So, I'm not sure I totally understand why it failed but I've now learnt that I need to use :getName() rather than .getName() to get the name

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

[This post contains formatting and embedded images that don't appear in email. View the post in your Web browser.]

 

Most objects in the LR SDK are represented as tables with methods that make them "opaque". For example:

johnrellis_0-1722639782471.png

johnrellis_3-1722640782099.png

 

This example shows that you can't use pairs() to iterate through the keys/values of such LR objects (that is, they are "opaque"):

johnrellis_2-1722640709837.png

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

"I'm not sure I totally understand why it failed but I've now learnt that I need to use :getName() rather than .getName() to get the name"

 

If you have an LrKeyword object stored in the variable k, then the expression k:getName() is equivalent to k.getName(k). A common mistake is to write k.getName(), in which case you'll get the error "assertion failed!", because no argument has been supplied to the getName() function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 08, 2024 Aug 08, 2024

Copy link to clipboard

Copied

LATEST

Thank you so much John, and sorry for my delay in responding. Your advice helped me understand this subtle differences in Lua with other programming languages that I'm familiar with. I've progressed a lot with my script now once I'd used your advice to get past that confusion. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines