[JW Lua] SetPageSize script

Charles O. Lawrence charlesolawrence at bellsouth.net
Fri Sep 27 16:06:53 CEST 2013


Jari, et al,

I have implemented a more "Lua-like" design as you suggest.  I like it much
better.  Thanks for the suggestion.  Please find attached rev 0.02.  It took
me some fiddling to get the right syntax to retrieve the table values within
a table, but it is similar to other programing languages I have used.  Is
there another syntax you suggest?  I sorted the popuplist table, since the
dropdown was not in the same order as the table was initialized.

Thanks,
Charles Lawrence




-----Original Message-----
From: JWLua [mailto:jwlua-bounces at jwmusic.nu] On Behalf Of Jari Williamsson
Sent: Thursday, September 26, 2013 11:13 AM
To: The JW Lua script plug-in.
Subject: Re: [JW Lua] SetPageSize script

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


_______________________________________________
JWLua mailing list
JWLua at jwmusic.nu
http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SetPageSize.lua
Type: application/octet-stream
Size: 4295 bytes
Desc: not available
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20130927/0616340d/attachment.obj>


More information about the JWLua mailing list