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

dynamic popup_menu

Explorer ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

I have search this forum and found some relating questions, but it does not help me.

https://community.adobe.com/t5/lightroom-classic-discussions/dynamic-table-for-popup-menu/m-p/429842...

 

I have a text file that contains multiple lines:

{ title = "Nikon F80s", value = "NF80" },
{ title = "Nikon ZF II", value = "NZFII" },

I read the file into a variable:

for line in io.lines(file) do 
	lines[#lines + 1] = line
  end

then in my function:

cameraContent = {}
local cameraFile = _PLUGIN.path .. '/lists/cameraList.txt'
local cameraContent = lines_from(cameraFile)
---
....
LrFunctionContext.callWithContext ("CreateDir", function (context)
		local f = LrView.osFactory ()
		local properties = LrBinding.makePropertyTable (context)
			-- Default values for boxes
			properties.scanDir = "yesScanDir"
			-- Present dialogbox 
			local result = LrDialogs.presentModalDialog {
...
f:popup_menu {
items =  cameraContent ,						
value = bind 'myCamera' , 
},		

The popup menu is still filled with each full line from the textfile.

The use of load loadstring  does not help and gives an error - bad argument #1 to '?' (string expected, got table)

TOPICS
SDK

Views

102

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 , Jan 31, 2024 Jan 31, 2024

The "items" must be a Lua array, where each entry is a table with keys "title" and "value". Instead, the code above is passing in an array of strings (lines).


The idiom for reading a Lua expression from a file is to a) use dofile() or b) to read the file using LrFilteUtils.readFile(), compiling the resulting string with loadstring(), which returns a function, and then invoking the function.  With either approach, the contents of the file should be one or more statements that, when evaluated, shou

...

Votes

Translate

Translate
LEGEND ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

The "items" must be a Lua array, where each entry is a table with keys "title" and "value". Instead, the code above is passing in an array of strings (lines).


The idiom for reading a Lua expression from a file is to a) use dofile() or b) to read the file using LrFilteUtils.readFile(), compiling the resulting string with loadstring(), which returns a function, and then invoking the function.  With either approach, the contents of the file should be one or more statements that, when evaluated, should return the desired data structure.  E.g.

return {
    {title = "Nikon F80s", value = "NF80"},
    {title = "Nikon ZF II", value = "NZFII"}}

 

In LR 3 and 4 on Windows, dofile() had a bug where it wouldn't accept file paths containing non-ASCII characters. I don't know if that bug still exists -- if it does, you'll have to do LrFileUtils.readFile(), loadstring(), and then invoke the returned 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
Explorer ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

Thank you John,

Going to try to get it to work.

I'm a analog photographer who just wants to automate his workflow, and just concentrate on taking images. My old app for recording my camera settings that I have been using for many years does not work anymore. I have switch to C+F wonderfull software but I need to start from scratch again.

Not easy when you don't have an developpers background.

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
Explorer ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

LATEST

Solved it:

ReturnContentFile = LrFileUtils.readFile(file) 
strTable = "{ " ..  ReturnContentFile .. " }"  	
strTable = loadstring("return "..strTable)()
return strTable

It took me a while before I found that I needed  an extra  { } surrounding my file contents

 

 

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