[JW Lua] SetPageSize script

Charles O. Lawrence charlesolawrence at bellsouth.net
Fri Sep 27 21:59:00 CEST 2013


You said to "...have the table with the sizes in a separate variable...".
Another good idea to make the code easier to read and understand.

I did not intend for this script to change any margins.  I had forgotten
about the pagesizes.txt file.  BTW, what is the 5th parameter (T,B,L,R,?)?
I might add this as an option to set margins back to their default values.

Thanks,
Charles Lawrence




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

On 2013-09-27 16:06, Charles O. Lawrence wrote:
> 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?

Personally, I would prefer to have the table with the sizes in a separate
variable, specially since you reference it twice, such as:
---
sizetable = selectPageSize[returnValues[1]] width = sizetable[1] height =
sizetable[2]
---

This approach becomes even more apparent if you expand the table, to include
the stuff like margins that is part of Finale's pagesizes.txt file.

The cool thing here is the if you implement things such as margins for your
table, these option can be made optional. Let's say that you have
"leftmargin = sizetable[3]" - if leftmargin is nil, don't set the value. 
(If you get lots of set-only-if-not-nil values, put that code in a small
function to get much nicer code.)

> I sorted the popuplist table, since the dropdown was not in the same 
> order as the table was initialized.

Ok, so it was as I suspected. It's the nature of a Lua table to not assume
that added elements are at the end of a table. In that aspect Lua tables
behaves differently compared to an array or a collection.

Btw, if you want to have fun with Lua, try to add a custom sort (for
example, sort by page size) of your table as an inline function without a
name directly as the 2nd parameter in the table.sort() call.


Best regards,

Jari Williamsson



_______________________________________________
JWLua mailing list
JWLua at jwmusic.nu
http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu





More information about the JWLua mailing list