[JW Lua] SetPageSize script

Charles O. Lawrence charlesolawrence at bellsouth.net
Sat Sep 28 16:31:01 CEST 2013


Jari (et al),

You said "...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."

I have implemented such a comparison function to sort by page size (area),
low to high.  It has more code than is absolutely necessary, but I wanted to
see if I was doing it right.  It also documents the method.

Next, I will implement a Boolean checkbox to reset page margins to their
defaults as well.  I would think that most users would not want this option
exercised.

Please find attached rev 0.03 of my script for your critique.

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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SetPageSize.lua
Type: application/octet-stream
Size: 5450 bytes
Desc: not available
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20130928/941dad86/attachment.obj>


More information about the JWLua mailing list