[JW Lua] SetPageSize script

Jari Williamsson jari.williamsson at mailbox.swipnet.se
Thu Sep 26 17:13:07 CEST 2013


On 2013-09-26 15:59, Charles O. Lawrence wrote:

> Please find attached a sample script that will set all pages in all
> parts and score to a selected page size.  Please critique the code and
> give comments if you see any logic errors/omissions or a cleaner more
> efficient way to accomplish this task.

I looked at the general design of the script. A more "Lua-like" approach 
would be to not separate name string and (in this case) page size. That 
makes it easier to maintain, read and expand.

Also, finenv.UserValueInput supports that programming model, since each 
page name string is unique in the table.

Test this this table-with-tables approach:
---
local selectPageSize = {["Letter (8.5 x 11)"] = {2448, 3168},
                         ["Legal (8.5 x 14)"] = {2448, 4032},
-- and so on and so on....
}  -- The end of the table
---

The "downside" is that you need to translate that to a string table for 
use as the finenv.UserValueInput() list, such as:
---
local popuplist = {}
for key, value in pairs(selectPageSize) do
     table.insert(popuplist, key)  -- Using Lua's table library
end
-- You might need to sort popuplist here as well, don't know...
---

For this example, use dialog:SetTypes("String") instead of 
"NumberedList" and the selected string value will be returned in your 
returnValues[1] from dialog:Execute(). The nice thing here is that you 
can use the selected string directly as the key to page size.

The code in this mail is untested, but the concept should work.


Best regards,

Jari Williamsson





More information about the JWLua mailing list