Lightroom SDK Guide

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 207

DownloadLightroom SDK Guide
Open PDF In BrowserView PDF
LIGHTROOM SDK 6
PROGRAMMERS GUIDE

Copyright © 201 Adobe Systems Incorporated. All rights reserved.
Adobe Photoshop Lightroom SDK  Programmers Guide
If this guide is distributed with software that includes an end user agreement, this guide, as well as the software
described in it, is furnished under license and may be used or copied only in accordance with the terms of such license.
Except as permitted by any such license, no part of this guide may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written
permission of Adobe Systems Incorporated. Please note that the content in this guide is protected under copyright law
even if it is not distributed with software that includes an end user license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be
construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or
liability for any errors or inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under
copyright law. The unauthorized incorporation of such material into your new work could be a violation of the rights of
the copyright owner. Please be sure to obtain any permission required from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to
refer to any actual organization.
Adobe, the Adobe logo, Photoshop, Lightroom, and Flash are either registered trademarks or trademarks of Adobe
Systems Incorporated in the United States and/or other countries.
Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States
and/or other countries. Apple, Mac, Mac OS, and Macintosh are trademarks of Apple Computer, Incorporated, registered
in the United States and other countries. Sun and Java are trademarks or registered trademarks of Sun Microsystems,
Incorporated in the United States and other countries. UNIX is a registered trademark of The Open Group in the US and
other countries.
All other trademarks are the property of their respective owners.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA. Notice to U.S. Government End Users.
The Software and Documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of
“Commercial Computer Software” and “Commercial Computer Software Documentation,” as such terms are used in 48
C.F.R. §12.212 or 48 C.F.R. §227.7202, as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through
227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are
being licensed to U.S. Government end users (a) only as Commercial Items and (b) with only those rights as are granted
to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright
laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA. For U.S.
Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if appropriate, the
provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance Act
of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR
Parts 60-1 through 60-60, 60-250, and 60-741. The affirmative action clause and regulations contained in the preceding
sentence shall be incorporated by reference.

Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Lightroom SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Lua language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
About this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Conventions used in this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

1

Using the Lightroom SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Writing plug-ins for Lightroom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
The Lightroom SDK scripting environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Namespaces, classes, and objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Defining function contexts and tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Including scripts with require() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Lua syntax notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

12
12
20
20
21

Writing a Lightroom Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Writing standard plug-ins for Lightroom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Declaring the contents of a plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Delivering a standard plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debugging standard plug-ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23
23
29
32

Customizing plug-in load behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Initialization and termination functions for the Plug-in Manager . . . . . . . . . . . . . . . . . . . . . . 34
Adding custom sections to the Plug-in Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Defining menu items for a plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

3

Creating Export and Publish Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Creating an export or publish service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Defining an export service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Initialization and termination functions for services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Defining a publish service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Publish service options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Adding an export post-process action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Inserting and removing actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Action dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Declaring export post-process actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Defining a post-process action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Removing photos from the export operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Defining post-processing of rendered photos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How post-process actions are executed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43
43
45
46
47
48
48
50

Final processing of rendered photos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Customizing the Export and Publishing Manager dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Customizing the export destination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

3

4

Contents

Adding custom sections to the Export or Publishing Manager dialog . . . . . . . . . . . . . . . . . 56
Restricting existing service functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Remembering user choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Export presets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Settings for publish services and post-process actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Lightroom built-in property keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Export Location section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
File Naming section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
File Settings section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Image Sizing section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Output Sharpening section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Metadata section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Video section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Watermarking section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Post-Processing Filter section properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
General export properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Publish Service properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

61
62
62
66
67
68
68
69
69
69
70
70

Working with Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Adding custom metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Declaring a Metadata Provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Defining metadata fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Adding custom metadata tagsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Defining a metadata tagset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Searching for photos by metadata values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Combining search criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Creating searches interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

5

Creating a User Interface for Your Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Adding custom dialog views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Using dialog boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Displaying predefined dialog boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Creating custom dialog boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
User interface elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
View properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

87
87
88
93

Binding UI values to data values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Specifying bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Creating observable property tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Bindings for selection controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Complex bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Determining layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Relative placement of sibling nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Placement within the parent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Factory functions for obtaining layout values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Layout examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

5

Contents

6

Writing a Web-engine Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Creating a web-engine plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Folder contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Defining the data model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
GalleryInfo top-level entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Data model entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Defining a UI for your model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Creating a dynamic data model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Creating a preview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Web SDK manifest API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
LuaPage syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Environment variables available to LuaPages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
LuaPage data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Web SDK tagsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Defining custom tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Using custom tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Lightroom built-in tagset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Web HTML Live Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Defining messages from Lightroom to a previewed page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Defining messages from a previewed page to Lightroom . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

7

Using ZStrings for Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
ZString format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
ZString characters and escape sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
The LOC function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Localization dictionary files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Localization dictionary file format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Example dictionary file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

8

SDK Sample Plug-ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
The FTP Upload sample plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Bring up the FTP plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Configure the connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Establish the connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
The Flickr plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
The Flickr API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Flickr plug-in walkthrough . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Metadata and filtering samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Custom metadata sample walkthrough . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Metadata filter sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Post-processing samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Post-processing actions walkthrough . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Web engine sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

6

Contents

9

Getting Started: A Tutorial Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Creating an export plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Create the information file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Create the service scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Displaying a dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Displaying a custom dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Create a properties table for program data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Create UI elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Run the plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Transforming data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Create multiple bindings to one key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Run the plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Binding to multiple keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Create multiple bindings to one key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Run the plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Adding a data observer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Set up the dialog and table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Create an observer for a data property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Create the dialog contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Run the plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Debugging your plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Specifying a log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Viewing trace information using log files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Viewing trace information in a platform console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

10

Defining Metadata: A Walkthrough . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Adding custom metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Define metadata fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Define a tagset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Using the plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Customizing the Plug-in Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

11

Web Gallery Plug-ins: A Tutorial Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Creating a Web Gallery plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Add descriptive files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Add HTML template files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Add subfolders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Defining a data model and functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Add a grid using built-in tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Add pagination using built-in tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Add another photo size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Customizing the Web Gallery UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Add a binding to a control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Add the title to the HTML template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Testing the plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Adding a customized tagset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

Contents

7

Define the tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Add the tagset to the gallery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

Preface
The Adobe® Photoshop® Lightroom® Software Development Kit (SDK) is a scripting interface to Lightroom
that allows you to extend and customize Lightroom functionality. Use the SDK API to write plug-ins for
Lightroom. This release allows you to customize the behavior of Lightroom’s export and publish
operations, define Lightroom-specific metadata for photos, and create customized HTML web galleries.

The Lightroom SDK
The Adobe Photoshop Lightroom SDK is available for download from:
http://www.adobe.com/devnet/photoshoplightroom/
The SDK contains these elements (paths are relative to the location that you choose during installation):
LR_SDK/Manual/Lightroom SDK Guide.pdf

This programming guide.

LR_SDK/API Reference/index.html

The home page for a complete API reference in HTML
format.

LR_SDK/Sample Plugins/

Sample code that demonstrates plug-in development.
For details of what these do and how to use them, see
Chapter 8, “SDK Sample Plug-ins.”

flickr.lrdevplugin
ftp_upload.lrdevplugin

custommetadatasample.lrdevplugin

These samples demonstrate the Service Provider
interface.
•

The first creates a service to upload selected photos
to Flickr using Lightroom’s Publish Manager service.

•

The second creates a service that uploads photos to
an FTP server, using a customized Export dialog.

This sample demonstrates the creation of
Lightroom-specific metadata, and the customization of
the Plug-in Manager dialog and behavior.
The sample creates custom metadata fields for use
within Lightroom, and a dialog that displays the values
of those metadata fields for selected photos. It also
demonstrates how to add menu items.

metaexportfilter.lrdevplugin

Demonstrates the Export Filter Provider by defining a
post-process action and a related section in the Export
dialog. This action offers the user a choice of metadata
values to filter on, and removes all photos that do not
match that choice from the export operation. There is a
predefined function, shouldRenderPhoto(), that helps
do this.

8

Preface

About this document

websample.lrwebengine

Demonstrates the web-engine plug-in by defining a
simple HTML gallery.

helloworld.lrdevplugin

This shows the finished code files produced by the
walkthrough in Chapter 9, “Getting Started: A Tutorial
Example.”

9

The walkthrough demonstrates the architecture of
standard plug-ins, and the basic techniques for creating
user-interface controls for Lightroom dialogs and
panels.
mymetadata.lrdevplugin
mysample.lrwebengine

These contain the finished code from the tutorial
walkthroughs in Chapter 10 and Chapter 11.

The Lua language
The SDK defines a Lua-language scripting API. For guidance on using the Lua language, we recommend
reviewing the official Lua web site, http://www.lua.org/, and the book “Programming in Lua, second
edition,” by Roberto Ierusalimschy. Lightroom 5 uses version 5.1.4 of the Lua language.
The Lightroom SDK provides a Lua scripting environment, which extends the Lua languages with an
object-oriented infrastructure; see “The Lightroom SDK scripting environment” on page 12.

About this document
This document has the following sections:
•

Chapter 1, “Using the Lightroom SDK," provides an introduction to the Lightroom SDK, with the basics
of how Lua plug-ins work, and the concepts and terminology of the Lightroom SDK scripting
environment.

•

Chapter 2, “Writing a Lightroom Plug-in," provides an overview of standard plug-in architecture, and
explains how to customize the Plug-in Manager dialog and plug-in loading behavior.

•

Chapter 3, “Creating Export and Publish Services," explains how to use the SDK to create an export
plug-in, which customizes the behavior of Lightroom's Export and Publishing Manager dialogs and
export processing.

•

Chapter 4, “Working with Metadata," explains how to define customized public or private metadata
fields for Lightroom.

•

Chapter 5, “Creating a User Interface for Your Plug-in," explains how to create and populate a dialog
box or a custom section in the Plug-in Manager dialog or Export dialog with user-interface elements,
using the LrView and LrDialogs namespaces.

•

Chapter 6, “Writing a Web-engine Plug-in," explains how to create a Lightroom plug-in that defines a
new type of web engine. This type of plug-in uses a slightly different architecture.

•

Chapter 7, “Using ZStrings for Localization," explains how to localize your plug-in’s user interface for
different languages.

•

Chapter 8, “SDK Sample Plug-ins," walks through the installation and usage of the sample plug-ins
provided with the SDK.

Preface

About this document

10

•

Chapter 9, “Getting Started: A Tutorial Example," walks through a “Hello World” tutorial to help you
create your first plug-in.

•

Chapter 10, “Defining Metadata: A Walkthrough," shows how to define Lightroom-specific metadata
properties for your photos.

•

Chapter 11, “Web Gallery Plug-ins: A Tutorial Example,” shows how to define your own HTML
web-engine plug-in.

Conventions used in this document
The following type styles are used for specific types of text:
Typeface Style

Used for:

Monospace font

Lua code and literal values, such as function names.

Monospace bold

Points of interest in code samples.

Monospace italic

Variables and placeholders.

Regular italic

Introduction of terms.

1

Using the Lightroom SDK
This chapter provides an introduction to the Lightroom SDK:
•

“Writing plug-ins for Lightroom” on page 11 describes the basics of how Lua plug-ins work, including
details of the information file and file-system locations.

•

“The Lightroom SDK scripting environment” on page 12 explains the concepts and terminology of the
Lightroom SDK scripting environment, and provides details of what tools are available to you within
the SDK scripting environment.

Writing plug-ins for Lightroom
The Lightroom SDK allows you to customize and extend certain Lightroom features by creating plug-ins.
For an overview of the plug-in architecture, see Chapter 2, “Writing a Lightroom Plug-in.”
In general, a plug-in consists of Lua-language files (scripts) that define the plug-in functionality, and an
information or manifest file that describes the contents of the plug-in. The information file must have a
specific name, and be placed in a folder with the Lua source files and resource files; the folders may need
to be in specific locations. The type of plug-in is determined by the folder and file placement, and by file
naming conventions.
In the current release these features are extensible:
•

Menu customization: Plug-ins can add new menu items in the Plug-in Extras menu; see Chapter 2,
“Writing a Lightroom Plug-in."

•

Export and publish functionality: You can create an export plug-in, which customizes the behavior of
Lightroom's Export and Publishing Manager dialogs and export processing. You can add or remove
items from the dialog, alter or augment the rendering process, and send images to locations other
than files on the local computer. See Chapter 3, “Creating Export and Publish Services."

•

Metadata: You can define customized public or private metadata fields for Lightroom. Public or
private metadata can be associated with individual photos. You can also define new ways of arranging
the display of metadata within the Library module’s Metadata panel. See Chapter 4, “Working with
Metadata."

•

Web engine functionality: You can create an HTML web-engine plug-in, which defines a new type of
HTML photo gallery. The engines you define appear in the Gallery panel at the upper right of the Web
module. See Chapter 6, “Writing a Web-engine Plug-in.”

The Lightroom SDK provides an API with which to define a user interface for your plug-in; see Chapter 5,
“Creating a User Interface for Your Plug-in."

11

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

12

The Lightroom SDK scripting environment
The SDK defines a Lua-language scripting API. The Lua scripting language is a fast, light-weight,
embeddable scripting language. For information about the language, see http://www.lua.org/.
The Lightroom scripting environment provides a programming structure that includes some
enhancements to the basic Lua-language constructs. This section describes the API usage and
terminology.
•

The API defined for the Lightroom SDK is fully documented in the Lightroom SDK API Reference, which
is part of the SDK. When you have installed the SDK, the home page is at:
LR_SDK_install_location/API Reference/index.html

Namespaces, classes, and objects
Lightroom defines a namespace as a table containing a suite of functions. This is somewhat like the Lua
module; however, Lightroom does not use or support the module system that was introduced in Lua 5.1
(see http://www.lua.org/manual/5.1/manual.html#5.3).
Lua does not have an object-oriented programming model, but it does allow Lua tables to be used in an
object-like fashion, which the Lightroom SDK does. Lightroom’s object and class model is derived from the
one described in Chapter 16 of "Programming in Lua," available online at http://www.lua.org/pil/16.html.
In Lightroom terminology, object and class are used in the typical object-oriented fashion: that is, a class is
a description of a set of behaviors that are associated with a particular data structure, and an object is a
single instance of that class.
•

The Lightroom SDK defines a set of namespaces and a set of classes; see “Accessing namespace
functions directly” on page 12 and “Creating objects” on page 14. Plug-ins cannot define either
namespaces or classes.

•

The Lua language defines built-in namespaces and global functions, of which a subset are accessible
in the Lightroom SDK Lua environment. See “Using built-in Lua features” on page 19.

Accessing namespace functions directly
You can access a namespace by using the built-in function import(); it takes a single parameter, the name
of the namespace to be loaded, and returns the table of functions, which you can then access using dot
notation.
For example:
local LrMD5 = import 'LrMD5' -- assign namespace to local variable
local digest = LrMD5.digest( 'some string' ) -- call "digest()" function in namespace

This example shows the convention of assigning the namespace to a variable of the same name. This
practice is not enforced in any way, but helps avoid confusion.

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

13

The Lightroom SDK defines these namespaces; for complete details, see the Lightroom SDK API Reference.
Namespace

Description

LrApplication

Application-wide information; provides access to the active catalog.

LrBinding

Allows you to define data relationships between UI elements and other
objects.

LrColor

Both a namespace and a class. Allows access to color values, specified using
RGB or grayscale values or by name.

LrDate

Allows you to create and manipulate date-time values.

LrDialogs

Allows you to show messages in predefined modal dialogs.

LrErrors

Allows you to format Lua error strings to be used in error dialogs.

LrExportSettings

Allows you to check or set an image file format for an export operation.

LrFileUtils

Allows you to manipulate files and folders in the file system in a
platform-independent manner.

LrFtp

Both a namespace and a class. The namespace functions allow you to work
with the paths and settings for FTP connections created with the LrFtp class.

LrFunctionContext

Both a namespace and a class. The namespace functions allows you to make
functions calls with defined methods for cleaning up resources allocated
during the execution of a function or task.

LrHttp

Allows you to send and receive data using HTTP. Must be used within a task.

LrLocalization

Allows you to localize your plug-in for use in multiple languages.

LrLogger

Both a namespace and a class. Provides logging capability.

LrMath

Provides additional basic math operations not otherwise available in the Lua
language.

LrMD5

Provides MD5 digest services.

LrPasswords

Provides a mechanism to store passwords in a secure fashion.

LrPathUtils

Allows you to manipulate file-system path strings in a platform-appropriate
way. (All paths are specified in platform-specific syntax.)

LrPhotoInfo

Allows you to get information about individual photo files, such as their
dimensions.

LrPrefs

Allows you define persistent preferences for your plug-in.

LrProgressScope

Both a namespace and a class. Allows you to provide feedback to the user
about the progress of a long-running task

LrRecursionGuard

Both a namespace and a class. Provides a simple recursion guard for function
execution.

LrShell

Provides access to shell functions of the platform file browser (Windows
Explorer in Windows or Finder in Mac OS).

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

Namespace

Description

LrStringUtils

Provides string manipulation utilities.

LrSystemInfo

Provides information about the environment in which Lightroom is running,
such as whether it is 32-bit or 64-bit architecture.

LrTasks

Allows you to start and manage tasks that run cooperatively on Lightroom's
main UI thread.

LrView

Both a namespace and a class. The namespace functions allow you to obtain
the factory object, create bindings between UI elements and data tables, and
share placement between UI elements.

LrXml

Both a namespace and a class. The namespace functions allows you to create
an XML builder object, and to parse existing XML documents into read-only
XML DOM objects.

14

Creating objects
When you use the import() function with a class, it returns a constructor function, rather than a table. Use
the constructor to create objects, which you can initialize with specific property values. You can then
access the functions and properties through the object using colon notation.
This example shows the standard way to create and use an object:
local LrLogger = import 'LrLogger'
-- LrLogger is a constructor function, not a table with more functions
local logger = LrLogger( 'myPlugin' )
-- Calling this function returns an instance of LrLogger, which is assigned to
-- local variable logger. Notice the lowercase naming convention for objects.
logger:enable( 'print' )
logger:warn( 'something bad happened' )
-- Method calls on the object that was just created.

There are some exceptions to this technique. You can create some objects using functions in other objects
or namespaces, such as LrApplication.activeCatalog(). Others are created and passed to you by
Lightroom.
The Lightroom SDK defines these classes; for complete details, see the Lightroom SDK API Reference.
Class

Description

Object creation

LrCatalog

Provides access to a
Lightroom catalog.

Returned by LrApplication.activeCatalog()
Most classes provide a pointer back to the catalog
that contains an object, such as LrPhoto.catalog.

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

Class

Description

Object creation

LrCollection

Provides access to a
photo collection.

Returned by:

LrCollectionSet

LrColor

Provides access to a
photo collection set.

Encapsulates a color.

LrCatalog:createCollection()
LrCatalog:createSmartCollection()
LrCatalog:getActiveSources()
LrCatalog:getCollections()
LrCatalog:getCollectionByLocalIdentifier()
LrCollectionSet:getChildren()
LrCollectionSet:getChildCollections
LrPhoto:getContainedCollections()

Returned by:
LrCatalog:createCollectionSet()
LrCatalog:getCollectionSets()
LrCollectionSet:getChildren()
LrCollection:getParent()
LrCollectionSet:getParent()
LrCollectionSet:getChildCollectionSets()

Import constructor:
local LrColor = import 'LrColor'

LrDevelopPreset

Provides access to a
develop preset.

LrDevelopPreset
Folder

Provides access to a
develop-preset folder.

LrExportContext

Encapsulates an export
context.

Returned by
LrDevelopPresetFolder:getDevelopPresets()

Returned by:
LrApplication.developPresetFolders()
LrDevelopPreset:getParent()

Object is passed to your

processRenderedPhotos() function

LrExportRendition

Encapsulates a single
photo rendition
operation, generated
during an export
operation.

Returned by LrExportSession:renditions()

LrExportSession

Provides access to the list
of photos and renditions
generated during an
export operation.

Import constructor:
local LrExportSession = import
'LrExportSession'

An object is also available as the value of
exportContext.exportSession.
LrFilterContext

Provides access to choices
the user has made in the
Export dialog, and to the
list of photos to be
exported.

An LrFilterContext object is passed to your
plug-in as a parameter to your service script's
postProcessRenderedPhotos function. You cannot
import the namespace or access the properties and
functions in any other way.

15

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

Class

Description

Object creation

LrFolder

Provides access to a
file-system folder that
contains photos.

Returned by:

LrFtp

LrFunctionContext

Both a namespace and a
class. The object
represents an FTP
connection.
Both a namespace and a
class. Use the object to
register the cleanup
handlers for the called
function execution.

LrCatalog:getFolders()
LrCatalog:getActiveSources()
Lrcatalog:getFolderByPath()
LrFolder:getParent()

Import the namespace:
local LrFtp = import 'LrFtp’
•

Use the factory function, LrFtp.create()

Import the namespace:
local LrFunctionContext = import
'LrFunctionContext’
•

Object is passed to functions called using the
namespace calling functions. For example:

LrFunctionContext.callWithContext(
"showCustomDialog",
function(contextObject)
-- body of called function
end)
LrKeyword

Encapsulates a keyword.

Returned by:
LrCatalog:createKeyword()
LrCatalog:getKeywords()
LrKeyword:getChildren()
LrKeyword:getParent()

Provides a mechanism for
writing debug output
that can be viewed with
an external log-viewer
application.

local LrLogger = import
'LrLogger'

LrObservableTable

Implements an
observable properties
table.

Create an observable table by calling
LrBinding.makePropertyTable(). Some API
functions create observable tables for you.

LrPhoto

A single photo or virtual
Returned by many functions of LrCatalog,
copy in Lightroom's active LrCollection, LrExportSession and so on. Many
catalog.
classes provide access to the photo objects that they
are associated with, such as
LrKeyword:getPhotos().

LrPlugin

Provides access to the
plug-in configuration,
including the path and
resources.

LrLogger

Import constructor:

Access the object for your plug-in with the global
variable _PLUGIN.

16

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

Class

Description

Object creation

LrProgressScope

Allows you to provide
feedback to the user
about the progress of a
long-running task.

Import constructor:

LrPublished
Collection

LrPublished
CollectionSet

LrPublishedPhoto

local LrProgressScope = import
'LrProgressScope'

Provides access to a
published-photo
collection.

LrCollection, such as:

Provides access to a
published-photo
collection set.

LrCollectionSet, such as:

Encapsulates the
publishing information
associated with a photo
that is part of a published
collection.

Access functions are parallel to those for

LrCatalog:createPublishedCollection()
LrPublishedCollectionSet:getChildren()

Access functions are parallel to those for

LrCatalog:getPublishedCollectionSets()
LrPublishService:getChildCollectionSets()

Returned by
LrPublishedCollection:getPublishedPhotos()

LrPublishService

Provides access to a
named publishing
service.

Returned by LrCatalog:getPublishServices()

LrRecursionGuard

Provides a simple
recursion guard for
function execution.

Import constructor:

LrVideoExportPreset

LrView

Represents a single video
export preset.
Allows you to construct
dialog box elements.

local LrRecursionGuard = import
'LrRecursionGuard'

Returned by

LrExportSettings.videoExportPresets.

Import the namespace:
local LrView = import 'LrView’
•

When creating a dialog to be invoked from a
menu command, import namespace and obtain
a factory object with the namespace function
LrView.osFactory().

•

When extending a Lightroom dialog, a factory
object is passed to
sectionsForTopOfDialog() and
sectionsForBottomOfDialog()

LrWebViewFactory

Allows you to construct
In a web-engine plug-in’s galleryInfo.lrweb file,
elements for panels in the this object is passed to the views function. It
Web module.
extends the standard view factory with additional
functions.
This object is only available within web-engine
plug-ins.

17

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

Class

Description

Object creation

LrXml

Both a namespace and a
class. There are two types
of object:

Import the namespace:

•

•

A builder object
allows you to create
and manipulate XML
documents.

18

local LrXml = import 'LrXml’
•

Create a builder object with the namespace
function LrXml.createXmlBuilder().

•

Create a DOM object with the namespace
function LrXml.parseXml().

A DOM object is
read-only, and allows
you to examine an
existing XML
document.

Accessing object functions and properties
A few classes (LrFtp, LrView, LrXml, and LrFunctionContext) act as both classes and namespaces, and
allow you to call some functions directly in the imported namespace, using dot notation. By convention,
the documentation uses lowercase names, as well as colon notation, to indicate that a function is called on
an instance. For example:
LrFtp.appendFtpPaths() -- A namespace function
ftpConnection:path() -- An object function

Classes define both functions and properties. To access properties in objects, use the dot notation. Again,
the documentation uses the lowercase naming convention to indicate an instance of a class:
exportRendition.photo -- An object property

A property can have no value; a nil property value is not the equivalent of false, zero, or the empty string.
Setting a nil value for a property that has a default value causes the property to revert to the default.

Using function contexts for error handling
The LrFunctionContext namespace and class is a programming utility for error handling.
Use LrFunctionContext.callWithContext() to wrap a function call. This allows you to attach any
number of handler functions to the call that respond to errors that may occur during the execution of the
wrapped function, or clean up resources regardless of how the wrapped function terminates. If you attach
multiple cleanup or error handlers to the wrapped function, the handlers are called in reverse order of
attachment.
Some of the functions in LrTasks work in conjunction with LrFunctionContext to provide standardized
error reporting behavior. For instance, LrTasks.startAsyncTask() calls
LrDialogs.attachErrorDialogToFunctionContext(). This ensures that errors that occur during the
execution of the task are reported to the user and not silently forgotten. Lightroom provides predefined
error dialogs that you can customize with explanatory messages, as shown in the following example. You
can use LrTasks.startAsyncTaskWithoutErrorHandler() if you wish to provide your own error
reporting instead.

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

19

Example: Function context with an error dialog
local LrDialogs = import 'LrDialogs'
local LrErrors = import 'LrErrors'
local LrFunctionContext = import 'LrFunctionContext'
LrFunctionContext.callWithContext( 'error handling demo', function ( context )
-- If an error is thrown during this function call context,
-- show a standard error dialog.
LrDialogs.attachErrorDialogToFunctionContext( context )
-- The code needed to perform your task goes here
-- For illustration, force an error here, throw error two different ways
if showInternalError then -- in some case
error "Example of an internal error" --call built-in error() function
else -- otherwise, use the LrErrors throw function
LrErrors.throwUserError( LOC "$$$/MyPlugin/Error/Example=Example of
a localized error message." )
end
end )

This shows the predefined error dialog with customized text, according to how the error was thrown:

Using built-in Lua features
The Lua language defines built-in namespaces and global functions, of which only a subset are supported
in the Lightroom SDK Lua environment, as follows:
Lua global functions
•

Available in Lightroom:
assert(), dofile(), error(), getmetatable(), ipairs(), load(), loadfile(),
loadstring(), next(), pairs(), pcall(), rawequal(), rawget(), rawset(), select(),
setmetatable(), tonumber(), tostring(), type(), unpack()

•

Not available in Lightroom:
collectgarbage(), gcinfo(), getfenv(), module(), newproxy(), package(), setfenv()

Lua standard namespaces
•

Available in Lightroom: io, math, string

CHAPTER 1: Using the Lightroom SDK
•

Not available in Lightroom: package

•

Partially available:

The Lightroom SDK scripting environment

20

•

os: Contains only the functions clock(), date(), time(), and tmpname(). All other functions
removed. Use LrFileUtils, LrDate, and LrTasks instead.

•

table: Contains all functions except getn(), setn(), and maxn(), which are deprecated as of Lua

5.1.

•

coroutine: Contains only the functions canYield() and running().

•

debug: Contains only the function getInfo().

Defining function contexts and tasks
Your plug-in can use a function context to create and manage a task, which is a kind of lightweight process
that runs cooperatively on Lightroom's main (user interface) thread. If your service defines a lengthy
export operation that would block the main Lightroom process, you should run it as a background task,
using functions such as LrFunctionContext.postAsyncTaskWithContext(). Some API functions, such
as those in the LrHttp namespace, are only available when called from within a background task.
The LrFunctionContext object helps you clean up resources following the execution of a function. You
can register any number of cleanup handlers to respond to the success or failure of a function. You must
create property tables within a function context, so that Lightroom can remove notifications when the
table is no longer needed.
You do not create instances of LrFunctionContext directly. They are created by the calling functions, and
exist only for the lifetime of the function call or task. Access the calling functions, such as
LrFunctionContext.postAsyncTaskWithContext(), directly from the imported namespace. A
functionContext object is passed as the first parameter of the call, followed by any other parameters you
provide. Use the passed object to provide the cleanup handlers for the called function execution.
In general, you are responsible for creating tasks when needed. There are some exceptions, however. Many
of the plug-in callback functions in the export and publish APIs are called from within tasks that Lightroom
starts. These are marked as such in the API reference.
For details of the LrFunctionContext and LrTasks functions, see the Lightroom SDK API Reference.

Including scripts with require()
Lightroom defines a require() function that works in a similar, but more narrowly-defined, fashion from
the version that exists in Lua. The require() function takes a single parameter, which is the name of
another Lua file in the same plug-in. On the first call, this file is loaded and executed in the context of its
plug-in; the return value is saved. If the require() function is called again in the same plug-in, its saved
value is used (unless the entire plug-in has been garbage collected, in which case the required file is
loaded and executed again).
A script to be executed this way typically has the effect of defining a table containing a suite of functions.
For example:
SomeFile.lua
SomeFile = {}
-- Typically a file that is required will define a global table whose name

CHAPTER 1: Using the Lightroom SDK

The Lightroom SDK scripting environment

21

-- matches the file name.
-- Note that this global is defined in a special function environment for your
-- plug-in and does not affect Lightroom as a whole.
-- You can give this table any name that does not conflict with built-in names
-- and keywords from Lua and Lightroom. In general, avoid names that start with
-- Lr to avoid conflicts with future versions of Lightroom.
function SomeFile.doSomething( arg )
return tostring( arg )
end

Usage of require()
require 'SomeFile.lua'
-- Causes SomeFile.lua to be executed and the value of SomeFile defined above
-- becomes available in the scope of this file.
SomeFile.doSomething( 42 )

Lua syntax notes
For people unfamiliar with the Lua language, here are some syntax conventions and usage notes.
•

Literal strings can be surrounded by either single or double quotes. These two statements are
equivalent:
local a = 'my string'
local a = "my string"

•

Semicolons at the ends of statements are optional. We typically omit them.

•

If you call a function with a single parameter that is a string literal or a table, you can omit the
parentheses around the argument list. This is frequently done when calling the built-in functions
import() and require().
These three statements are equivalent (where func is a variable containing a valid function):
func( "foo" )
func "foo"
func 'foo'

These two statements are also equivalent; the simpler syntax is commonly used when building view
descriptions:
func( { a = 1, b = 2 } )
func{ a = 1, b = 2 }
•

It is useful to read the chapter on table constructors (http://www.lua.org/pil/3.6.html). There are
several shorthand formats that we use widely, especially in view descriptions. For example, these
forms are equivalent:
local t = { a = 1, b = 2 }
local t = { [ "a" ] = 1, [ "b" ] = 2 }
local t = {}; t.a = 1; t.b = 2

•

Lua defines an array as a table with numbered keys. Arrays in Lua are 1-based; that is, the first item in
the array is at index 1, not index 0.

•

The value nil evaluates to a Boolean value of false, but numbers (including 0) evaluate to true. Thus,
in a conditional, only nil and false are considered false. If you use 0 as the condition of an if or
while statement for example, the statement is executed, because the number 0 is a true value.

CHAPTER 1: Using the Lightroom SDK
•

The Lightroom SDK scripting environment

22

Lightroom defines Boolean globals, WIN_ENV and MAC_ENV, which you can use to determine which
platform your script is running on. The LrSystemInfo namespace (first available in version 3.0 of the
Lightroom SDK) can provide additional information about the platform, including whether is 32-bit or
64-bit.

2

Writing a Lightroom Plug-in
The Lightroom SDK allows you to create plug-ins that customize the behavior of Lightroom in specific
ways. Most types of plug-in share a common architecture, which is discussed in this chapter.
•

Web Gallery plug-ins use a different architecture; see Chapter 6, “Writing a Web-engine Plug-in.”

The Plug-in Manager dialog allows a user to load plug-ins from any location, enable and disable loaded
plug-ins, and remove unused plug-ins. Your plug-in can customize the dialog by adding sections. See
“Customizing plug-in load behavior” on page 33.

Writing standard plug-ins for Lightroom
The Lightroom SDK allows you to customize the behavior of Lightroom in specific ways using a standard
plug-in (as opposed to a web-engine plug-in). The behavior implemented by your plug-in is provided by
one or more Lua scripts. An information file installed in a standard plug-in folder identifies your plug-in
scripts to Lightroom, and associates the plug-in with a unique name.
•

You can add items to the File, Library, or Help menus to start an operation.

•

Your plug-in can add a new export or publish destination with an Export Service Provider or Publish
Service Provider. Such a service can also customize the Export or Publishing Manager dialog by adding
and removing sections as appropriate for the destination when the user selects it. See “Creating an
export or publish service” on page 37.

•

Your plug-in can intercept the export process with an Export Filter Provider, which can apply further
processing to photos that the user has chosen to export. The post-process action that a filter defines is
applied after Lightroom’s initial rendering, and before the photos are sent to the final destination. Each
filter can add a section to the Export dialog, in which the user can select options and set parameters.
See “Adding an export post-process action” on page 43.

•

In addition to or instead of defining export customizations, your plug-in can define custom metadata
fields for Lightroom. See Chapter 4, “Working with Metadata."

Declaring the contents of a plug-in
In addition to the Lua script or scripts that define your extension to Lightroom functionality, your plug-in
must contain a file named Info.lua that describes the plug-in to Lightroom, using a Lua table of
descriptive items. The table can or must include these items:
LrSdkVersion

Required
number

LrSdkMinimumVersion

Optional
number

The preferred version of the Lightroom SDK for this plugin. Should be set to .0 for the current release; older plugins may have a value of 1.3, 1.4, 2.0, 3.0, or .0.
The minimum version of the SDK that this plug-in can use.
If your plug-in works with Lightroom 2.0, 3.0,or .0 but
it also provides new features specific to Lightroom , set
this value to 2.0 and LrSdkVersion to .0. Default is the
value of LrSdkVersion.
23

CHAPTER 2: Writing a Lightroom Plug-in

LrToolkitIdentifier

Writing standard plug-ins for Lightroom

Required
string

A string that uniquely identifies your plug-in. Use
Java-style package names (your domain name in reversed
sequence).
You can use the Plug-in Manager to add multiple plug-ins
with the same identifier, but only one of them can be
enabled. If you enable one, any other plug-in that shares
the same plug-in ID is automatically disabled.
Note that com.adobe.*, which is used in the examples, is
reserved for plug-ins written by Adobe; your own plug-ins
will use your own domain name (com.myCompany.*).

LrPluginName

LrPluginInfoProvider

Required
for 2.0 or
newer

A localizable string for the plug-in’s display name, which
appears in the Plug-in Manager dialog. Required for SDK
version 2.0 or newer; ignored by earlier versions.

string

If a plug-in defined for an earlier version is loaded in
Lightroom 2.0 or newer, the Plug-in Manager displays the
title of the first Export Service Provider, or if no Export
Service Provider is defined, the base name of the plug-in
folder.

Optional

The name of the Lua file (service definition script) to be
executed when the plug-in is loaded. This script can define
functions that run when plug-in is selected or deselected
in the Plug-in Manager dialog, and can add sections to the
Plug-in Manager dialog that are shown when the plug-in is
selected. It See “Customizing plug-in load behavior” on
page 33.

string

Ignored in any Lightroom version older than 2.0.
LrInitPlugin

Optional
string

The name of a Lua script that is loaded and executed when
your plug-in is loaded or reloaded. See “Customizing
plug-in load behavior” on page 33
This item is ignored if LrSdkVersion is less than 2.0.

LrForceInitPlugin

Optional
Boolean

When true, forces the initialization script to run at
application startup, even for plug-ins that do not provide
export or publish services or define custom metadata, as
long as the plug-in contributes at least a menu item.
Otherwise, the initialization script does not run until the
plug-in’s first use.
Ignored in any Lightroom version older than 4.0.

LrPluginInfoUrl

Optional
string

The URL of your web site, or a page that provides
information about your plug-in. See “Customizing plug-in
load behavior” on page 33
Ignored in any Lightroom version older than 2.0.

24

CHAPTER 2: Writing a Lightroom Plug-in

LrShutdownPlugin

Writing standard plug-ins for Lightroom

Optional
string

The name of a Lua script that is loaded and executed when
the user unloads this plug-in.
This script is executed only if the user loaded or reloaded
the plug-in through the Plug-in Manager dialog, or
approved updating of the catalog structure, during the
current Lightroom session.
Ignored in any Lightroom version older than 3.0.

LrShutdownApp

Optional
string

The name of a Lua script that is loaded and executed when
Lightroom is shutting down. See “Application termination
script” on page 29.
This item is ignored if LrSdkVersion is less than 4.0.

LrEnablePlugin

Optional
string

LrDisablePlugin

Optional
string

VERSION

Optional
table

The name of a Lua script that is called when the user
enables this plug-in from the Plug-in Manager dialog.
Ignored in any Lightroom version older than 3.0.
The name of a Lua script that is called when the user
disables this plug-in from the Plug-in Manager dialog.
Ignored in any Lightroom version older than 3.0.
Allows you to provide a version number for your plug-in
that is displayed in the Plug-in Manager dialog. The version
number is for your own use, and need not relate to
Lightroom's version number.
The table has these members:
major (number)
minor (number )
revision (number)
build (number)
display (string)

The numeric values are assembled in order to create a
version designation in the default format:
major.minor.revision.build

The build value is omitted if zero; both revision and
build are omitted if both are zero.
If you prefer to display a version number in a different
format, include the display string in the display field. You
can use LOC to localize the string; see “The LOC function”
on page 150.
Ignored in any Lightroom version older than 2.0.

25

CHAPTER 2: Writing a Lightroom Plug-in

LrExportMenuItems
LrLibraryMenuItems
LrHelpMenuItems

LrExportFilterProvider

Writing standard plug-ins for Lightroom

Optional
table of
tables

Optional
table of
tables

These allow you to add new script-defined menu items to
the Plug-in Extras submenus that appear in Lightroom’s
File, Library, and Help menus.
For details of the member tables, see “Defining menu items
for a plug-in” on page 35:
Adds one or more new export filters, which can process
photos before they are rendered for the export destination.
Each item is a table with these entries:
title (string): The display name of the filter.
file (string): The name of the Lua file (filter definition
script) to be executed when the filter is chosen. See
“Adding an export post-process action” on page 43.
id (string): A unique identifying string for this filter.
requiresFilter (string, optional): The identifier for
another filter that must be used with this one.

Can be combined with other services (export services,
custom metadata) or can be the only service provided by
the plug-in.
Ignored in any Lightroom version older than 2.0.
URLHandler

Optional
string

26

Optional. The name of a file that provides custom URL
handling. The file must return a table that contains a
'URLHandler' entry. This must be a function that takes a
URL as a parameter.
Lightroom is configured to be the registered receiver of
URLs starting with 'lightroom://'. When it receives such
a URL, it checks registered handlers to find an appropriate
one. For example, the plug-in with the ID 'my.plugin.id'
can register a handler for URLs starting with
'lightroom://my.plugin.id'.
Ignored in any Lightroom version older than 4.0.

CHAPTER 2: Writing a Lightroom Plug-in

LrExportServiceProvider

Writing standard plug-ins for Lightroom

Optional
table of
tables

Adds one or more new export destinations or publish
service providers.
Each item is a table with these entries:
title (string): The display name of this export

destination.

file (string): The name of the Lua file (service definition

script) to be executed when the export destination or
publish service is chosen. See “Defining an export
service” on page 37.

builtInPresetsDir (string, optional): The name of a

subdirectory in the plug-in directory that contains
predefined export settings values. This must be a
simple folder name; it cannot contain any
path-significant characters, such as slashes.
Lightroom preset files are identified by the
.lrtemplate extension. (Publish services are not
associated with presets.)

id (string, optional): A unique identifier for this export
service. If none is provided, a simple consecutive
number value (1, 2, 3...) is assigned.

Can be combined with other services (export filters,
custom metadata) or can be the only service provided by
the plug-in.
LrMetadataProvider

Optional
table of
tables

Adds custom metadata fields, available only in Lightroom.
There can be only one such item in a plug-in. It contains a
string, the name of the Lua file (metadata definition script)
that defines the fields. See “Adding custom metadata” on
page 71.
Can be combined with other services (export services,
export filters) or can be the only service provided by the
plug-in.
Ignored in any Lightroom version older than 2.0.

LrMetadataTagsetFactory

Optional
table of
tables

Adds a tagset of predefined metadata fields. The user can
select defined metadata tagsets from a menu in the
Metadata panel. Some tagsets are supplied by Lightroom;
this allows your plug-in to supply additional tagsets. See
“Adding custom metadata tagsets” on page 76.
Ignored in any Lightroom version older than 2.0.

27

CHAPTER 2: Writing a Lightroom Plug-in

LrAlsoUseBuiltInTranslations

Writing standard plug-ins for Lightroom

Optional
Boolean

28

Controls behavior of built-in LOC function. When true,
strings that are not found in the plug-in’s translation file are
checked against Lightroom’s translation file for the current
language.
Note that string keys are not guaranteed to remain the
same across version releases.
Ignored in any Lightroom version older than 3.0.

LrLimitNumberOfTempRenditions

Optional
Boolean

Controls whether Lightroom will throttle the number of
temporary image files on disk waiting for the plug-in’s
processing during export. The intent of this option is to
allow protection against high disk space consumption
during large exports.
If true, the plug-in is expected to remove the temporary
rendition files when it is done with them.
Ignored in any Lightroom version older than 5.0.

The loader environment
The Info.lua file is a special Lua environment that is much more restrictive than the general SDK Lua
environment in which other scripts run.
•

The standard Lua namespace string is available, and you can use the LOC function for localization of
display strings in this file (see Chapter 7, “Using ZStrings for Localization“).

•

You can use WIN_ENV and MAC_ENV environment variables, and the _VERSION variable that contains
most of the version information otherwise available through LrApplication.versionTable().

However, you cannot use any of the other Lua or Lightroom globals defined in the SDK scripting
environment, (see “The Lightroom SDK scripting environment” on page 12). For example, you cannot use
import or require in this context.
Here is an example of an Info.lua file for a plug-in that adds items to the Lightroom menus:
return {
LrSdkVersion = 5.0,
LrSdkMinimumVersion = 1.3, -- minimum SDK version required by this plug-in
LrToolkitIdentifier = 'com.adobe.lightroom.sdk.helloworld',
LrPluginName = LOC "$$$/HelloWorld/PluginName=Hello World Sample",
-- Add the menu item to the File menu.
LrExportMenuItems = {
title = "Hello World Dialog",
file = "ExportMenuItem.lua",
},
-- Add the menu item to the Library menu.
LrLibraryMenuItems = {
{
title = LOC "$$$/HelloWorld/CustomDialog=Hello World Custom Dialog",

CHAPTER 2: Writing a Lightroom Plug-in

Writing standard plug-ins for Lightroom

29

file = "ShowCustomDialog.lua",
},
{
title = LOC "$$$/HelloWorld/MultiBind=Hello world Custom Dialog with
MultipleBind",
file = "CustomDialogWithMultipleBind.lua",
},
{
title = LOC "$$$/HelloWorld/RadioButtons=Hello world RadioButtons",
file = "RadioButtons.lua",
},
{
title = LOC "$$$/HelloWorld/DialogObserver=Hello world Custom Dialog with
Observer",
file = "CustomDialogWithObserver.lua",
},
},
VERSION = { major=3, minor=0, revision=0, build=200000, },
}

You can find more examples in the sample plug-ins provided with the SDK.

Application termination script
LrShutdownApp specifies a script that is called at application shutdown time. This script must return a
table that contains an LrShutdownFunction member; this function takes two arguments, doneFunction
and progressFunction, in that order.
•

The doneFunction takes no arguments; it is called when the plug-in's shutdown tasks have been
completed (which allows the plug-in's shutdown operation to use asynchronous tasks).

•

The progressFunction is invoked to report progress during the execution of the plug-in's shutdown
tasks. This function takes two arguments, percent complete (number between 0 and 1) and a
descriptive display string for the progress dialog. It must return a Boolean value, true if the user clicks
Cancel in the progress dialog.

If 10 seconds pass without progress being reported by a call to the progressFunction, the shutdown task
is assumed hung or terminated, and application shutdown proceeds. The plug-in shutdown must monitor
this status and respond appropriately to it.
The LrDialogs namespace is not available in the environment of the shutdown task.

Delivering a standard plug-in
Package your Lua files (the information file, Info.lua, and all Lua scripts) in a single folder with a suffix of
.lrplugin; for example, MyPluginName.lrplugin.
NOTE: In Mac OS, the suffix .lrplugin creates a package, which looks like a single file. For convenience,
you can use the suffix .lrdevplugin during development, and change the extension to .lrplugin for
delivery. The .lrdevplugin suffix is recognized by Lightroom but does not trigger the package behavior
in the Mac OS Finder.
A plug-in folder can reside in any location on the hard drive. Users can load the plug-in using the Add
button in the Plug-in Manager. Once it is added, users can enable or disable it through the dialog, reload it
using the Plug-in Author Tools in the dialog, or unload it using the Remove button.

CHAPTER 2: Writing a Lightroom Plug-in

Writing standard plug-ins for Lightroom

30

The standard Plug-in Manager dialog in Lightroom looks like this:

Your plug-in can customize the Plug-in Manager, adding sections that appear when a user selects your
plug-in in the dialog. For example, in the following figure, the plug-in called “Plug-in Info Sample” defines
two custom sections, one above and one below the Lightroom-defined sections. They appear only when
the plug-in is selected in the list. The sections are collapsible, and you can define a descriptive string (a
synopsis) to appear on the right side when the section is closed.

CHAPTER 2: Writing a Lightroom Plug-in

Writing standard plug-ins for Lightroom

31

For details of how to define these sections, see See “Adding custom sections to the Plug-in Manager” on
page 34.

Automatic plug-in loading
Lightroom automatically checks for plug-ins in the standard Modules folder where other Lightroom
settings are stored:
In Mac OS (current user)

~/Library/Application Support/Adobe/Lightroom/Modules

In Mac OS (all users)

/Library/Application Support/Adobe/Lightroom/Modules

In Windows XP

C:\Documents and Users\username\Application
Data\Adobe\Lightroom\Modules

In Windows 7/Vista

C:\Users\username\AppData\Roaming\Adobe\Lightroom\Modules

You may want to use this location if, for example, you are writing an installer that installs a Lightroom
plug-in and also installs a helper application.
Plug-ins that are installed in this location are automatically listed in the Plug-in Manager dialog. You can
use the dialog to enable or disable such a plug-in, but not to remove it. The Remove button is dimmed
when such a plug-in is selected.

CHAPTER 2: Writing a Lightroom Plug-in

Writing standard plug-ins for Lightroom

32

Debugging standard plug-ins
The Plug-in Manager also provides access to tools for plug-in authors.

This section is generally not needed by end users, and is closed by default. If you open the "Plug-in Author
Tools" section, you can:
•

Reload a plug-in after you make code changes.

•

Choose to have Lightroom reload the plug-in automatically on each export or publish operation.
NOTE: Reloading a plug-in interactively or automatically after export does not reload any localization
dictionaries supplied with that plug-in. The translation dictionaries are read only when the plug-in is
first loaded or Lightroom is restarted. See Chapter 7, “Using ZStrings for Localization.”

•

Choose a file to which to save diagnostic messages if a plug-in fails to load, or encounters an error at
any stage of its operation.

The Lightroom SDK does not supply a development environment in which to debug your plug-ins, but it
does supply the LrLogger namespace, which allows you to configure a log file and viewer for trace
information of various kinds, and add tracing statements to your scripts. For an example, see “Debugging
your plug-in” on page 186.

Finding deprecated calls
You can add a debugging flag to your configuration file (config.lua) to help you find occurrences of calls
to deprecated functionality in your plug-in.
sdkDeprecation.action=throw|log

When you specify the action throw, Lightroom throws an exception each time a deprecated call is
executed.
To write deprecated call occurrences to a file, you must specify the action log, and also define this logger
in your config.lua file:
loggers.AgSdkDeprecation = {
logLevel = "info",
action = "logfile",
}

Lightroom writes log message to this file:
•

(Windows) \My Documents\AgSdkDeprecation.log

•

(Mac OS) ~/Documents/AgSdkDeprecation.log.

CHAPTER 2: Writing a Lightroom Plug-in

Customizing plug-in load behavior

33

Customizing plug-in load behavior
You can customize your plug-in’s behavior when it is loaded or selected in the Plug-in Manager dialog. To
do this, the Info.lua file for your plug-in can include these entries:
•

LrPluginInfoProvider points to a script that can return any or all of the following function
definitions which customize appearance or behavior of the Plug-in Manager dialog when the plug-in
is selected:

Item

Description

startDialog
endDialog

Initialization and termination functions that run when your plug-in
is selected or deselected in the Plug-in Manager dialog.
The same items are defined slightly differently in an Export Service
Provider to run when the service is selected or deselected in the
Export dialog; see “Initialization and termination functions for the
Plug-in Manager” on page 34.

sectionsForTopOfDialog
sectionsForBottomOfDialog

Definitions for one or more new sections to display in the Plug-in
Manager dialog when your plug-in is selected in the dialog.
The same items can be defined in an Export Service Provider or
Export Filter Provider to customize the Export dialog when the
service or filter is selected or deselected there; see “Adding custom
sections to the Plug-in Manager” on page 34 for details.

•

LrInitPlugin points to a script that runs when the plug-in is loaded or reloaded. You can use this to

initialize values in your plug-in’s global function environment, which are protected from garbage
collection. When the plug-in is reloaded, a new environment is created. All previous values are
discarded and this function is executed again.
•

LrShutdownPlugin and LrShutdownApp point to scripts that allow you to control the termination
procedure for your plug-in, specified by LrShutdownPlugin and LrShutdownApp.. You can use these
to clean up private data. See “Application termination script” on page 29.

•

LrPluginInfoUrl gives the URL of your web site, or a page that provides information about your
plug-in. This URL is displayed in the Status section of the Plug-in Manager dialog when your plug-in is
loaded and selected. The URL is also displayed as part of the error message if your plug-in fails to load
properly or cannot be found.

•

LrEnablePlugin and LrDisablePlugin provide functions to be called when your plug-in is enabled

or disabled in the Plug-in Manager dialog.
For example:

return {
LrSdkVersion = 5.0,
LrSdkMinimumVersion = 2.0, -- minimum SDK version required by this plug-in
LrToolkitIdentifier = 'com.adobe.lightroom.sample.plug-in-info',
LrPluginName = LOC "$$$/PluginInfo/Name=Plug-in Info Sample",
LrPluginInfoProvider = 'PluginInfoProvider.lua',
LrInitPlugin = 'PluginInit.lua',
LrPluginInfoUrl = 'http://www.mycompany.com/lrplugin_info.html',
}

CHAPTER 2: Writing a Lightroom Plug-in

Customizing plug-in load behavior

34

Initialization and termination functions for the Plug-in Manager
In addition to the LrInitPlugin and LrShutdownPlugin scripts that are run on load and unload, you can
provide functions to be called when your plug-in is selected or deselected. To do so, the service definition
script for your Plug-in Info Provider should return these table entries, which contain the function
definitions:
startDialog = function( propertyTable ) ... end,
endDialog = function( propertyTable ) ... end,

When the functions are defined in a Plug-in Info Provider:
•

The startDialog function is called whenever your plug-in is selected in the Plug-in Manager.

•

The endDialog function is called when the user deselects the plug-in in the Plug-in Manager.

NOTE: These same entries can be supplied by an Export Service Provider, although the definitions are
slightly different. Functions defined in an Export Service Provider are executed only when the plug-in is
selected in the Export dialog, never from the Plug-in Manager dialog. See “Initialization and termination
functions for services” on page 40.
The propertyTable parameter for both functions is an empty, observable table which you can use to keep
private data for your plug-in. (See “Binding UI values to data values” on page 97.) This table is discarded
when your plug-in is deselected in the Plug-in Manager or when the Plug-in Manager dialog is closed. It is
not preserved across sessions. You can use LrPreferences if you want to save information across
invocations.
These are blocking calls. If you need to start a long-running task (such as network access), create a task
using the LrTasks namespace. See “Defining function contexts and tasks” on page 20.

Adding custom sections to the Plug-in Manager
Your plug-in can define one or more sections to be displayed in the Plug-in Manager dialog (when defined
in an LrPluginInfoProvider entry) or in the Export or Publishing Manager dialog (when defined in an
LrExportServiceProvider entry). The custom sections can be shown above or below the Lightroom
standard sections for the dialog.
To customize the dialog, define a function that returns a table of sections, defined using LrView objects.
The function is the value of one of these service entries:
sectionsForTopOfDialog = function( viewFactory, propertyTable ) ... end,
sectionsForBottomOfDialog = function( viewFactory, propertyTable ) ... end,

NOTE: Similar functions can be defined in an Export Service Provider, to customize the Export dialog
when the export destination is selected or the Publishing Manager dialog for a publish service, and
also in an Export Filter Provider, to add a section to the dialog when a post-process action is selected.
See “Customizing the Export and Publishing Manager dialogs” on page 55 and “Adding an export
post-process action” on page 43.
Lightroom passes your function a factory object which allows you to create the LrView objects that define
the elements of your sections; that is, UI controls, such as buttons and text, and containers that group the
controls and determine the layout. For additional details of the dialog elements you can create with
LrView, see “Adding custom dialog views” on page 85.”

CHAPTER 2: Writing a Lightroom Plug-in

Defining menu items for a plug-in

35

The function that you define here returns a table of tables, where each table defines one dialog section:
sectionsForTopOfDialog = function( viewFactory, propertyTable )
return {
{ ...section entry ... },
{ ...section entry ... },
...
}
}
end

A section entry table defines the contents of an implicit container, which Lightroom creates to hold your
view hierarchy.
•

Each section entry sets a title and synopsis for the section; the section is identified by the title
text on the left, and is collapsible. When in the collapsed state, the synopsis text is shown on the
right.

•

The rest of the table entry creates the UI elements that are shown when the section is expanded. To
create the UI elements, use the LrView factory passed to your top-level sectionsFor... function.
This process is explained in more detail in “Adding custom dialog views” on page 85.

When adding sections to the Plug-in Manager, the propertyTable parameter for both functions is an empty,
observable table which you can use to keep private data for your plug-in for a dynamic user interface. See
“Binding UI values to data values” on page 97.

Defining menu items for a plug-in
To define a menu item that starts your plug-in’s UI, or performs any other script-defined operation, the
table returned by your Info.lua file must include one of these items:

CHAPTER 2: Writing a Lightroom Plug-in

Defining menu items for a plug-in

36

LrExportMenuItems
LrLibraryMenuItems
LrHelpMenuItems
•

Items that you add in LrExportMenuItems appear in the Plug-in Extras submenu of the File menu
(immediately below the Export section).

•

Items that you add to the Library and Help menus appear in the Plug-in Extras submenu of those
menus.

Each item is a table of tables, and each member table defines one menu item. The member table for a
menu item should contain these entries:
title

(String) The display name of the menu item.

file

(String) The name of the Lua file (service definition script) to be executed when the menu
item is chosen. See “Defining an export service” on page 37.

enabledWhen

(String, optional) A condition under which to enable this menu item. One of:
•

photosAvailable: Item enabled when any photos or videos are available in the

grid.
•

photosSelected: Item enabled when any photos are selected. Ignores videos.

•

videosSelected: Item enabled when any videos are selected. Ignores still photos.

•

anythingSelected: Item enabled when any photos or videos are selected.

If the selection is very large (>5000 photos), menu items are enabled regardless of this
value.
In Windows, the title string can include an ampersand (&) character in the name to make the following
character a keyboard shortcut or accelerator that invokes that item. (This feature is not available in Mac OS;
on that platform, the & character is automatically removed if present.)
For example, suppose the table returned by your Info.lua file contains this item:
LrExportMenuItems = { title = 'My &Plugin', file = 'somefile.lua' }

This would create a command in the File > Plug-in Extras menu with the label “My Plugin”. The command
would execute the script found in somefile.lua.
The user can invoke this command using the keyboard accelerator sequence ALT F + U + ENTER + P.
•

ALT F brings up the File menu

•

U is the keyboard accelerator for the Plug-in Extras submenu

•

P is the keyboard accelerator for the new command

3

Creating Export and Publish Services
Plug-ins can customize Lightroom's export and publish behavior. You can:
•

Create an Export Filter that modifies a photo after Lightroom performs the initial rendering, but before
it is passed to it final export destination.

•

Alter the rendering process, or define post-processing actions for rendered photos.

•

Send rendered images to locations other than files on the local computer.

•

Customize the Export and Publishing Manager dialogs by adding or removing sections.

Creating an export or publish service
Lightroom offers two customizable mechanisms for transferring photos to an external location: export and
publish.
•

Export is a one-time operation: the user selects some photos, the photos are rendered once and
transferred to their destination. Lightroom maintains no further record of the export (although some
plug-ins do retain such a record via custom metadata). By default, Lightroom provides export services
for a user-selected location on the local hard drive and CD/DVD drive. Plug-ins can define export
services to extend this support to other destinations (typically web services or devices). See “Defining
an export service” on page 37.

•

Publish is similar to export, but represents an ongoing relationship between Lightroom and the
destination. You publish a collection (or many collections) of photos to a location when you want
them to stay up to date as you change the photos. To publish, the user establishes a connection to a
destination (typically, but not necessarily, a web service) in the Publishing Manager dialog. By default,
Lightroom provides publish service support for user-selected locations on the local hard drive and
Flickr. As with export services, plug-ins can define publish services to extend this support to other
destinations. See “Defining a publish service” on page 41.

Though they are presented differently, there is a lot in common between these two mechanisms and they
share much of the same API. Export services are the simpler of the two, so we’ll start by describing this API,
then describe additional functionality that is specific to publish services.

Defining an export service
To define the functionality of your export service, write a Lua script that returns a table; each predefined
entry in the table describes a specific type of customization. You then declare the name of your service and
associate it with the defining script, in the same way you declare any plug-in.
To declare an Export Service Provider, add the following block to your Info.lua file:
LrExportServiceProvider = {
title = "Service Name", -- this string appears as the Export destination
file = "MyExportServiceProvider.lua", -- the service definition script
builtInPresetsDir = "myPresets", -- an optional subfolder for presets
},

37

Defining an export service 38

CHAPTER 3: Creating Export and Publish Services

The title and file entries are required. You can use the built-in function LOC and a ZString if you wish to
localize the service’s title; see details in Chapter 7, “Using ZStrings for Localization.”
The service definition script should return a table that contains:
•

A pair of functions that initialize and terminate your export service.

•

Settings that you define for your export service.

•

One or more items that define the desired customizations for the Export dialog. These types of
customizations are defined:

•

•

Restrict the built-in services offered by the Export dialog.

•

Customize the Export dialog by defining new sections.

A function that defines the export operation to be performed on rendered photos (required).

Here is an example of a table returned by a service definition script:
return {
startDialog = function( propertyTable ) ... end,
endDialog = function( propertyTable, why ) ... end,
exportPresetFields = { { key = 'myPluginSetting', default = 'Initial value' } },
showSections = { 'fileNaming', 'imageSettings' },
sectionsForBottomOfDialog = function( viewFactory, propertyTable ) ... end,
processRenderedPhotos = function( functionContext, exportContext ) ... end
}

These are the specific items that can be in the table returned by the service definition script for an Export
or Publish Service Provider:
Item

Description

startDialog
endDialog

Initialization and termination functions for your plug-in; see
“Initialization and termination functions for services” on page 40.

exportPresetFields

A set of properties that you define for your plug-in that you want
to be persistent between sessions. See “Remembering user
choices” on page 59. These are added to the built-in settings
defined by Lightroom; see “Lightroom built-in property keys” on
page 61.

processRenderedPhotos

A callback function that manages the rendering and subsequent
handling of exported photos; see “Customizing the Export and
Publishing Manager dialogs” on page 55.

Defining an export service 39

CHAPTER 3: Creating Export and Publish Services

Item

Description

canExportToTemporaryLocation

A Boolean value that indicates whether the service provider can
place files in a temporary export destination in the local file
system.
When true, an additional item, “Temporary folder (will be
discarded upon completion)” is added to the Export To pop-up
menu at the top of the Export dialog. Default is false. (This is tied
to LR_export_destinationType; see “Lightroom built-in
property keys” on page 61.)
If the user selects this option, the file naming options in the dialog
disappear and the files are written to a hidden temporary folder
on the local hard drive. When the Export Service Provider has
completed its work, this folder and its contents are deleted.
If your plug-in hides the Export Location section of the dialog, you
do not need to use this option. The temporary folder behavior
happens automatically in that case.
Optional in Lightroom SDK 2.0 and later. Ignored in earlier
versions.

showSections
hideSections

A callback function that returns a table of built-in sections to
include or exclude from those displayed in the Export dialog.
See “Restricting existing service functionality” on page 58 for
details.

allowFileFormats
disallowFileFormats

A table of file formats to include or exclude from those offered in
the Export dialog.
See “Restricting existing service functionality” on page 58 for
details.

allowColorSpaces
disallowColorSpaces

A table of color spaces to include or exclude from those offered in
the Export dialog.
See “Restricting existing service functionality” on page 58 for
details.

sectionsForTopOfDialog
sectionsForBottomOfDialog

Definitions for one or more new sections to display in the Export
dialog; see “Adding custom sections to the Export or Publishing
Manager dialog” on page 56 for details.

hidePrintResolution

When true, the options for sizing in the Image Sizing section are
shown only in pixel units; all mention of print units such as inches,
centimeters, and pixels-per-inch are hidden.

additional publish service options

If this is a publish service, there are a number of other options that
you can specify; see “Publish service options” on page 42.

Defining an export service 40

CHAPTER 3: Creating Export and Publish Services

Initialization and termination functions for services
You can provide functions to be called when a post-process action or export destination defined by your
plug-in is selected or deselected in the Export or Publishing Manager dialog. To do so, the service
definition script for your Export Filter Provider or Export Service Provider should return these table entries,
which contain the function definitions:
startDialog = function( propertyTable ) ... end,
endDialog = function( propertyTable, why ) ... end,
•

The startDialog function is called when the user chooses a post-process action or export destination
provided by this plug-in in the Export dialog, or when the destination is already selected when the
dialog is invoked, remembered from the previous export operation.

•

The endDialog function is called when the user deselects the action or export destination in the
Export dialog, or dismisses the Export dialog.

NOTE: Similar entries can be supplied by a Plug-in Info Provider, although the definitions are slightly
different. Functions defined in a Plug-in Info Provider are executed only when the plug-in is selected in the
Plug-in Manager dialog, never from the Export dialog. See “Initialization and termination functions for the
Plug-in Manager” on page 34.
The propertyTable parameter for both functions is a table which contains the most recent settings for your
export plug-in, including both settings that you have defined and Lightroom-defined export settings (see
“Remembering user choices” on page 59). When your plug-in is being used as a publish service provider,
the property table contains additional values that tell you about the publishing status; see “Publish Service
properties” on page 70.
When your plug-in is deactivated, Lightroom calls your endDialog function with why set to one of the
following string values:
changedServiceProvider

A different Export Service Provider was chosen as the export or publish
destination. Your plug-in is no longer active.

ok

The user clicked the “Export” or “Save” button. The Export or Publishing
Manager dialog has closed.

cancel

•

For an export service, Lightroom begins exporting images through
your plug-in. Do not attempt to start uploading photos at this point;
use the processRenderedPhotos callback function to do that. See
“Customizing the Export and Publishing Manager dialogs” on page 55.

•

For a publish service, Lightroom creates a new publish service in the
Publish Services panel that can be used later to publish images
through your plug-in.

The user clicked the “Cancel” button and the Export or Publishing Manager
dialog has closed without initiating the operation.

These are blocking calls. If you need to start a long-running task (such as network access), create a task
using the LrTasks namespace. See “Defining function contexts and tasks” on page 20.

CHAPTER 3: Creating Export and Publish Services

Defining a publish service

41

Defining a publish service
Starting with version 3.0, Lightroom allows you to send photos to a local or network destination for
publication. The publication process is similar to the export process, and the Publishing Manager dialog is
largely similar to the Export dialog.

A publish service differs from an export service in these ways:
•

The publish service keeps information about what has been published previously, which allows you to
export only new or changed images to the same destination.

CHAPTER 3: Creating Export and Publish Services

Defining a publish service

42

•

A publish service keeps track of the locations to which items have been published, and can access
those locations.

•

A publish service can manage collections or folders on the remote export destination from within the
Lightroom catalog.

•

A publish service can retrieve comment and rating information that has been added to an image after
publication.

Within each publish service, the user can create one or more collections, just like those in the Library
module’s Collections panel. These are referred to as published collections. The user adds photos to
published collections (or has them added automatically if it is a published smart collection). When the user
chooses to publish (by choosing Publish Now from the published collection’s context menu, for example),
Lightroom brings the collection up to date, synchronizing the local photos with the remote copies.
Updating the collection may involve one or more of the following operations:
•

Export new photos to the collection.

•

Re-export existing photos to the collection (updating the rendering or metadata if they have changed
since the previous publish).

•

Delete photos from the collection.

•

Update the sorting sequence for the collection (if applicable).

•

Download comments and ratings (if applicable) from the remote service.

Publish service options
To define the functionality of your publish service, write a Lua script that returns a table; each predefined
entry in the table describes a specific type of customization. You then declare the name of your service and
associate it with the defining script, in the same way you declare any plug-in.
To declare a Publish service, add the following block to your Info.lua file:
LrExportServiceProvider = {
title = "Service Name", -- this string appears in the Publish Services panel
file = "MyPublishServiceProvider.lua", -- the service definition script
},

Notice that this differs from an Export service in that you do not provide a presets folder location. A plug-in
cannot control the settings in the Publishing Manager dialog using presets, although it can provide
default values for its own settings, and modify its own settings on dialog startup using the startDialog
callback.
With the exception of export presets, a publish service is a superset of an export service. The publish
service definition script can create any of the elements that an export service does, with only minor
differences. In addition, your publish service should define additional elements that control the
publication data and processes.
The API defines a number of additional items that allow you to customize the publishing experience for
the end user, and to reflect changes in the collection structure made by your plug-in. These are the
additional items that can be in the table returned by the service definition script for a Publish Service

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

43

Provider; for details of how to define these items and what they do, see the API Reference documentation
and the Flickr plug-in.

Adding an export post-process action
An Export Filter Provider is a script that allows you to modify a photo after Lightroom performs the initial
rendering, but before it is passed to it final export destination, by defining a post-process action. A
post-process action can modify the rendered images, or can suppress the export of certain photos, based
on any criteria that you define. The script is identified by the LrExportFilterProvider entry in the
plug-in’s Info.lua file.
A single SDK export plug-in can define one or more Export Filter Providers, one or more Export Service
Providers, or both. In any given export session, there must be exactly one Export Service Provider, but
there can be any number of post-process actions (or none). A single Export Filter Provider can define
multiple actions. Post-process actions are executed in a specific sequence, partly determined by user
choices. If you set up a dependency using the requiresFilter option, the sequence of execution honors
that dependency.
While Export Service Providers can add multiple sections at either the top or the bottom of the Export
dialog, each post-process action can provide only one section for the dialog, which is always inserted after
Lightroom's built-in sections, and before any "bottom" sections defined by the Export Service Provider.
Export Filter Providers cannot define presets of their own, but can be included in an Export Service preset;
see “Creating an export or publish service” on page 37.
A post-process action is inserted between Lightroom's initial rendering of photos and the writing of the
rendered image files to their destination (either the default destination, or one provided by a plug-in’s
export service). A post-process action (or set of actions) can be applied to photos that are being exported
to any destination; that is, an Export Filter Provider does not need to be part of the same plug-in that
provides the export service.
For details, see “How post-process actions are executed” on page 50

Inserting and removing actions
When any plug-in defining a post-process action is loaded, the action appears in the Post-Process Actions
section of the Export dialog, on the left below the Presets section. When you open the plug-in, the
individual actions defined by the plug-in appear as choices below it. When you select an action, the Insert
button is enabled, allowing you to insert the action into the processing queue. (You can also insert an
action by double-clicking it.)

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

An action that has been inserted is flagged with a check mark; when it is selected, the Remove button is
enabled, allowing you to remove it from the processing queue.

When an action is inserted, the related section is shown in the Export dialog. You can also remove the
action from the queue by clicking the X icon in the related section.

44

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

45

Action dependencies
You can set up a dependency among a set of actions, such that one action actually performs the photo
processing, and other actions in the set are used to determine the parameters for that operation. The one
that performs the rendition is typically the only one that defines a filterRenderedPhotos() function.
This main action is required by the others in the set. To declare the dependency, make the ID of the main
action the value of the requiresFilter option for the dependent actions.
Each post-process action can define a single section for the Export dialog. When the user selects an action,
that action’s dialog section is shown, along with that of the required filter, if there is one.
For example, suppose your plug-in has defined:
1. MyAction, the main action that performs the filtering operation
2. Color, which allows the user to choose a color to be used by MyAction
3. Lines, which allows a user to choose line widths to be used by MyAction
4. An Export Service Provider that performs an FTP upload
When the user chooses the FTP-upload export destination and clicks Export, the service provider requests
an export rendition for each photo that is active at the time. If the user does not choose any actions, the
request is satisfied directly by Lightroom using LrExportRendition.
If the user inserts Color, the dialog shows both the section for defining a border, and the section for
MyAction, which is required by Color. After making all the necessary choices for the chosen actions, the

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

46

user clicks Export. In this case, the request is intercepted and redirected to Color. Color receives a list of
renditions that it is expected to satisfy; the action then makes its own rendition request. This request is
similarly intercepted and sent to MyAction. MyAction performs the actual processing and makes its own
request for renditions. When there are no more actions, the requests are satisfied directly by Lightroom
using LrExportRendition.
Each action runs in its own task in Lightroom (see “Defining function contexts and tasks” on page 20),
which means that the operations performed by each action can be performed in parallel. An action task
first requests its renditions, then iterates through them making its transformations as appropriate. When
the action is done rendering each photo, it signals the downstream task which can then process the
rendered photo. For a more detailed description of the processing path, see “How post-process actions are
executed” on page 50.

Declaring export post-process actions
In the Info.lua file for a plug-in that defines an export post-process action, you must set LrSdkVersion
= 2.0 (or higher) in order for your filters to be recognized. If you set LrSdkMinimumVersion = 1.3, the
plug-in can be loaded in Lightroom 1.3, but the post-process actions are ignored.

To declare one or more post-process actions, add the following block to your Info.lua file:
LrExportFilterProvider = {
title = "Filter Name", -- this display string appears in the dialog
file = "MyExportFilterProvider.lua", -- the action definition script
id = "myFilter", -- a unique identifier for the action
requiresFilter = "mainFilter", -- optional
supportsVideo = "true" -- optional
},

There can be one or many action definitions. Each definition is a table with up to four items:
•

title (string): The localizable display name of the action, which appears in the Post-Process Actions

section of the Export dialog.

•

file (string): The name of the Lua file (action definition script) that provides more information about

the action. The script is executed when the export operation is started; that is, when the user clicks
Export in the Export dialog.

•

id (string): An identifying string for this action, unique within this plug-in. Required if more than one

action is defined in one plug-in.
•

requiresFilter (string): Optional, the identifier for the action that performs the processing.

•

supportsVideo (Boolean): Optional. If true, this filter has access to video files. Default is false; if not
supplied, video files are not processed by this filter. Supported in version 4.0 or higher.

For example, this defines three distinct actions, and the first is the one that actually performs the
processing. It must be present before either of the other two can run; they simply set parameters to be
used by the main action:
LrExportFilterProvider = {
{
title = "MyAction",
file = "myAction.lua",
id = "main",
},
{

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

title = "Color",
file = "colorAction.lua",
id = "color",
requiresFilter = "main",
},
{
title = "Lines",
file = "lineAction.lua",
id = "lines",
requiresFilter = "main",
},
},

Defining a post-process action
An action definition script must return a table which can contain these entries. All entries are optional.
postProcessRenderedPhotos

A function that defines how this action processes the list of rendered
photos that it receives. See “Defining post-processing of rendered
photos” on page 48.
Typically, only the main action in a group defines this function.

shouldRenderPhoto

A function that selects photos to be removed from the list of rendered
photos that it receives. See “Removing photos from the export
operation” on page 48.

startDialog
endDialog

Initialization and termination functions that run when the action is
selected or deselected in the Export dialog. See “Initialization and
termination functions for services” on page 40.

exportPresetFields

A set of export preset settings that you define for your plug-in (in
addition to the built-in settings defined by Lightroom). If provided,
these fields are transferred from the Export dialog’s property table to
any export preset that is created when this post-process action is
selected for the current Export session. See “Remembering user
choices” on page 59.

47

CHAPTER 3: Creating Export and Publish Services

sectionForFilterInDialog

Adding an export post-process action

48

A function that defines a new section in the Export dialog which
appears when the action is selected, allowing the user to make choices
that affect the operation. Any action in a group can define a dialog
section.
The function must conform to this prototype:
sectionForFilterInDialog = function( viewFactory,
propertyTable ) ... end,

This function is defined in the same way as sectionsForTopOfDialog
and sectionsForBottomOfDialog, except that the function returns a
single section definition, not an array of section definitions; see
“Adding custom sections to the Export or Publishing Manager dialog”
on page 56. The section is always added at the bottom of the Export
dialog, but above any “bottom” sections defined for the active Export
Service Provider.
The property table passed to this function is shared among all Export
Filter Providers and Export Service Providers defined by this plug-in.

Removing photos from the export operation
If you wish to remove photos from the list of those to be exported, based on criteria of your choosing, your
action definition script can define a function named shouldRenderPhoto(). This function receives two
parameters, the export settings and the current photo, and is called successively on each entry in the list of
rendered photos passed to the action.
shouldRenderPhoto = function ( exportSettings, photo )...end,

The function should return true if the photo should remain in the list and be passed to the next action or
exported, or false if it should be removed from the list.
For a publish operation, if a post-process action returns false for a potentially publishable photo, that
photo is not published, but remains in the “New Photos to Publish” state.
This example is for a simple filter that removes photos that do not have a minimum star rating:
function RatingExportFilterProvider.shouldRenderPhoto( exportSettings, photo )
local minRating = exportSettings.min_rating or 1
local shouldRender
local rating = photo:getRawMetadata( 'rating' )
shouldRender = rating and rating >= minRating
return shouldRender
end

Defining post-processing of rendered photos
To specify exactly how each photo should be modified after it is rendered and passed to the action, the
action-definition script for your main action defines a function named postProcessRenderedPhotos().
postProcessRenderedPhotos = function( functionContext, filterContext ) ... end,

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

49

This function takes two parameters, a function context and a filter context. It can retrieve each photo from
the filterContext.renditionsToSatisfy property, and process it as desired. The list of renditions
provides access to the export settings with which the photos were originally rendered, and can check or
modify those settings and rerender the photos as needed.
The processing is typically performed by an external application. You can build a command string and pass
it to a platform-specific shell for execution, using LrTasks.execute().
This processing function typically looks something like this:
function SimpleExternalToolFilterProvider.postProcessRenderedPhotos( functionContext,
filterContext )
-- Optional: If you want to change the render settings for each photo
-- before Lightroom renders it, write something like the following.
-- If not, omit the renditionOptions definition, and also omit
-- renditionOptions from the call to filterContext:rendition()
local renditionOptions = {
filterSettings = function( renditionToSatisfy, exportSettings )
exportSettings.LR_format = 'TIFF'
return os.tmpname()
-- ... if you wanted Lightroom to generate TIFF files
-- and override the configured filename when providing
-- input images to this post-process action.
-- By doing so, you assume responsibility for creating
-- the file type that was originally requested and placing it
-- in the location that was originally requested in your
-- filter loop below.
end,
}
for sourceRendition, renditionToSatisfy in filterContext:renditions(
renditionOptions ) do
-- Wait for the upstream task to finish its work on this photo.
local success, pathOrMessage = sourceRendition:waitForRender()
if success then
-- Now that the photo is completed and available to this filter,
-- you can do your work on the photo here.
-- It would look somethinglike this:
local status = LrTasks.execute( 'mytool "' .. pathOrMessage .. '"' )
-- (This tool is hypothetical.)
-- You may need to use escapes in the file name so that
-- special characters are not interpreted by the OS shell
-- (cmd.exe in Windows or bash in Mac OS).
-- In Windows, enclose the whole command in double quotes.
-- If your tool cannot process the photo as intended, use
-- something like this to signal a failure for this rendition only:
if status ~= (desired status) then
renditionToSatisfy:renditionIsDone( false, "error message" )
end
-- (Replace "error message" with a user-readable string explaining why
-- the photo failed to render.)
----end

It is neither necessary nor harmful to call renditionIsDone if the
rendition has completed successfully.
The iterator for filterContext:renditions calls it
automatically if you have not already done so.

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

50

end
end

How post-process actions are executed
During an export operation, rendition requests and state information are passed up a chain of processors
from the Export Service Provider to the Lightroom built-in render engine, and rendered photos are passed
back down again. The sequence is followed for each photo in the list of photos to be exported. This section
explains the sequence of calls, and what information is passed at each point.
This Export Dialog shows three Export Filter Providers, whose actions have all been inserted in the
processing queue. The Export Service Provider for FTP Upload (one of the sample plug-ins included in the
SDK) has been selected.

The post-process actions are always invoked in the order in which they appear in the dialog, but the export
operation traverses the stack several times, either top-to-bottom (blue arrows), or bottom-to-top (red
arrows). In this discussion, the terms upstream and downstream refer to the downward flow; for example,
when photos that have been rendered by the built-in render engine (using information passed up from
the providers) are passed back down to be modified, and finally exported:

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

51

•

An upstream provider means the post-process action immediately above the current one in the dialog,
which provides a rendered photo to the current action for further processing. When there are no more
actions, the final upstream provider is Lightroom’s built-in rendering engine.

•

A downstream consumer means the post-process action immediately below the current one in the
dialog, which receives a rendered photo from the current one, its upstream provider. When there are
no more actions, the final downstream consumer is the Export Service Provider that sends the
rendered photo to the final destination.

When the user starts the export operation by clicking Export, Lightroom constructs an LrExportSession
object with the settings and photos chosen in the dialog.
It then calls exportSession:doExportOnCurrentTask(), which performs the following operations. (If
you wish to start an export without using the export dialog, you can make the same calls yourself.)
In this discussion, an Export Service Provider is called a service, and an Export Filter Provider is called a filter.

Stage 1: Deciding how the photos should be rendered
If the service has defined an updateExportSettings() function, it is called. This function takes one
argument, the export-settings table, and allows the service to force certain render settings to its preferred
or required settings. For example, to force a specific size for the exported photos, you could use this
definition:
updateExportSettings = function( exportSettings )
exportSettings.LR_size_maxHeight = 400
exportSettings.LR_size_maxWidth = 400
end

The filters, if any, are not involved at this stage.

Stage 2: Deciding what photos should be rendered
The filters are invoked from top-to-bottom. For each filter:
•

If it is defined, the shouldRenderPhoto() function is called for each photo. If it returns false, the photo
is removed from the list of photos to export (and thus does not get passed to the downstream
consumer). If it returns true, the photo remains in the list and is passed to the downstream consumer.

•

If shouldRenderPhoto() is not defined for the filter, all photos are passed to the downstream
consumer.

Stage 3: Requesting renditions
1. The export session (LrExportSession) generates rendition request objects (LrExportRendition) for
every photo that was not removed in Stage 2. (The actual rendering of the photos does not start yet.)
During this stage, Lightroom can show a dialog message if a photo already exists at the proposed
destination location. You can control this behavior using the LR_collisionHandling setting in the
export settings table.
2. The service's processRenderedPhotos() function is called. If no such function exists, a default one is
provided that performs the steps described below.

CHAPTER 3: Creating Export and Publish Services

Adding an export post-process action

52

IMPORTANT: Each of the providers (the export service, filters, and Lightroom's built-in rendering engine)
runs in its own task (using LrTasks), so these loops operate in parallel. It is likely that each provider will be
running simultaneously. Several photos can be in process simultaneously by different providers. This
allows the overall export operation to complete much more quickly than it would if every photo had to go
through all of the steps before the processing of the next photo could begin.
3. The processRenderedPhotos() function calls exportContext:renditions() and then waits for
each rendition to be completed by calling rendition:waitForRender(). (We will discuss the
completion of this loop in Stage 4.)
4. The service's rendition requests are sent to its upstream provider (that is, the bottom-most filter, or if
there are no filters, Lightroom's built-in render engine).
5. For each filter, if a postProcessRenderedPhotos() function is defined, it is called. The function is
called only once, regardless of the number of photos being exported.
This function should enter into a loop of the form:
for sourceRendition, renditionToSatisfy in filterContext:renditions() do ... end
•

The filter context object generates a new rendition request (LrExportRendition) for each of the
renditions provided this filter.

•

The renditions() iterator provides two values: sourceRendition (the new rendition to be
satisfied by the upstream provider) and renditionToSatisfy (the corresponding rendition that
this filter is expected to satisfy for its downstream consumer).

ADVANCED: If the filter provider wishes to request a different file format than it is expected to satisfy, it can
do so using the renditionOptions/filterSettings code snippet shown in “Defining post-processing
of rendered photos” on page 48. This might be a good idea as a way to avoid re-encoding (and thus
degrading) JPEG files. If you do this, you are still responsible for providing an output file in the exact format
and location required by renditionToSatisfy.
•

The filter must wait for each rendition to be completed by its upstream provider by calling
sourceRendition:waitForRender(). (We will discuss the completion of this loop in Stage 4.)

If there is no processRenderedPhotos() function defined by this filter, the filter is simply left out of
the loop and all rendition requests instead go to the upstream provider.
IMPORTANT: Each filter must generate a photo conforming exactly to the specifications provided to it. In
particular, it must provide a suitable photo file in the specified format and at the exact path specified by
the downstream consumer. If it cannot do so, it must use renditionToSatisfy:renditionIsDone(
false, message ) to indicate why not. It must never provide a file of a different format than that
requested.
6. After all of the filters have had an opportunity to intercept the rendition requests, the requests are
finally passed to Lightroom's built-in rendering engine.

Stage 4: Processing rendered photos
As Lightroom completes each rendition request, it signals completion by allowing the corresponding
rendition:waitForRender() call to complete.
The rendering loops described in stage 3 then finish in top-to-bottom sequence for each photo. For each
filter that defines the postProcessRenderedPhotos() function:

CHAPTER 3: Creating Export and Publish Services

Final processing of rendered photos

53

1. The waitForRender() call completes, meaning that the upstream provider has completed its attempt
to render the photo. If that attempt was successful, a valid photo file conforming to the specifications
requested by this filter is present at the path specified by the sourceRendition; that is, specified by
this filter when it requested the rendition from its upstream provider.
2. The filter can now do whatever processing it needs to do on that file. This typically means invoking a
third-party application using LrTasks.execute().
ADVANCED: If the filter has changed the file format or location on disk using renditionOptions, it must
now perform the appropriate operations on the file to convert it so that it now satisfies the request as
specified in renditionToSatisfy.
3. When the processing operation is finished, the filter must report its status on the rendition by calling
renditionToSatisfy:renditionIsDone( success, message ).
This is done automatically by the filterContext:renditions() iterator if you have not already
done so explicitly. The iterator verifies that a file exists at the expected path and signals success or
failure accordingly. If the file is missing, it uses a generic "an unknown error occurred" message. If you
want to provide a more meaningful message, make an explicit call to renditionIsDone( false,
message ). Typically, you need only call renditionIsDone() on failure.
4. The call to renditionToSatisfy:renditionIsDone() allows the downstream consumer's
waitForRender() call to complete.
5. Meanwhile, the task for this filter continues on and waits for the next rendition.
6. Once all of the filters have finished processing a photo, the waitForRender() call in the service’s
processRenderedPhotos loop completes. The service does whatever processing it needs to (in this
example, uploading with FTP), and then waits for the next photo to be available.
7. If the "Add to this Catalog" checkbox was selected, Lightroom adds the new photo to the catalog at
this point.

Stage 5: Error reporting and clean up
Once the service’s processRenderedPhotos loop completes, Lightroom takes the following clean-up
actions:
•

If the photo files were rendered into a temporary folder, Lightroom deletes the folder and its contents.

•

If the export was triggered through the Export dialog:
•

Plays the export completion sound, if any.

•

If any photos failed to export, shows an error dialog that summarizes all of the errors encountered
while exporting.

•

Creates a temporary "Previous Export" collection with the source photos that were exported.

These behaviors are not available when an export is initiated by calling LrExportSession directly.

Final processing of rendered photos
The processRenderedPhotos() service entry allows you to control what happens to each exported
photo after it is rendered by Lightroom and after all post-process actions have been applied to it. This is

CHAPTER 3: Creating Export and Publish Services

Final processing of rendered photos

54

the function that is responsible for transferring the image file to its destination, as defined by your plug-in.
The function that you define is launched within a cooperative task that Lightroom provides. You do not
need to start your own task to run this function; and in general, you should not need to start another task
from within your processing function. (See “Defining function contexts and tasks” on page 20.)
processRenderedPhotos = function( functionContext, exportContext )
...
end,

The parameters functionContext and exportContext are instances of LrFunctionContext and
LrExportContext respectively, which Lightroom creates and passes to your function.
•

Use the function-context object to define cleanup handlers for this call.

•

Use the export-context object to gain access to the setting chosen by the user (in
exportContext.propertyTable), and the list of photos to be exported.

•

Use the export-context object to configure the progress indicator to update as photos are displayed.
This would look like this example adapted from the Flickr plug-in:
local progressScope = exportContext:configureProgress {
title = nPhotos > 1 and
LOC( "$$$/Flickr/Publish/Progress=Publishing ^1 photos to Flickr", nPhotos )
or LOC "$$$/Flickr/Publish/Progress/One=Publishing one photo to Flickr",
}

The function that you define typically contains a loop of this form:
for i, rendition in exportContext:renditions() do
-- Wait until Lightroom has finished rendering this photo.
local success, pathOrMessage = rendition:waitForRender()
-- Do something with the rendered photo.
if success then
-- when success is true, pathOrMessage contains path of rendered file
local uploadStatus, uploadMessage = uploadToSomewhere( pathOrMessage )
if not uploadStatus then
rendition:uploadFailed( uploadMessage )
end
else
-- Report waitForRender failure
rendition:uploadFailed( pathOrMessage )
end
end
end
•

Lightroom renders the photos in a separate background thread, so it is likely that your upload
processing will overlap subsequent rendering operations to some extent.

•

The function exportContext:renditions() automatically updates the progress indicator in the
upper-left corner of the Lightroom catalog window, using a text message that you set by calling
exportContext:configureProgress().

CHAPTER 3: Creating Export and Publish Services

Customizing the Export and Publishing Manager dialogs

55

Customizing the Export and Publishing Manager dialogs
Customizing the export destination
After Lightroom has completed the rendering of an individual photo for export, and also completed any
post-processing of that rendered photo by any selected actions, it completes the export operation by
sending the resulting image file to the export-service code, which handles the actual export to the
user-selected destination. By default, Lightroom provides export services for a user-selected location in
the local file system, or the CD/DVD drive.
The drop-down menu at the top of the Export dialog, labeled “Export To,” gives you a choice of
destinations:

Your plug-in can provide an export service that allows the user to choose a different destination, such a
remote site, and define how the image files are sent to that destination; by FTP upload, for example.
A plug-in that includes an Export Service Provider gives the user a further choice of destinations for the
export operation. For example, a plug-in can add a web service such as Flickr as the destination, so that the
export operation uploads the selected files to Flickr, using the settings that the user selects in the rest of
the dialog. When the plug-in is loaded, the user can select the new destination using the up or down arrow
at the right.
If you provide a new export destination, you typically also need to add settings that are meaningful for
your customized export operation. Your plug-in can define customizations for other parts of the Export
dialog, which are shown when the user selects your Export destination.
•

If your upload operation requires more complex user choices, you can add new sections to the Export
dialog, with the UI elements that the user will need to make those choices. See “Adding custom
sections to the Export or Publishing Manager dialog” on page 56.

•

The User Presets list at the left can include presets that you define and include with your plug-in, as
well as those defined by Lightroom for export operations; see “Remembering user choices” on
page 59.

CHAPTER 3: Creating Export and Publish Services

Customizing the Export and Publishing Manager dialogs

56

Adding custom sections to the Export or Publishing Manager dialog
Your plug-in can define one or more sections to be displayed in the Export or Publishing Manager dialog.
The custom sections can be shown above or below the Lightroom standard sections for the dialog.
To customize the dialog, define a function that returns a table of sections, defined using LrView objects.
The function is the value of one of these service entries:
sectionsForTopOfDialog = function( viewFactory, propertyTable ) ... end,
sectionsForBottomOfDialog = function( viewFactory, propertyTable ) ... end,

NOTE: Similar functions can be defined in a Plug-in Info Provider, to customize the Plug-in Manager
dialog, and in an Export Filter Provider, to add a section to the Export dialog when a post-process
action is selected. See “Adding custom sections to the Plug-in Manager” on page 34 and “Adding an
export post-process action” on page 43.
Lightroom passes your function a factory object which allows you to create the LrView objects that define
the elements of your sections; that is, UI controls, such as buttons and text, and containers that group the
controls and determine the layout. For additional details of the dialog elements you can create with
LrView, see Chapter 5, “Creating a User Interface for Your Plug-in.”
The function that you define here returns a table of tables, where each table defines one dialog section:
sectionsForTopOfDialog = function( viewFactory, propertyTable )
return {
{ ...section entry ... },
{ ...section entry ... },
...
}
}
end

A section entry table defines the contents of an implicit container, which Lightroom creates to hold your
view hierarchy.
•

Each section entry sets a title and synopsis for the section; the section is identified by the title
text on the left, and is collapsible. When in the collapsed state, the synopsis text is shown on the
right:

•

The rest of the table entry creates the UI elements that are shown when the section is expanded. To
create the UI elements, use the LrView factory passed to your top-level sectionsFor... function.
This process is explained in more detail in Chapter 5, “Creating a User Interface for Your Plug-in.”

When adding sections to the Export dialog, the propertyTable parameter for both functions is the property
table containing the plug-in and Lightroom-defined export settings. When your plug-in is being used as a
publish service provider, the property table contains additional values that tell you about the publishing
status; see “Publish Service properties” on page 70.
You can add your own program data values to this table (see “Remembering user choices” on page 59),
and create bindings between the UI elements and the data values, so that the UI text is dynamically tied to
your plug-in data. This is shown in the example below, and explained more fully in “Binding UI values to
data values” on page 97.

CHAPTER 3: Creating Export and Publish Services

Customizing the Export and Publishing Manager dialogs

57

A custom section example
This sample code creates a section in the destination dialog with two UI controls, an editable text field and
a button. These are in a container, a row element which controls the placement of its child nodes, but is not
drawn on the screen.
The value of the edit field is tied to a data key in the property table. The enabled state of the button is also
tied to a data key, so that the button is only enabled when the user types into the edit field, thus setting
the data value.
In this example, the synopsis text is also dynamic, bound to the same data key as the edit field value.
(Currently, you cannot bind the title value.) Notice that for synopsis, you must specify the bound table
explicitly. This is because it is not part of the view hierarchy, where the propertyTable is automatically
assigned as the default bound table.
All of these concepts and techniques are explained more fully and described in more detail in Chapter 5,
“Creating a User Interface for Your Plug-in."
sectionsForTopOfDialog = function( viewFactory, propertyTable )
local LrDialogs = import "LrDialogs" -- get the namespaces we need
local LrView = import "LrView"
local bind = LrView.bind -- a local shortcut for the binding function
propertyTable.user_text = "" -- add program data, no initial value
propertyTable.buttonEnabled = false -- button starts out disabled
return { -- create section entries
{ -- first section entry
title = "Section title",
-- bind the synopsis to a variable for a dynamic description
-- of this section that appears when it is collapsed
synopsis = bind { key = 'user_text', object = propertyTable },
-- create the view hierarchy that appears in the open section
viewFactory:row { -- create root container node
spacing = viewFactory:control_spacing(), -- default spacing
viewFactory:edit_field { -- create edit field
value = bind 'user_text', -- bound to property
immediate = true, -- update value w/every keystroke
validate = function( view, value )
if #value > 0 then -- check length of entered text
-- any input, enable button
propertyTable.buttonEnabled = true
else
-- no input, disable button
propertyTable.buttonEnabled = false
end
return true, value
end
},

CHAPTER 3: Creating Export and Publish Services

Customizing the Export and Publishing Manager dialogs

58

viewFactory:push_button { -- create button
enabled = bind 'buttonEnabled',-- enable when property is set
title = "My Button", -- text in button
action = function( button )
LrDialogs.message( "You typed: ", propertyTable.user_text)
end
}
}
}
}
end

This code creates this custom section at the top of the Export dialog (when defined by an
LrExportServiceProvider entry):

Restricting existing service functionality
Your service can restrict the built-in services offered by the Export and Publishing Manager dialogs, by
hiding some of the built-in sections that are normally displayed, or by limiting the options offered by the
dialog.
A single toggle entry controls whether users can select measurement units:
hidePrintResolution = Boolean

When true, the options for sizing in the Image Sizing section
are shown only in pixel units; all mention of print units such as
inches, centimeters, and pixels-per-inch are hidden. Default is
false.

The rest of the service table entries that restrict existing functionality in the dialog come in positive and
negative forms; that is, you can list the features to be included, or you can list the features to be excluded.
For each such pair, you can provide only one of the entries, not both. If you provide neither, all default
elements in that category appear.
For example, you can choose which of the built-in sections to display in the dialog. If you use the positive
form, you list the sections to be shown:
showSections = { 'fileNaming', 'imageSettings' },

This causes the File Naming and Image Sizing sections to be visible, and hides all of the other built-in
sections. If you use negative form, you list the sections to be hidden. For example, this hides the Export
Location section, and shows all other built-in sections:
hideSections = { 'exportLocation' },

CHAPTER 3: Creating Export and Publish Services

Remembering user choices

59

These are the service-table entry pairs for each type of restriction:
Restriction

Service table entries

Allowed values

File formats

allowFileFormats = { ’format’[, ...] },
disallowFileFormats = { ’format’[, ...] },

These still-photo file formats
are recognized:
JPEG
PSD
TIFF
DNG
ORIGINAL

Video file formats are
determined elsewhere.
Color spaces

allowColorSpaces = { ’colorspace’[, ...] },
disallowColorSpaces = { ’colorspace’[, ...] },

These color spaces are
recognized:
sRGB
AdobeRGB
ProPhotoRGB

Section display showSections = {’section’[, ...] },

hideSections = { ’section’[, ...] },

These built-in sections are
defined:
exportLocation
fileNaming
fileSettings
imageSettings
outputSharpening
metadata
video
watermarking

•

When you hide a section, all of the preset values set in that section are excluded
from any presets that the user creates when your plug-in is activated.

•

If you hide the exportLocation section (the topmost section in the default
dialog), Lightroom renders the photos into a temporary location, then deletes that
directory and its contents after your processRenderedPhotos function
terminates.

NOTE: In the Lightroom 1.3 SDK, there was an additional option, postProcessing,
which was removed in Lightroom 2.0. This section is now only available with the
built-in “Export to Files on Disk” service. If specified, it is ignored by Lightroom 2.0 or
newer.

Remembering user choices
You typically define properties for your own export or publish operation, whose key names, values, and
usage are entirely defined by your plug-in.
Some of these are simply transient or local data (see “Creating observable property tables” on page 100),
but some are intended to be export settings. Export settings (both plug-in-defined and Lightroom-defined)
are persistent properties whose values are saved from one invocation of the Export or Publishing Manager

CHAPTER 3: Creating Export and Publish Services

Remembering user choices

60

dialog to the next, and across Lightroom sessions. The most recent settings values are passed to your
initialization function when the plug-in is invoked, to various service-script functions (such as
startDialog, sectionsForTopOfDialog, and so on), and to your plug-in’s termination function.
To declare persistent properties and their default values, the service definition script for an export service,
publish service, or post-process action can return this item:
exportPresetFields

A table of keys and associated default values. These are automatically
stored in both Lightroom preferences and Export presets.
The default values are used only on the first invocation of your plug-in;
after that, the previously set values are restored.
Although export presets are not available for publish-service plug-ins, this
description is used to describe which values from the publish service are
remembered from one invocation to the next of the Publish Manager
dialog.

For example:
exportPresetFields = {
{ key = 'privacy',
{ key = 'privacy_family',
{ key = 'privacy_friends',
{ key = 'safety',
{ key = 'hideFromPublic',
{ key = 'type',
{ key = 'addTags',
}

default
default
default
default
default
default
default

=
=
=
=
=
=
=

'public'
false
false
'safe'
false
'photo'
''

},
},
},
},
},
},
},

The settings you declare here are automatically saved along with the export settings already defined by
Lightroom (see “Lightroom built-in property keys” on page 61). The first time your plug-in is activated, the
default value is used to initialize your settings. On the second and subsequent activations, the settings
chosen by the user in previous sessions are restored.

Export presets
For an export service, the user can choose to save a particular configuration of settings values as an export
preset. A preset contains all of the current settings values, including Lightroom-defined fields,
plug-in-defined fields, and post-process action-defined fields. It does not contain any publish-specific
setting that are shown only in the Publishing Manager dialog.
If you wish to create a predefined preset for your export-service plug-in, to be loaded along with your
plug-in and appear in the Lightroom Presets list, you must:
1. Make the value selections in the Export dialog.
2. Use Add to save a User Preset.

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

61

3. Right-click (control-click in Mac OS) on the newly-created Preset to find the preset file. Move the preset
file from that folder to the subfolder that you specified using the builtInPresetsDir entry for the
LrExportServiceProvider entry in the Info.lua file for your plug-in.

Settings for publish services and post-process actions
Although you can define persistent setting for a publish service using the exportPresetFields item, and
those values are saved as part of any publish service the user creates in the Publishing Manager dialog, you
cannot associate a preset with a publish service. The settings for the Publishing Dialog cannot be loaded
from a preset, they can only be set directly by the plug-in (using defaults or a startDialog callback) or
interactively in the UI.
Similarly, post-process actions cannot have their own presets, but user choices can be remembered if you
add an exportPresetFields entry to the action’s info.lua file; see “Defining a post-process action” on
page 47. If the user has chosen to activate the post-process action for a particular export operation, user
choices for that action are captured in any preset created for that export service.

Lightroom built-in property keys
Your export operation makes use of the settings that you have defined for your plug-in (see
“Remembering user choices” on page 59), and can also check any of the Lightroom-defined properties, as

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

62

set in the Export dialog. These are all in the property table passed to your initialization function (see
“Initialization and termination functions for services” on page 40).
The Lightroom built-in keys apply to specific sections of the Export dialog and Library module window, as
follows:

Export Location section properties
LR_export_destinationType

String. The value of the "Export To:" pop-up. One of:
chooseLater
desktop
documents
home
pictures
sourceFolder
specificFolder
tempFolder

LR_export_destinationPathPrefix String. Destination folder.
LR_export_useSubfolder

Boolean. True when the "Put in Subfolder" option is checked,
false when it is unchecked.
Cannot be used if destination type is tempFolder.

LR_export_destinationPathSuffix String. Subfolder name. Valid only if use-subfolder is true.
LR_reimportExportedPhoto

Boolean. True when the "Add to This Catalog" option is checked,
false when it is unchecked.
Cannot be used if destination type is tempFolder.

LR_reimport_stackWithOriginal

Boolean. True when the "Stack With Original " option is checked,
false when it is unchecked.
This is only meaningful if destination type is sourceFolder and
use-subfolder is false. Ignored otherwise.

LR_collisionHandling

String. The value of the "Existing Files:" pop-up. One of:
ask
rename
overwrite
skip

File Naming section properties
LR_extensionCase

String. The case to use for the file extension. One of:
One of
uppercase
lowercase

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

LR_initialSequenceNumber

Number. The initial value for the sequence number, when files
are renamed on export using a sequence number.

LR_renamingTokensOn

Boolean. When true, the files are renamed on export as
described below.

LR_tokenCustomString

String. A naming template to use when files are renamed on
export.

LR_tokens

String. A file-naming pattern. The string is used as the file name,
but can contain a pattern within double curly braces which is
replaced by information about the photo being exported. For
example, the string {{image_name}} is replaced by the file
name. See allowed token patterns below.

63

Token patterns
This is the complete list of patterns that are allowed in the LR_tokens string, as presented in the pop-up
menu in the File Naming Template dialog:
Image Name and Custom patterns
Pattern

Replaced by

{{image_name}}

File name

{{image_filename_number_suffix}}

File number suffix

{{image_folder}}

Folder name

{{image_originalName}}

Original file name

{{image_originalName_number_suffix}}

Original number suffix

{{copy_name}}

Copy name

{{custom_token}}

Custom Text (the value of LR_tokenCustomString)

Sequence and Date patterns
Pattern

Replaced by

{{naming_sequenceNumber_1Digit}}

Sequence # (1)

{{naming_sequenceNumber_2Digits}}

Sequence # (01)

{{naming_sequenceNumber_3Digits}}

Sequence # (001)

{{naming_sequenceNumber_4Digits}}

Sequence # (0001)

{{naming_sequenceNumber_5Digits}}

Sequence # (00001)

{{naming_operationSequence_1Digit}}

Image # (1)

{{naming_operationSequence_2Digits}}

Image # (01)

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

{{naming_operationSequence_3Digits}}

Image # (001)

{{naming_operationSequence_4Digits}}

Image # (0001)

{{naming_operationSequence_5Digits}}

Image # (00001)

{{naming_sequenceTotal_1Digit}}

Total # (1)

{{naming_sequenceTotal_2Digits}}

Total # (01)

{{naming_sequenceTotal_3Digits}}

Total # (001)

{{naming_sequenceTotal_4Digits}}

Total # (0001)

{{naming_sequenceTotal_5Digits}}

Total # (00001)

{{date_LocalEncoding}}

Date (Month DD, YYYY)

{{date_YYYYMMDD}}

Date (YYYYMMDD)

{{date_YYMMDD}}

Date (YYMMDD)

{{date_YYYY}}

Date (YYYY)

{{date_YY}}

Date (YY)

{{date_Month}}

Date (Month)

{{date_Mon}}

Date (Mon)

{{date_MM}}

Date (MM)

{{date_DD}}

Date (DD)

{{date_Julian}}

Julian Day of the Year

{{date_Hour}}

Hour

{{date_Minute}}

Minute

{{date_Second}}

Second

Metadata patterns
Pattern

Replaced by

{{com.adobe.title}}

Title

{{com.adobe.caption}}

Caption

{{com.adobe.copyright}}

Copyright

{{com.adobe.keywords}}

Keywords

{{com.adobe.creator}}

Creator

{{com.adobe.creatorJobTitle}}

Creator Job Title

{{com.adobe.creatorAddress}}

Creator Address

{{com.adobe.creatorCity}}

Creator City

64

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

Pattern

Replaced by

{{com.adobe.creatorState}}

Creator State / Province

{{com.adobe.creatorZip}}

Creator Postal Code

{{com.adobe.creatorCountry}}

Creator Country

{{com.adobe.creatorWorkPhone}}

Creator Phone

{{com.adobe.creatorWorkEmail}}

Creator E-Mail

{{com.adobe.creatorWorkWebsite}}

Creator Website

{{com.adobe.descriptionWriter}}

Description Writer

{{com.adobe.iptcSubjectCode}}

IPTC Subject Code

{{com.adobe.intellectualGenre}}

Intellectual Genre

{{com.adobe.scene}}

Scene

{{com.adobe.location}}

Location

{{com.adobe.isoCountryCode}}

ISO Country Code

{{com.adobe.headline}}

Headline

{{com.adobe.city}}

City

{{com.adobe.state}}

State / Province

{{com.adobe.country}}

Country

{{com.adobe.jobIdentifier}}

Job Identifier

{{com.adobe.instructions}}

Instructions

{{com.adobe.provider}}

Provider

{{com.adobe.source}}

Source

{{com.adobe.rightsUsageTerms}}

Rights Usage Terms

{{com.adobe.copyrightInfoURL}}

Copyright Info URL

{{com.adobe.imageFileDimensions}}

Dimensions

{{com.adobe.imageCroppedDimensions}}

Cropped

{{com.adobe.exposure}}

Exposure

{{com.adobe.focalLength}}

Focal Length

{{com.adobe.focalLength35mm}}

Focal Length 35mm

{{com.adobe.brightnessValue}}

Brightness Value

{{com.adobe.exposureBiasValue}}

Exposure Bias

{{com.adobe.subjectDistance}}

Subject Distance

{{com.adobe.ISOSpeedRating}}

ISO Speed Rating

65

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

Pattern

Replaced by

{{com.adobe.flash}}

Flash

{{com.adobe.exposureProgram}}

Exposure Program

{{com.adobe.meteringMode}}

Metering Mode

{{com.adobe.make}}

Make

{{com.adobe.model}}

Model

{{com.adobe.serialNumber}}

Serial Number

{{com.adobe.artist}}

Artist

{{com.adobe.software}}

Software

{{com.adobe.lens}}

Lens

{{com.adobe.GPS}}

GPS

{{com.adobe.GPSAltitude}}

Altitude

{{com.adobe.rating.string}}

Rating

{{com.adobe.colorLabels.string}}

Label

File Settings section properties
LR_format

String. File format for still photos. One of:
JPEG
PSD
TIFF
DNG
ORIGINAL

LR_export_colorSpace

String. Color space. One of
sRGB
AdobeRGB
ProPhotoRGB

LR_export_bitDepth

Number. Bit depth for TIFF or PSD. Ignored for other formats.
One of:
8
16

The following apply only if LR_format = JPEG
LR_jpeg_quality

Number. JPEG quality [0..1]. A percentage value where 1 is the
best quality.

66

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

LR_jpeg_useLimitSize

Boolean. True when the “Limit File Size To:” option is checked,
false when it is unchecked.

67

When true, Lightroom chooses the quality setting that best
matches the desired file size.
LR_jpeg_limitSize

Number. When file size is limited, the target size in kilobytes.

The following apply only if LR_format = TIFF
LRtiff_compressionMethod

String. TIFF compression method. One of:
compressionMethod_None
compressionMethod_LZW
compressionMethod_ZIP

The following apply only if LR_format = DNG
LR_DNG_previewSize

String. JPEG preview size. One of:
none
medium
large

LR_DNG_compatability

Number. The oldest version of Adobe Camera Raw/Photoshop
that can read these files. One of:
33816576 (Camera Raw 2.4 and later)
67174400 (Camera Raw 4.1 and later)
67502080 (Camera Raw 4.6 and later)
84148224 (Camera Raw 5.4 and later)

LR_DNG_conversionMethod

String. Image conversion method. One of:
preserveRAW
convertToLinear

LR_DNG_embedRAW

Boolean. True to embed original raw file.

Image Sizing section properties
LR_size_doConstrain

Boolean. True to constrain maximum size.

LR_size_doNotEnlarge

Boolean. True to prevent enlargement of the image size.

LR_size_maxHeight

Number. Height constraint in units specified by
LR_size_units.

LR_size_maxWidth

Number. Width constraint in units specified by LR_size_units.

LR_size_megapixels

Number. When resize type is megapixels, the number of
megapixels.

CHAPTER 3: Creating Export and Publish Services

LR_size_resizeType

Lightroom built-in property keys

String. The resize method. One of:
wh (width and height)
dimensions
longEdge
shortEdge
megapixels

For the long-edge and short-edge methods, the value is
constrained by LR_size_maxHeight.
LR_size_resolution

Number. Resolution, in units specified by
LR_size_resolutionUnits.

LR_size_resolutionUnits

String. Resolution units. One of:
inch
cm

LR_size_units

String. Size constraint units. One of
inch
cm
pixels

Output Sharpening section properties
LR_outputSharpeningOn

Boolean. True when the "Sharpen For" option is checked, false
when it is unchecked.

LR_outputSharpeningMedia

String. The destination media for the sharpening operation.
One of:
screen
matte
glossy

LR_outputSharpeningLevel

Number. The amount of sharpening. One of 1 (low), 2 (medium),
or 3 (high).

Metadata section properties
LR_minimizeEmbeddedMetadata

Boolean. True when the "Minimize Embedded Metadata"
option is checked, false when it is unchecked. This property is
superseded by LR_embeddedMetadataOption.

LR_metadata_keywordOptions

String. Corresponds to the state of the “Keywords as Lightroom
Hierarchy” checkbox. Value can be lightroomHierarchical
(checked) or flat (unchecked). Ignored when
LR_minimizeEmbeddedMetadata is true.

68

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

LR_removeLocationMetadata

Boolean. True when "Remove Location Info" box is checked,
false when it is unchecked. When true, Lightroom strips all GPS
location metadata from the photo on export.

LR_embeddedMetadataOption

String. Corresponds to the state of the “Include” popup menu.
Value can be copyrightOnly, copyrightAndContactOnly,
allExceptCameraInfo, or all.

Video section properties
LR_includeVideoFiles

Boolean. True when the "Include Video Files" option is checked,
false when it is unchecked.
When true, export any video files that are selected. When false,
omit those files and show an error message when the export
operation is completed.
Considered only when the plug-in sets canExportVideo =
true in its service description script, to indicate that it can
process video. Otherwise, this is ignored and the
corresponding checkbox is not shown.

NOTE: To dynamically set the format and preset to use for video export, use the method

LrExportSettings.applyVideoExportPreset(). See the API Reference for details.

Watermarking section properties
LR_useWatermark

Boolean. True to enable watermarking on export.

LR_watermarking_id

When watermarking is enabled, the unique identifier of the
watermark to use. Lightroom assigns this ID when the user
creates a new watermarking preset. You cannot modify it, or
create a watermarking preset programmatically.

Post-Processing Filter section properties
LR_exportFiltersFromThisPlugin

Table with a key that is the ID of each enabled filter, and a
corresponding value that is the index of that filter in the overall
filter stack. For example:
LR_exportFiltersFromThisPlugin.myFirstFilter.1
LR_exportFiltersFromThisPlugin.mySecondFilter.2

If your plug-in contains multiple filters, this tells you which ones
were selected by the user.

69

CHAPTER 3: Creating Export and Publish Services

Lightroom built-in property keys

70

General export properties
This property allows your plug-in to disable the Export button in the Export dialog, or the Save button in
the Publishing Manager dialog.
LR_cantExportBecause

String, optional. If present, describes why an export cannot be initiated.
Appears in the bottom of the dialog near the disabled (dimmed) Export
or Save button. When the error condition is fixed, your plug-in should
set this value to nil. In response to that change, Lightroom enables the
Export or Save button (if no other error conditions exist).
Ignored in versions earlier than 2.0.

Publish Service properties
These properties are part of the settings table passed to the following callbacks, when they are defined as
part of a publish service provider:
startDialog
endDialog
sectionsForTopOfDialog
sectionsForBottomOfDialog
LR_publish_connectionName

String. The descriptive name of a connection, as
assigned by the user in the Publishing Manager dialog.

LR_isExportForPublish

Boolean, read-only. True when the current export
operation is part of a publish service, either currently
running or being edited in the Publishing Manager.

LR_editingExistingPublishConnection

Boolean. True when the user is editing an existing
publish service.

LR_publishService

LrPublishService. When editing an existing publish

service, the service object.

4

Working with Metadata
•

A plug-in can define customized metadata fields for photos by declaring a Metadata Provider in the
information file, and defining type and version information for each field. See “Adding custom
metadata” on page 71.

•

A plug-in can specify metadata tagsets that affect the display of custom metadata fields in the Library
module’s Metadata panel. See “Adding custom metadata tagsets” on page 76.

•

Plug-ins can define complex searches that find photos according to metadata values. See “Searching
for photos by metadata values” on page 78.

Adding custom metadata
Your plug-in can define custom metadata fields for photos that are imported into Lightroom. These fields
can be visible and even editable in Lightroom's Metadata panel, or can be invisible and used to store
private data.

Declaring a Metadata Provider
Like an Export Service or Export Filter Provider, you declare a Metadata Provider in the information file
(Info.lua) for your plug-in. See “Writing standard plug-ins for Lightroom” on page 23.
To declare a Metadata Provider, include an LrMetadataProvider entry in the Info.lua file; for example:
return {
LrSdkVersion = 5.0,
LrToolkitIdentifier = 'com.adobe.lightroom.metadata.sample',
LrPluginName = LOC "$$$/CustomMetadata/PluginName=Metadata Sample",
LrMetadataProvider = 'SampleMetadataDefinition.lua',
}

The information file that declares a Metadata Provider can also declare metadata tagsets (see “Adding
custom metadata tagsets” on page 76), export services and/or filters, but need not do so.
Limitations of custom metadata in this release
In the current implementation, custom metadata defined by a plug-in has these limitations, which will be
addressed in future versions of the Lightroom SDK:
•

Values stored in custom metadata fields are stored only in Lightroom's database. In the current
release, a plug-in cannot link custom metadata fields to XMP values or save them with the image file.

•

A plug-in cannot specify complex data types. You can define simple fields per photo, but you cannot
define a whole spreadsheet per photo.

71

CHAPTER 4: Working with Metadata

Adding custom metadata

Defining metadata fields
The script for your Metadata Provider defines specific metadata fields. The metadata definition script
returns a table that describes the fields to be added to Lightroom's metadata schema. It contains the
following fields:
metadataFieldsForPhotos

table

Required. Defines new data fields to be stored for
each photo.
The table is an array of field definitions. Each entry
in the metadataFieldsForPhotos array describes a
single field which can be associated with photos in
the catalog. Each field can hold only one value per
photo.
See “Metadata field entries” on page 73.

schemaVersion

number

Required. Allows for versioning of the property
definition schema. Typically this number starts at 1
and you increment it whenever you release a new
version of the schema or need to run the update
function.

updateFromEarlierSchemaVersion

function

Optional. Allows your plug-in to update data when
a new schema version is in place.
The function takes three parameters; catalog,
previousSchemaVersion, and progressScope.
When the plug-in is first installed,

previousSchemaVersion is nil.

See example below.
noAutoUpdate

Boolean

Optional. When false (the default), Lightroom
attempts to automatically update metadata from
old field definitions to new. If you prefer to handle
this in your own plug-in (using the
updateFromEarlierSchemaVersion callback), set
this to true.

72

CHAPTER 4: Working with Metadata

Adding custom metadata

Metadata field entries
Each of the entries in the metadataFieldsForPhotos array is a table that describes one metadata field;
each metadata field describes a photo in the catalog. Each field can have only one value per photo. The
following entries are recognized within each table:
id

string

Required. A unique identifier that allows a plug-in to access this field. The
name must conform to the same naming conventions as Lua variables; that is,
it must start with a letter, followed by letters or numbers, case is significant.

version

number

Optional. If present, defines a version number specifically for this field, distinct
from the version number defined by schemaVersion in the outer metadata
definition script.
If you make a change to a field definition that is incompatible with the
previous definition (for example, changing the value of searchable), you
must bump the field's version number. A migration script can search for
photos that contain the old version of the field and manually migrate values.

title

string

Optional. If this field is displayed in the Metadata panel, this is the localizable
display name. This name should be relatively short, since space in the
Metadata panel is at a premium. A name longer than about 100 pixels is likely
to be truncated on display; however, the full text is shown in the tooltip when
the cursor hovers over the name.
If this item is omitted, the field does not appear in the Metadata panel. This
can be useful for storing private, per-image plug-in information, such as the
image’s ID at an on-line service that is the export destination, or other
cross-reference information.

dataType

string

Optional. If this field is present, Lightroom disallows any other data type from
being stored in this field. Nil is always permitted. You cannot require that a
field have a value.
The value is one of these strings:
string — The field value must have a string value.
enum — The field value must have one of the allowed values specified in
the values entry. In the Metadata panel, allowed values are shown as a

pop-up menu for the field.
url — The field value must have a string value. In the Metadata panel, the
text field is acccompanied by a button that treats the text value as a URL,
opening it in the user’s preferred web browser.

73

CHAPTER 4: Working with Metadata

Adding custom metadata

table

values

Required when dataType = "enum", otherwise disallowed. An array of allowed
values. Each entry in the array is a table that must contain a value and a title.
The title is shown in the popup menu; the corresponding value (which must
be a string, number, or Boolean, or nil) is written to the database. The values
table can have only one entry where value = nil. If such an entry is present,
the corresponding label is used when no value has been assigned to this
property for a photo.
The values table can also have an entry allowPluginToSetOtherValues =
true.
•

If present, your plug-in can store values outside of the enumerated values
in this field.

•

If not, an attempt to set such a value triggers a Lua error and does not
change the value stored in the database.

readOnly

Boolean Optional. Use only when title is provided. When true, the field is visible in the
Metadata panel, but not editable by the user. The value can still be set
programmatically, using LrPhoto:setPropertyForPlugin().

searchable

Boolean Optional. Use only when title is provided. When true, this field is stored in a
separate table and indexed for faster searching; this also means that the field
can be chosen by a user as a search criterion for smart collections. Strings
stored in this field must not exceed 511 bytes. Default is false.

browsable

Boolean Optional. Use only when title is provided and searchable is true. When
true, this field can be used as a filter in the Library metadata browser.

Custom metadata example
This sample Metadata Provider script defines three metadata fields of representative types.
return {
metadataFieldsForPhotos = {
{
id
----

= 'siteId',
This field is not available in the metadata browser because
it does not have a title field. You might use a field like this
to store a photo ID from an external database or web service.

},
{
id = 'randomString',
title = LOC "$$$/Sample/Fields/RandomString=Random String",
dataType = 'string', -- Specifies the data type for this field.
},
{
id = 'modelRelease',
title = LOC "$$$/Sample/Fields/ModelRelease=Model Release",
dataType = 'enum',
values = {
{
value = nil,

74

CHAPTER 4: Working with Metadata

Adding custom metadata

75

title = LOC "$$$/Sample/Fields/ModelRelease/NotSure=Not Sure",
},
{
value = 'yes',
title = LOC "$$$/Sample/Fields/ModelRelease/Yes=Yes",
},
{
value = 'no',
title = LOC "$$$/Sample/Fields/ModelRelease/No=No",
},
-- optional: allowPluginToSetOtherValues = true,
},
},
},
schemaVersion = 1,
-- must be a number, preferably a positive integer
updateFromEarlierSchemaVersion = function( catalog, previousSchemaVersion,
progressScope )
-- When the plug-in is first installed, previousSchemaVersion is nil.
-----

As of Lightroom version 3.0, a progress-scope variable is available; you can
use it to signal progress for your upgrader function.
Note: This function is called from within a catalog:withPrivateWriteAccessDo
block. You should not call any of the with___Do functions yourself.

catalog:assertHasPrivateWriteAccess(
"SampleMetadataDefinition.updateFromEarlierSchemaVersion" )
local myPluginId = 'com.adobe.lightroom.metadata.sample'
if previousSchemaVersion == 1 then
local photosToMigrate = catalog:findPhotosWithProperty( myPluginId,'siteId')
-- optional: can add property version number here
for i, photo in ipairs( photosToMigrate ) do
local oldSiteId = photo:getPropertyForPlugin( myPluginId, 'siteId' )
-- add property version here if used above
local newSiteId = "new:" .. oldSiteId
-- replace this with whatever data transformation you need to do
photo:setPropertyForPlugin( _PLUGIN, 'siteId', newSiteId )
end
elseif previousSchemaVersion == 2 then
-- and so on...
end
end,
}

This is how these fields appear in the Metadata panel, when the user has chosen a metadata tagset that
contains them, or one of the default metadata tagsets “All” or “All Plug-in Metadata” (see “Adding custom
metadata tagsets” on page 76). The user-visible custom fields from plug-ins are shown after all of the
built-in metadata fields.

CHAPTER 4: Working with Metadata

Adding custom metadata tagsets

76

•

Notice that the field "siteId" does not appear in the panel because no title is defined for it; it is an
invisible field, internal to the plug-in.

•

The field "randomString" appears with the localized title value, "Random String", as the display label.
Because it is a plain string value, it appears as an editable text field.

•

The field "modelRelease" also appears with the title value, "Model Release", as the display label.
Because it is an enumerated value, clicking it pops up a menu of the allowed values, each shown using
its own localized title value as the display string.

Adding custom metadata tagsets
The drop-down menu at the top left of the Metadata panel allows users to filter what is shown in the
panel, by selecting a metadata tagset to be displayed. A metadata tagset is a predefined set of metadata
fields. When you select a tagset, the Metadata panel displays only the fields included in that set.

There are predefined tagsets, and you can also create your own. Your plug-in can define a named
metadata tagset, which can include fields defined by your plug-in, by other plug-ins, or by Lightroom.
This is the Info.lua file for a minimal plug-in that defines a tagset:
return {
LrSdkVersion = 5.0,
LrToolkitIdentifier = 'com.adobe.lightroom.metadata.sample',
LrPluginName = LOC "$$$/CustomMetadata/PluginName=Metadata Sample",
LrMetadataTagsetFactory = 'SampleTagset.lua',
}

CHAPTER 4: Working with Metadata

Adding custom metadata tagsets

77

The metadata-tagset provider can appear in the same plug-in with export-service and export-filter
providers, and with simple Metadata Providers.
The metadata-tagset provider is a Lua file that returns a tagset definition. You can use the
LrMetadataTagsetFactory entry to specify more than one such file in a single plug-in. For example:
LrMetadataTagsetFactory = { 'Tagset1.lua', 'Tagset2.lua', 'Tagset3.lua' },

Defining a metadata tagset
Each tagset definition file must return a table listing the fields that should appear in the Metadata panel
when that tagset is selected. The file can return an array of such tables to define multiple tagsets.
The table contains these entries:
id

string

Required. An identifier for this tagset that is unique within this plug-in. The
name must conform to the same naming conventions as Lua variables; that is,
it must start with a letter, followed by letters or numbers. Case is significant.

title

string

Required. The localizable display name of the tagset, which appears in the
popup menu for the Metadata panel.

items

table

Required. An array of metadata fields that appear in this tagset, in order of
appearance.

Each entry in the items array identifies a field to be included in the Metadata menu. It can be a simple
string specifying the field name, or an array that specifies the field name and additional information about
that field:
fieldname

string

The first element in the array is the unique identifying name of the field,
or one of the special values described below.

label

string

Optional. When the field name is the special value 'com.adobe.label',
this is the localizable string to use as the section label.

Certain special values are defined for field names. See the API Reference documentation for metadata
plug-in-defined functions, and the metadata sample plug-in.
•

You can include all visible metadata from a plug-in by specifying the field name with the wild-card
character "*"; for example, "com.mycompany.uploader.*". The visible fields are included in the
sequence in which they are defined in the definition script. The fields for each plug-in are preceded by
a dividing line and the plug-in’s name.
If you refer to a plug-in that is missing or that defines no visible metadata, it is not an error; the block
and separator for that plug-in are simply not displayed.

•

You can include all visible metadata from a plug-in by specifying the special field name
"com.adobe.allPluginMetadata". This is the field name used by the built-in "All Plug-in Metadata"
preset.

•

The special name 'com.adobe.separator' inserts a dividing line in the Metadata panel before the first
field from this plug-in.

CHAPTER 4: Working with Metadata
•

Searching for photos by metadata values

78

The special name 'com.adobe.label' inserts a section label in the Metadata panel, specified by a
label entry in an array with this name. A label is typically used below a separator.

Custom metadata tagset example
This sample metadata-tagset provider script defines a set of metadata fields.
return {
title = LOC "$$$/SampleTagset/Title=Sample Tagset from Plug-in",
id = 'sampleTagset',
items = {
'com.adobe.filename',
'com.adobe.copyname',
'com.adobe.folder',
'com.adobe.separator',
'com.adobe.title',
{ 'com.adobe.caption', height_in_lines = 3 },
'com.adobe.separator',
{ 'com.adobe.label', label = LOC "$$$/Metadata/SampleLabel=Section Label" },
'com.adobe.dateCreated',
'com.adobe.location',
'com.adobe.city',
'com.adobe.state',
'com.adobe.country',
'com.adobe.isoCountryCode',
'com.adobe.GPS',
'com.adobe.GPSAltitude',
'com.adobe.lightroom.metadata.sample.randomString',
},
}

Searching for photos by metadata values
The LrCatalog object provides a function, findPhotos(), that allows you to search through the catalog
for photos with particular metadata values. You pass this function a search descriptor to define the search,
which is a table containing a metadata field (the search criteria), a matching operation (which depends on
the datatype of the field), and a value to match against.
This function must be used within a background task. For example:
import "LrTasks".startAsyncTask( function()
local catalog = import "LrApplication".activeCatalog()
local photos = catalog:findPhotos {
searchDesc = {
criteria = "rating",
operation = ">",
value = 3,

CHAPTER 4: Working with Metadata

Searching for photos by metadata values

79

},
}
for _, photo in ipairs( photos ) do
-- do somethingwith path
end
end )

This simple usage is straightforward, although the function allows many matching operations, depending
on the datatype of the metadata field to be considered.
criteria

The allowed values for criteria correspond to choices in the Edit Smart Collection dialog:
rating

(number)

pick

(enum) Value must be one of: 1 (flagged), 0 (unflagged), -1 (rejected)

labelColor

(enum) Value must be one of: 1 (red), 2 (yellow), 3 (green), 4 (blue), 5 (purple),
"custom" (any label not currently assigned to a color), "none"

labelText

(string, can be empty) User-assigned name of color label

folder

(string) Name of folder, including all parent folders shown in the Folders panel

collection

(string) Name of any collection containing this photo

all

(string) Any searchable text

filename

(string)

copyname

(string, can be empty) Copy Name assigned in Metadata panel

fileFormat

(enum) Value must be one of: "DNG", "RAW", "JPG", "TIFF", "PSD"

metadata

(string) Any searchable metadata

title

(string, can be empty)

caption

(string, can be empty)

keywords

(string, plural, can be empty)

iptc

(string) Any IPTC metadata; that is, any text in a field that is indexed by Lightroom.

exif

(string) Any EXIF metadata; that is, any text in a field that is indexed by Lightroom.

captureTime

(date)

touchTime

(date) Edit Date

camera

(string, with exact match)

cameraSN

(string, with exact match) Camera Serial Number

lens

(string, with exact match)

isoSpeedRating (number)
hasGPSData

(Boolean)

CHAPTER 4: Working with Metadata

Searching for photos by metadata values

country

(string, with exact match)

state

(string, with exact match)

city

(string, with exact match)

location

(string, with exact match)

creator

(string, with exact match)

jobIdentifier

(string, with exact match)

copyrightState (enum) Value must be one of: true (Boolean, copyrighted), false (Boolean, public

domain), "unknown"

hasAdjustments (Boolean)
developPreset

(enum) Value must be one of: "default", "specified", "custom"

treatment

(enum) Value must be one of: "grayscale", "color"

cropped

(Boolean)

aspectRatio

(enum) Value must be one of: "portrait", "landscape", "square"

You can search plug-in defined fields, using these special criteria values:

operation

"allPluginMetadata"

Any searchable plug-in-defined metadata.

sdktext:plugin_id.field_name

A specific, searchable, plug-in-defined field (with datatype text
or enum).

sdktext:plugin_id.*

All searchable fields defined by a specific plug-in (with datatype
text or enum).

The allowed values for operation depend on value type of the criteria field, and also correspond to
selectable values the Edit Smart Collections dialog.
•

For string values, one of:
any

"contains"

all

"contains all"

words

"contains words"

noneOf

"does not contain"

beginsWith

"starts with"

endsWith

"ends with"

empty

"are empty", only valid for items that can be empty,

notEmpty

"are not empty", only valid for items that can be empty,

80

CHAPTER 4: Working with Metadata

Searching for photos by metadata values

==

"is", only valid for items that can have an exact match,

!=

"is not", only valid for items that can have an exact match

•

For Boolean values, one of "isTrue", "isFalse"

•

For enumerated values, one of == (is), != (is not)

•

For number and rating values, one of:
==

"is"

!=

"is not"

>

is greater than"

<

"is less than"

>=

"is greater than or equal to"

<=

"is less than or equal to"

in

"is in range"
End value of range specified in value2 parameter.

•

For date values, one of:
==

"is"

!=

"is not"

>

"is after"

<

"is before"

inLast
notInLast

"is in the last"
"is not in the last"
With unit specified in value_unit parameter, one of:
hours
days
weeks
months
years

in

"is in the range"
End value of range specified in value2 parameter.

today

"is today"

yesterday

"is yesterday"

thisWeek

"is in this week"

81

CHAPTER 4: Working with Metadata

value

Searching for photos by metadata values

thisMonth

"is in this month"

thisYear

"is in this year"

82

The value to match against must be of the type indicated for the criteria. Additional parameters value2
and value_unit are used with specific types and operations, as mentioned above.

Combining search criteria
You can create a more complex search descriptor by using a combine entry to specify how to combine the
results of several criterion tables:
import "LrTasks".startAsyncTask( function()
local catalog = import "LrApplication".activeCatalog()
local photos = catalog:findPhotos {
searchDesc = {
combine = "intersect",
{
criteria = "rating",
operation = ">",
value = 3,
},
{
criteria = "captureDate",
operation = ">",
value = "2007-01-01",
}
},
}

for _, photo in ipairs( photos ) do
-- do something with path
end
end )

There are three ways to combine criteria:
combine = "union"

Any of the criteria match.

combine = "intersect"

All of the criteria match.

combine = "exclude"

None of the criteria match.

A combine entry is followed by an array of elements to be combined. This array can contain nested
combine entries, so the search can become quite complex. For example:
{
combine = "union",
{
combine = "intersect",
{
criteria = "rating",

CHAPTER 4: Working with Metadata

Searching for photos by metadata values

83

operation = ">=",
value = 1,
},
{
criteria = "labelColor",
operation = "==",
value = 1,
},
},
{
criteria = "rating",
operation = "==",
value = 5,
},
}

This renders the following statement of Boolean logic:
photos where ( rating >= 1 AND labelColor == 1 ) OR ( rating == 5 )

Creating searches interactively
If you are unsure how to construct a particular search, you can make Lightroom build it for you. To do this:
1. Construct the search as a Smart Collection in Lightroom:

2. Right click the resulting collection in the Collections panel and choose “Export Smart Collection
Settings.”

3. Open the resulting .lrsmcol file in a text editor.
4. Select and copy the value entry:

CHAPTER 4: Working with Metadata

Searching for photos by metadata values

84

5. Edit the resulting code to change value to searchDesc, and include it in your call to findPhotos().
6. Make any other appropriate changes in the code. In this example, for instance, you would not need
the combine element. If you remove it, you can also promote the parameter table to the top level in
searchDesc:
searchDesc = {
criteria = "captureTime",
operation = ">",
value = "2008-02-12",
}

5

Creating a User Interface for Your Plug-in
You can define a user interface to your plug-in with these tools:
•

Your plug-in can define one or more custom sections to be displayed in the Plug-in Manager dialog or
Export dialog, above and/or below the Lightroom standard sections. The custom sections are
displayed when the user chooses your export destination. You define the UI elements of a custom
section using LrView objects; see “Adding custom dialog views” on page 85.

•

You can call the functions of the LrDialog namespace to display messages, prompts, and errors to
users in predefined dialogs. See “Displaying predefined dialog boxes” on page 86.

•

You can use the functions in the LrDialog and LrView namespaces to create your own dialog boxes.
You can display them when users choose your custom menu items, invoke them from tasks, or invoke
them in response to selections in controls you have added to the Export dialog. See “Creating custom
dialog boxes” on page 87.

The LrView class models a node tree, where each node is a UI element, represented by a specific type of
LrView object. A node can be a container or parent of other nodes, or a control, an individual UI element

such as a checkbox, which displays a value and can allow user input. Containers and controls are arranged
in a node tree, or view hierarchy. A view hierarchy has a top-level container node, additional child
containers if needed, and leaf nodes that are the controls.
The LrView namespace and class provides a set of interface elements, with functionality to lay out and
localize the display, and a binding mechanism that lets you tie the displayed values to your plug-in data
and settings.
•

“User interface elements” on page 87 introduces the UI elements you can create with LrView.

•

“Binding UI values to data values” on page 97 explains the binding mechanism, with examples of how
to create various relationships between your data and your display.

•

““Determining layout” on page 110 explains the placement options and gives examples of various
layout techniques.

Adding custom dialog views
You can create custom sections to be displayed in the Plug-in Manager or Export dialog using these
service-script entries:
sectionsForTopOfDialog = function( viewFactory, propertyTable ) ... end,
sectionsForBottomOfDialog = function( viewFactory, propertyTable ) ... end,
•

The function that you define here is slightly different for the two dialogs; see “Adding custom sections
to the Plug-in Manager” on page 34 and “Adding custom sections to the Export or Publishing
Manager dialog” on page 56.

•

For an Export Filter Provider, a very similar function, sectionForFilterInDialog, creates only one
section, rather than multiple sections. See “Defining a post-process action” on page 47.

In any case, however, the function must define the UI to be displayed when each dialog-box section is
expanded. To do so, use the viewFactory object to construct all of the elements of a view hierarchy.
85

CHAPTER 5: Creating a User Interface for Your Plug-in

Using dialog boxes

86

To create the containment hierarchy, use the view factory to create a container, and within that call, use it
to create the child containers and controls:
viewFactory:group_box {
...initial property settings...
viewFactory:row {-- a row of controls within the box
...initial property settings...
viewFactory:static_text { -- a text label, contained in the row
...initial property settings...
viewFactory:button { -- a button that responds to a click, contained in the row
...initial property settings...
...

Control nodes have properties that define a tooltip for the node, control the visibility, and affect the size,
displayed font, and enabled state. Additional properties apply to controls of specific types; for instance, a
pop-up menu has an items property, which contains a table of the selectable menu items to display. Each
item is in turn a table containing a title (displayed string) and value (the value returned when the item is
selected):
viewFactory:popup_menu {
title = "myPopup",
items = { -- the menu items
{ title = "First item", value = 1 },
{ title = "Second item", value = 2 },
},
value = LrView.bind( "myPopup_value" ), -- the control value
size = 'small'
},
•

The types of containers and controls and their view properties are listed and described in “User
interface elements” on page 87.

•

Certain properties describe node layout; that is, the sizing and placement of each node with respect to
its container and sibling nodes. You can set layout values individually, or use LrView functions to set
spacing and margin values for an entire node tree. The layout properties and functions are described
in “Determining layout” on page 110.

•

Display strings in all containers and controls (generally specified in the title property) can be
localized to different languages by using the LOC function to specify the string value; for details, see
Chapter 7, “Using ZStrings for Localization.”

Using dialog boxes
The LrDialogs namespace provides functions that you can use to display simple messages in predefined
dialog boxes, or to define a completely customized dialog box. All dialog boxes are modal, meaning that
when the dialog is invoked, no other actions can be taken in the Lightroom UI until the dialog is dismissed.

Displaying predefined dialog boxes
The predefined dialog boxes display:
•

Messages
Message dialogs display your text message to the user. They have a single OK button that dismisses
the dialog; you can specify the button text. One version has a "Don’t show again" checkbox, so that the
user can prevent this message from being displayed next time the same situation occurs.

CHAPTER 5: Creating a User Interface for Your Plug-in
•

User interface elements

87

Confirmations and prompts
In addition to your text message, these dialogs have configurable OK and Cancel buttons. These return
different values to the invocation function, which you use to decide on the action to be taken. Again,
there is a "Don’t show again" version.
These dialogs are extensible; you can define an optional third button, or a small UI section that you
define using LrView; see “Creating custom dialog boxes” on page 87.

•

Errors
You can display a simple error message with a single OK button, or you can wrap an error dialog
around a function context, so that if the wrapped function throws an error, the dialog appears. See
“Using function contexts for error handling” on page 18.

•

Platform Open File and Save File
You can bring up the platform-defined file-selection dialogs, so that the user can choose a file system
location.

Creating custom dialog boxes
You can use the LrDialogs.presentModalDialog() function to create a completely customized dialog
box, which you can, for example, invoke from a menu item that your plug-in adds to the Lightroom menu
bar, using one of the menu service items: LrExportMenuItems, LrLibraryMenuItems, or
LrHelpMenuItems.
Most of the contents of this dialog are defined by an LrView hierarchy that you define. To build the
contents of a custom dialog, obtain a factory object using the LrView namespace function
LrView.osFactory(). Like the confirmation dialogs, this dialog automatically contains configurable OK
and Cancel buttons.
You can choose to make this dialog user-resizeable, and can also choose to save its most recent frame size
as one of your plug-in settings. The location of the dialog is also saved, if the user moves it.
The example code in “Building a basic dialog” on page 113 demonstrates how to build and invoke a
custom dialog within a function context.
Floating (non-modal) dialogs can be created using the LrDialogs.presentFloatingDialog() function
in a similar manner to that described for LrDialogs.presentModalDialog() above. For specifics, see
the Lightroom SDK API Reference. Use floating dialogs when it is desirable to let the user interact with
Lightroom’s main window, as well as the dialog itself, while the dialog box is open.

User interface elements
This section provides details of the types of container and control nodes you can create with an LrView
factory object.

Containers
When creating a dialog or a section for the Plug-in Manager or Export dialog, you generally begin with a
top-level container, then, within that container, create its children. Depending on the complexity of your

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

88

interface, the children can be nested containers (such as a tabbed view that contains tabbed pages),
placement containers (rows and columns), or the visible controls (such as text and buttons).
•

All containers have the shared view properties listed in “General view properties” on page 94, except
as mentioned.

•

All containers except spacer have the layout properties listed in “Determining layout” on page 110.

Types of containers are:
Container type

Description

view

A basic containment frame for a set of
controls, with no visual representation.

group_box

A visible containment frame for a set of
controls. Can have a localizable title,
which is displayed near the top left corner
of the frame.

title and font: See “Control node

A container of tabbed pages. The
containing tab_view draws the frames for
its tab_view_item children, but has no
title. The font is used for the tab text of the
children.

font and size: See “Control node

A tabbed page in a tab_view. The
localizable title text is displayed in the
tab.

title: The display text for the tab.
identifier: A unique identifier string

tab_view

tab_view_item

Type-specific properties

view properties” on page 95
show_title: True to display the title.
Default is true.
view properties” on page 95
value: The identifier of the currentlly
selected tab.

for this page, used to select the current
tab in the parent tab view container.
Required.
Note: Previous versions of this document
incorrectly stated that the identifier
could be any type.

column
row

spacer

These group controls for layout purposes,
but do not otherwise affect the child
nodes.

This is a row that contains no child nodes.
It is used only for spacing.

These do not have any non-layout
properties, such as visible.
Otherwise, a column or row is the same
as a view with place = vertical or
horizontal.
width, height: The size in pixels.

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

89

Controls
You can use the LrView factory to create visible controls of types common to Windows and Mac OS
interface systems. If the creation function is called within the creation of a container, the control is a child
of that container.
For complete details of how to create the controls and specify their appearance and behavior, see the
Lightroom SDK API Reference. The following table summarizes the available control types and lists their
type-specific properties.
•

All controls have the shared view properties listed in “General view properties” on page 94 and
“Control node view properties” on page 95.

•

All controls have the layout properties and functions described in “Determining layout” on page 110.

Control type

Description

Type-specific properties

checkbox

Displays the title text with a
platform-style checkbox button.

title: Display label.
value: The control value.
checked_value: When the box is

A checkbox is checked (selected) when its

value is equal to its checked_value, and
unchecked (deselected) when its value is
equal to its unchecked_value. If its value

has any other value, the button shows a
mixed state.

See “Binding checkbox selections” on
page 101.

selected (checked) this becomes the
control value. Default is true.
unchecked_value: When the box is
deselected (unchecked) this becomes
the control value. Default is false.
All text properties. See “Text view
properties” on page 97.

NOTE: The comparison of property values is very specific; the values 0, false, nil, and ""
(the empty string) are all distinct.
color_well

Displays a color, and responds to a click by
displaying a predefined color-selection UI.

value: The value, an LrColor object.

combo_box

An editable text field with a pop-up menu
of predefined text values. User can enter
any text, or select from the menu. When an
item is selected from the menu, its value
becomes the control value, and is
displayed in the text field.

items: An array of entry values to

See “Binding combo box selections” on
page 104.

All edit and text properties. See
“Edit-field view properties” on page 95
and “Text view properties” on page 97.

appear in the menu, or a function that
returns such an array. The values are
not localizable in place; to localize, you
must build the array with localized
strings.

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

90

Control type

Description

edit_field

An editable text field. An edit field accepts All edit and text properties. See
keyboard input when it has the input focus. “Edit-field view properties” on page 95
and “Text view properties” on page 97.
User input is committed (that is, the value
is updated) with every keystroke if
immediate is true. If immediate is false,
input is committed when the control loses
focus. There is a platform difference in the
focus behavior:
•

In Windows, the control loses focus
when the user clicks outside it.

•

In Mac OS, it loses focus when the user
uses TAB to shift the focus, not when the
user clicks outside the control.

Type-specific properties

NOTE: When the user types ENTER/RETURN in an edit field, the default button of the
containing dialog is invoked. In the case of an Export dialog section, this is the Export
button. If you do not want that to happen, disable the default button until the user
indicates that input is done.
password_field An editable text field that obscures the

entered text, displaying only bullet
characters.

picture

A static image or icon.
TIP: you can typically get the path to the
image file using this function:
_PLUGIN:resourceId(’myPic.png’)

popup_menu

A pop-up menu of choices, each with a
title and value. When the user pops up
the menu and makes a choice, the selected
item’s title and value become those of
the control. The current title text is
displayed in the control when the menu is
not open.
See “Binding pop-up menu selections” on
page 103 for example of how to specify
items and use the value_equal function.

All edit and text properties. See
“Edit-field view properties” on page 95
and “Text view properties” on page 97.
value: The full path to the JPG or PNG
image file.
frame_width: Pixel width of a frame to
draw around the image. Default: 0.
frame_color: An LrColor object.
Default is black.
title: Display label.
value: The value of the currently

selected item.

items: A table of items to appear in

the menu. Each selectable item entry
contains a title and a value. The
title text is displayed when the
menu is open. An entry of
separator=true creates a separator,
an unselectable line in the menu.
value_equal: A function that
compares the current control value to
each item’s value in turn, to determine
the selection.
All text properties. See “Text view
properties” on page 97.

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

Control type

Description

Type-specific properties

push_button

A button that responds to a click with an
action. Drawn in platform-standard style
with a rounded appearance.

title: Display label.
action: A function defining the action

to be taken when the button is clicked,
in the form myAction( button ).
All text properties. See “Text view
properties” on page 97.

radio_button

Displays the title text with a
platform-style radio button. The button is
checked (selected) when its value is equal
to its checked_value, and unchecked
(deselected) when its value has any other
value, except nil. When the value is nil, the
button shows a mixed state.

title: Display label.
value: The control value.
checked_value: A value that indicates

the selected state.

Within a container, only one of a set of radio
buttons should be selected. Selecting one
button should deselect all others in the set.
You must enforce this in the way you bind
the button values. It is not automatic.
See “Binding radio button selections” on
page 102.
slider

A draggable “bug” that changes an
associated numeric value.

value: The current numeric value.
min: The low end of the range.
max: The high end of the range.
integral: True to change only by

integer increments. Default is false.
static_text

Text that typically does not respond to user
input, such as a label or instructions.
Although the user cannot change the text,
it can still be made dynamic by binding the
title to a data value; see “Binding UI
values to data values” on page 97.

title: Display label.
truncation: Where to truncate the
text if needed, "head", "middle", or
"tail".
selectable: True to make text

selectable (in Mac OS only).

alignment: Text alignment, "left",
"center", or "right".
text_color: An LrColor object.

Default is black.

mouse_down: A function called in

response to this event; takes one
argument, the view object that was
clicked.

All text properties. See “Text view
properties” on page 97.

91

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

Control type

Description

Type-specific properties

separator

Draws a line across its container, but has no
other behavior. The line is always 2 pixels in
width, and is drawn either vertically or
horizontally, depending on the fill value. If
both values are set, the larger value
determines the direction of the line.

fill_horizontal: The width of the
horizontal line, a percentage of the
parent's width in the range [0..1].
fill_vertical: The height of the
vertical line, a percentage of the
parent's height in the range [0..1].

The following figures show examples of the various control and container types. The appearance is
appropriate to the platform; these examples show some of each.
Containers
and
placement
controls

92

CHAPTER 5: Creating a User Interface for Your Plug-in

Buttons.
selection,
edit and
text
controls

Other
controls

User interface elements

93

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

94

View properties
Properties in container and control nodes affect the layout of the controls, and their appearance. Layout
properties, and certain view properties, are available to all nodes, both containers and controls. Other view
properties are available only in control nodes. Most types of controls have additional view properties
specific to their type; these are reflected in the creation parameters.

General view properties
Of the properties that are available in both containers and controls, many are connected with layout
behavior; these are discussed separately in “Determining layout” on page 110. The following view
properties are available in all containers and controls except the layout containers, row and column:
View property

Datatype

Description

bind_to_object

table

The default bound property table for this object and its
children. The default can be overridden at any level of the
node hierarchy, or for individual property bindings. See
“Binding UI values to data values” on page 97.

—or—
object

In views created with sectionsForTopOfDialog and
sectionsForBottomOfDialog, this is set automatically to

the property table passed along with the view factory. This
creates a binding between all nodes in the view and the
settings table, so that any node can observe any setting.
tooltip

string

A help string that appears when the cursor hovers over a
container or control.
Default nil.

visible

Boolean

Determines whether a container or control is shown or
hidden. This is not the same as being enabled or disabled;
the disabled state is only applied when a control is visible.
Default is true.
•

When true in a container, the container is visible, and
its children are visible according to their individual
visibility values.

•

When false in a container, the container and all of its
child nodes are hidden, regardless of the value in each
child node.

•

When true in a control, the control is visible if its
parent is visible. When false, it is hidden even if its
parent is visible.

Value must be true or false; do not use nil.
TIP: An item still affects layout, even when it is hidden.

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

Control node view properties
These properties are available in control nodes of all types, but not in containers.
Control node property

Datatype

Description

enabled

Boolean

When true, the control is drawn normally and is
sensitive to user input. When false, it is drawn with a
grayed appearance and does not respond to input.
Value must be true or false; do not use nil.

string or table

font

The font to be used for this control, if it contains text.
Can be:
•

A string with the name of the font.

•

One of these strings:





•

string

size

A table with the keys name and size (see size
property)

The size of text in the control (if not otherwise
determined by the font specification) and of other
visual features in non-text controls. For example,
affects the track and thumb size in a slider.
One of:

regular (the default)
small
mini

Edit-field view properties
These properties are available in control nodes that contain editable text; these include edit_field,
combo_box, and password_field.
Property

Datatype

Description

value

any

Value to be displayed.

min

number

The minimum value allowed. If specified, the field is
numeric.

max

number

The maximum value allowed. If specified, the field is
numeric.

precision

number

The number of decimal places to display. Default is 2.
If specified, the field is numeric.

95

CHAPTER 5: Creating a User Interface for Your Plug-in

User interface elements

Property

Datatype

Description

alignment

string

Alignment of text in frame, left (the default),
center, or right.

text_color

LrColor

The color of displayed text. Default is black.

immediate

Boolean

If true, the field commits its value as the user is
typing, and the validate function is called for every
change. Default is false, validation occurs on loss of
focus.

auto_completion

Boolean

True if the field should auto complete as the user
types. Default is false.

completion

table or function

A table of strings for completion, or a function that
returns a table of strings:
myCompletion( view, partialWord )

increment

number

If field is numeric, the amount to increment the
value (without SHIFT key). If the precision is 0, default
is 1; otherwise default is 0.1.

large_increment

number

If field is numeric, the amount to increment the
value when the SHIFT key is held down. If the
precision is 0, default is 10; otherwise default is 1.

validate

function

A function called to validate the value:
myValidate( view, value )

Returns result, value, message:
result: (Boolean) True if value was valid.
value: (any) The new value.
message: (string) An error message to be
displayed if result is false.
value_to_string

function

An optional conversion function, called to convert a
non-string value to a display string. Takes arguments
view (this control) and value (the entered value),
and returns a string.

string_to_value

function

An optional conversion function, called to convert
the display string to a non-string value. Takes
arguments view (this control) and string (the
string), and returns a value of the required type.

wraps

Boolean

True to wrap text. Default is true.

96

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values

97

Text view properties
These properties apply to any control that displays text, including popup_menu, static_text, and
push_button, as well as the editable text controls.
Property

Datatype

Description

width_in_chars

number

Calculates the minimum width using this as the
number of m characters that should fit. Considered
together with width_in_digits. Default is 15 for
editable text fields.

width_in_digits

number

Calculates the minimum width using this as the
number of 0 digits that should fit. Considered
together with width_in_chars. Default is 0.

height_in_lines

number

Calculates the minimum height using this as the
number of lines that should fit within the field.
Default is 1.

Binding UI values to data values
Bindings allow you to make your UI dynamic by specifying a relationship between an LrView object’s state
and current values in an observable table (see “Creating observable property tables” on page 100). This can
be the export-settings property table provided by the API, or a table that you create for local program data
that you define.
When you create a binding, the value or state of the UI element reflects the data value, and the data value
reflects the UI element state. This is a two-way relationship; when the binding is established, the data value
from the table is pushed to the view, and when the user changes the bound value in the view (by selecting
a checkbox, for instance, or entering a value in a text field), the table is notified and the corresponding
data key value or values change accordingly. Similarly, when your program changes a value in the table,
the bound UI elements are updated to display the new value.
To create bindings:
1. Specify a bound table at some level of the view hierarchy. Set the table as the value of the
bind_to_object property (you can also use the name object for this property). The bound table of a
parent container is inherited by its children, but can be overridden.
•

When you create a dialog box, you must set the bound table explicitly.

•

When you create a section for the Plug-in Manager or Export dialog using the
sectionsForTopOfDialog or sectionsForBottomOfDialog functions, the settings table for
your plug-in is passed to those functions as the propertyTable value. This table contains both
export settings that you have defined for your plug-in (see “Remembering user choices” on
page 59) and Lightroom-defined export settings (see “Lightroom built-in property keys” on
page 61).
The propertyTable is automatically set as the default bound table for all of the UI elements in the
view hierarchy for that section. However, the bindable synopsis for the section is not part of the
view hierarchy; if you want to make that value dynamic, you must specify the table explicitly. See
“Adding custom sections to the Plug-in Manager” on page 34.

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values

98

2. For each specific UI element, set the value of each dynamic property using the LrView.bind()
function to associate that value with a specific key in the bound table.
•

The simplest binding simply mirrors the key value and the property value; for instance, setting one
value to true sets the other value to true.

•

You can use the LrBindings functions to create other common mappings between the bound
key value and the view property value. See “Specifying bindings” on page 98.

•

For more complex mappings, see “Transforming values” on page 106 and “Binding multiple keys”
on page 108.

A typical example is a binding between the visible property and a particular settings value, so that a
control is only shown when the appropriate setting is present. For example, in the File Settings section of
the Export dialog, the control that appears next to the Format combo box changes according to the
selected format.

When JPEG is selected, there is a slider for setting the Quality. When you select the TIFF format, the slider is
hidden and a Compression pop-up menu is shown. For PSD and DNG, both of these controls (and their
labels) are hidden.
To accomplish this, Lightroom binds the Format pop-up menu’s value property to the LR_format setting.
Then the visible property of the slider and its label are bound to the JPEG value of LR_format. The
example code in “Changing the contents of a view dynamically” on page 115 shows how to use bindings
in this way, setting the visibility state of different sets of controls, based on the selection in a pop-up menu.
Notice in this example that two control values are related by being bound to the same key value; this is
how you bind control values to one another.
NOTE: Bindings are used to create dynamic text in LrView objects only. The title of a dialog box, for
example, is not part of an LrView object, and you cannot bind it. Similarly, the title of an Export dialog
section cannot be bound.

Specifying bindings
The LrView namespace function LrView.bind() creates a direct association between a key or keys in an
observable table and a view property value. Use this function when creating the view or control, to specify
the view property value. For example:
visible = LrView.bind( "LR_export_useSubfolder" )

Many of the sample plug-ins create a shortcut to the function:
local bind = LrView.bind -- shortcut for bind() method

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values

99

You can then use the shortcut to specify dynamic property values:
...
viewFactory:static_text {
title = bind 'mySetting',
...

The required argument of LrView.bind() is the key name; by default, this is in the table that is already
bound to the UI element; that is, the value of bind_to_object in the same UI element. This is inherited in
the view hierarchy, but can be overridden at any level.
You can override the bound table for a specific binding by passing the LrView.bind() function a table
containing both the key and the table it comes from:
visible = LrView.bind { key = "mySetting", bind_to_object = "myTable" }

This allows you to bind different properties in one view object to keys in different tables.
The bound table is typically the export-settings table, since your UI is typically a way for your user to see
and set these values. The SDK makes this default case easy for sections that you define for the Export
dialog. In views created with sectionsForTopOfDialog and sectionsForBottomOfDialog, the value of
bind_to_object for the entire view hierarchy is set automatically to the export-settings table passed
along with the view factory. See “Adding custom sections to the Plug-in Manager” on page 34.

Simple bindings
The simplest binding is between a property in the LrView object and a settings key of the same datatype,
and simply keeps the two synchronized. For example:
visible = LrView.bind( "LR_export_useSubfolder" )

In this case, both the local property (visible) and the bound table item (a Lightroom-defined export
setting) have Boolean values. Setting the use-subfolder preference to true (in the Export dialog, for
instance) makes the control visible.
For some other common types of binding, you can use an LrBinding function as the value assignment; for
example:
visible = LrBinding.negativeOfKey( "LR_export_useSubfolder" )

This binds the property to the opposite of the table value; that is, setting the use-subfolder preference to
true hides the control. The binding works in both directions; that is, hiding the control would also set
LR_export_useSubfolder to true. This function can be used to negate numeric as well as Boolean values;
for example, a value of 2 would become -2.
Although negativeOfKey() works both ways, and with numeric values, the other LrBinding functions
can be used only with Boolean values, and work only in one direction; a change in the bound table sets the
bound property value, but not the reverse. The LrBinding functions allow you to:
•

Set a Boolean property to the opposite of a Boolean key value, or a numeric property to the negation
of a numeric key value (LrBinding.negativeOfKey).

•

Set a Boolean property when a key value is or is not present (LrBinding.keyIsNil, keyIsNotNil).

•

Set a Boolean property when a key value is or is not equal to a specific value (LrBinding.keyEquals,
keyIsNot).

CHAPTER 5: Creating a User Interface for Your Plug-in
•

Binding UI values to data values 100

Set a Boolean property when a set of Boolean keys are either all true, or when any one is true
(LrBinding.andAllKeys, orAllKeys); for more information on how this works, see “Binding multiple
keys” on page 108.

For details of the LrBinding functions, see the Lightroom SDK API Reference.

Creating observable property tables
The Lightroom SDK defines a notification mechanism based on observable tables. When a value changes in
an observable table (such as the export-settings table), all registered observers (typically LrView objects)
are notified. A plug-in uses this mechanism to make UI controls in the plug-in’s user interface respond to
changes in data properties.
The LrView objects that define your UI elements in an Export dialog section are automatically registered
as observers of the export-settings table that is passed on creation; see “Adding custom sections to the
Plug-in Manager” on page 34.
To use export settings in another context, or to define additional program data, use the function
LrBindings.makePropertyTable() to create an observable table, and populate it with your own plug-in
settings or any other program data.
An observable table must be created with a function context, so that Lightroom can clean up the
notifications if anything goes wrong. (See “Using function contexts for error handling” on page 18.) A
function context is created using LrFunctionContext.callWithContext(). This passes a
function-context object to its main function; you pass that object on to your table-creation function. For
example:
LrFunctionContext.callWithContext("showCustomDialog", function( context )
local properties = LrBinding.makePropertyTable( context )
properties.url = "http://www.adobe.com" -- create a settings value
-- add code to take create dialog contents
end)

When you create a new table, it is initially empty. You can explicitly add keys and values, as in the example.
However, it is not necessary to add a key to a table before you reference it in a binding; if it is not yet in the
table, its value is nil. The example in “Transforming values” on page 106 shows how a control’s value is
bound to a key that is not yet in the table. When the control first gets a value, the key is put into the table
with that value.
TIP: You can use a naming convention to distinguish program data from persistent export settings (that is,
those specified in the exportPresetFields table; see “Remembering user choices” on page 59). For
example, you might use an underscore prefix, “_tempUrl,” to indicate a local data property.

Adding observers to tables
You can create a general and flexible response to a change in an observable table by adding an observer.
An observer associates a function that you define with a key in the table, so that whenever the key value
changes, the function is called.
To receive notification of changes in the table you create, use this function to register an observer of the
table:
propertyTable:addObserver( key, func )

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values 101

For example:
LrFunctionContext.callWithContext("showCustomDialog", function( context )
local myPropTable = LrBinding.makePropertyTable( context )
mypropTable:addObserver( 'mySetting', function( properties, key, newValue )
-- do something when this value changes
end )
-- add code to create dialog contents
end)

The handler function you specify for your observer takes as arguments the observed table (so you can
access other data values), the key whose value change triggered the notification (in case you are using the
same handler function for multiple keys), and the new value of that key.
You can define a function to handle more than one key notification, using the key argument to distinguish
which key changed. If you do, you must pass the function to a separate addObserver() call for each key.
For examples of how and why to add an observer to a table, see “Binding combo box selections” on
page 104, and Chapter 9, “Getting Started: A Tutorial Example.

Bindings for selection controls
Controls that have a selection state include checkboxes, radio buttons, pop-up menus, and (to some
extent) combo boxes. You can use bindings to keep track of the selection state, and to create
dependencies between what is selected in one of these controls and what is shown elsewhere in the UI, or
what actions are taken.

Binding checkbox selections
The value property of a radio button or checkbox controls and reflects the current selection state:
•

In both, if the user checks the button, the checked_value becomes the new control value.

•

In the checkbox, if the user unchecks the button, the unchecked_value becomes the new control
value.

EXAMPLE 1: This example shows how bindings work in checkboxes:
local LrBinding = import "LrBinding"
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrView = import "LrView"
local bind = LrView.bind -- shortcut for bind() method
LrFunctionContext.callWithContext( 'bindingButtonsExample', function( context )
local f = LrView.osFactory() -- obtain view factory
local properties = LrBinding.makePropertyTable( context ) -- make prop table
-- create some keys with initial values
properties.checkbox_state = 'checked' -- for checkbox
properties.my_value = 'value_1' -- for radio buttons and pop-up menu
local contents = f:column { -- create view hierarchy
fill_horizontal = 1,
spacing = f:control_spacing(),
bind_to_object = properties, -- default bound table is the one we made
f:group_box {
title = "Checkboxes", -- (only one here)
fill_horizontal = 1,
spacing = f:control_spacing(),

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values 102

f:checkbox {
title = "Value will be string",
value = bind 'checkbox_state', -- bind to the key value
checked_value = 'checked', -- this is the initial state
unchecked_value = 'unchecked', -- when the user unchecks the box,
-- this becomes the value, and thus
-- the bound key value as well.
},
f:static_text {
fill_horizontal = 1,
title = bind 'checkbox_state', -- bound to same key as checkbox value
},
},
-- (add radio button container here for example 2)
-- (add pop-up container here for example 3)
local result = LrDialogs.presentModalDialog( -- invoke the dialog
{
title = "Binding Buttons Example",
contents = contents,
}
)
end )

Binding radio button selections
The user cannot uncheck a radio button; a selected button is deselected only when another button in the
group is selected. Simply putting the buttons in the same container does not enforce this usage; to
arrange it, bind the value of each button in the set to a different value of the same key.
EXAMPLE 2: Add this to the previous code for an example of binding in a set of radio buttons:
f:group_box { -- the buttons in this container make a set
title = "Radio Buttons",
fill_horizontal = 1,
spacing = f:control_spacing(),
f:radio_button {
title = "Value 1",
value = bind 'my_value', -- all of the buttons bound to the same key
checked_value = 'value_1',
},
f:radio_button {
title = "Value 2",
value = bind 'my_value',
checked_value = 'value_2',
},
f:radio_button {
title = "Value 3",
value = bind 'my_value',
checked_value = 'value_3',
},
f:static_text {
fill_horizontal = 1,
title = bind 'my_value',
},
},

Binding UI values to data values 103

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding pop-up menu selections
The pop-up menu and the menu component of a combo box allow you to specify a set of choices, using an
items table; each item entry is a table containing a title and value. The title is localizable display text,
that appears in the menu (see Chapter 7, “Using ZStrings for Localization“).
items = { { title = "First item",
{ title = "Second item",
{ title = "Third item",

value = 1 },
value = 2 },
value = 3 }, },

The value of the item that the user selects from the menu becomes the control’s value. For the pop-up
menu, the title becomes the control’s title, and is displayed in the control when the menu is not
shown. (For the combo box, the displayed text is the value, or the result of the value_to_string
function; see “Edit-field view properties” on page 95.)
EXAMPLE 3: This code fragment adds a pop-up menu to the previous example, with the currently selected
value from the menu similarly bound to a static text value:
f:group_box {
title = "Popup Menu",
fill_horizontal = 1,
spacing = f:control_spacing(),
f:popup_menu {
value = bind 'my_value', -- current value bound to same key as static text
items = { -- the menu items and their values
{ title = "Value 1", value = 'value_1' },
{ title = "Value 2", value = 'value_2' },
{ title = "Value 3", value = 'value_3' },
}
},
f:static_text {
fill_horizontal = 1,
title = bind 'my_value', -- bound to same key as current selection
},
},
}

You can bind the items property to a settings key to create a dynamic menu. However, you can only set
the whole menu at once; you cannot bind individual item values.
EXAMPLE 4: This code binds the currently selected value from a pop-up menu to the same key as an
editable text value. The user can change this value by entering any text in the edit field; the entered text
shows up immediately as the value of the pop-up control.
However, since the user can enter any text, that text might not match the menu items. This code shows
how to use the pop-up control’s value_equal function to do a case-insensitive comparison of the
user-entered value with the item values. The function is called for each item until it returns true, or has
gone through all the items.
•

If the entered text matches one of the item values (that is, the function returns true), the matching
item becomes the selected item in the pop-up menu, and the item’s title text is displayed in the
pop-up control.

•

If the function goes through all the items without finding a match, the pop-up control shows no
selection; that is, it appears blank, and the next time the user pops up the menu, none of the items is in
the selected state. The entered value remains in the pop-up control’s value property.

local LrDialogs = import "LrDialogs"

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values 104

local LrFunctionContext = import "LrFunctionContext"
local LrStringUtils = import "LrStringUtils"
local LrView = import "LrView"
LrFunctionContext.callWithContext( 'bindingExample', function( context )
local f = LrView.osFactory()
local properties = LrBinding.makePropertyTable( context )
properties.format = "jpeg"
local contents = f:column {
spacing = f:control_spacing(),
bind_to_object = properties,
f:popup_menu {
items = {
{ title = "JPEG", value = "jpeg" },
{ title = "TIFF", value = "tiff" },
},
value = LrView.bind 'format',
value_equal = function( value1, value2 )
return LrStringUtils.lower( value1 ) == LrStringUtils.lower( value2 )
end,
},
f:edit_field {
immediate = true,
value = LrView.bind 'format',
},
}
local result = LrDialogs.presentModalDialog(
{
title = "Dialog Example",
contents = contents,
}
)
end )

Binding combo box selections
For a combo box, the user can enter text in the edit-field portion, which becomes the new control value. If
you select an item from the menu portion, that item value becomes the control value; this provides an
input shortcut for the user. Unlike the pop-up menu, the combo box menu items are simple values; if you
need to localize them, you must do so when building the item array.
This example shows how to create a dynamic menu for a combo box that gives previously-entered values
as menu choices. This code:
•

Binds the value and items of the combo box to data properties storeValue and storeItems.

•

Creates an observer for the storeValue property, so that a change in that property (caused by
entering a new value in the combo box) calls a function.
•

The observer function checks to see if the current value is already in the items list (stored in
storeItems), and if it is not, adds it to the list.

•

Because of the binding, any change the function makes to the storeItems property is
automatically reflected in the combo box items.

local
local
local
local

LrBinding = import "LrBinding"
LrDialogs = import "LrDialogs"
LrFunctionContext = import "LrFunctionContext"
LrStringUtils = import "LrStringUtils"

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values 105

local LrView = import "LrView"
-- Create an observable table within a function context.
LrFunctionContext.callWithContext( 'bindingExample', function( context )
-- Obtain the view factory.
local f = LrView.osFactory()
-- Create the observable table.
local properties = LrBinding.makePropertyTable( context )
-- Add an observer of the storeValue property.
properties:addObserver( 'storeValue', function( properties, key, newValue )
local items = properties.storeItems -- get current items list from this table
if items == nil then
items = {}
end
-- Check if current value is already in the list.
local inList
for i, v in ipairs( items ) do
if v == newValue then
inList = true
break
end
end
-- If not, add it.
if not inList then
items[ #items + 1 ] = newValue
end
-- Reset data value with current items list
properties.storeItems = items
end )
-- Create the view hierarchy for the dialog.
local contents = f:column {
spacing = f:control_spacing(),
bind_to_object = properties, -- bound to the table we created
f:combo_box {
value = LrView.bind 'storeValue', -- bind to observed key
items = LrView.bind 'storeItems', -- bind to data value that the
-- observer modifies
},
}
-- Display the dialog.
local result = LrDialogs.presentModalDialog(
{
title = "Dialog Example",
contents = contents,
}
)
end )

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values 106

Complex bindings
The LrBinding functions provide a particular, limited set of value transformations. To specify more
complex bindings, the argument to LrView.bind() can be a table with these items:
key

A key name in the bound table. The value can be mapped to a value for the
local property by the transform function.

bind_to_object

Optional. The name of an observable table which overrides the value of the
bind_to_object view property.

—or—
object
transform

Optional. A function that maps the key or key values to the local property
value. See “Transforming values” on page 106. This function is called
immediately when the value changes in either the bound view property or
the bound table key.

Here is an example of binding to keys in two different tables in a single view object:
...
visible = LrView.bind("myBooleanSetting"), -- simple binding between two
-- Booleans in the default table
enabled = LrView.bind( {
key = "mySetting", -- a single key
bind_to_object = mySettingsTable, -- a non-default bound table
transform = function( value, fromTable ) -- a mapping function
...
end
}
)
...

Transforming values
The transformation function that you specify for a binding maps the value of a key in the bound table to a
value in the bound property. If the LrBinding functions do not provide mapping that you need, define
your own transformation function. It is passed these parameters:
value: The new value of the key or property that changed.
fromTable (Boolean): True if the change that triggered this notification was in the bound table, false if
the change was in the bound view property.

Your function should return the new value for the destination property or key.
This simple example creates a slider with a range of 0-110, then reports when the value goes over 100, by
using a transformation function. The slider value and the visible property of a text box are bound to the
same key. For the text box, the transform function returns true (making visible true) only when the value
is over 100.
sectionsForTopOfDialog = function(viewFactory, propertyTable)
return {
{
title = "Section Title",
viewFactory:slider {
min = 0,

CHAPTER 5: Creating a User Interface for Your Plug-in

Binding UI values to data values 107

max = 110,
value = LrView.bind "slider_value",
title = "slider title",
},
viewFactory:static_text {
title = "You’re over a hundred",
visible = LrView.bind {
key = "slider_value",
transform = function(value, fromTable)
return value > 100
end
}
}
}
}
end

Transformations can work in both directions; changes in the bound property affect the bound table key,
and changes in the table key affect the property. If you write a custom function for a one-way
transformation, return the value LrBinding.kUnsupportedDirection to indicate that one or the other
direction is not supported by your transformation.
Here is an example of a one-way transformation. This example shows a transformation that makes a text
display visible only when text is entered in an edit field. The transform function checks for a value of nil or
the empty string in the key to which both controls are bound. This example pops up a dialog, so it needs to
create an observable table to hold the data.
local LrBinding = import "LrBinding"
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrView = import "LrView"
LrFunctionContext.callWithContext( 'bindingExample', function( context )
local f = LrView.osFactory() -- obtain the view factory
local properties = LrBinding.makePropertyTable( context ) -- make a settings table
-- the new table is initially empty
local contents = f:column {-- create view hierarchy for dialog
spacing = f:control_spacing(),
bind_to_object = properties, -- default bound table is the one we made
f:row {
fill_horizonal = 1,
spacing = f:label_spacing(),
f:static_text {
title = "Type anything:",
alignment = 'right',
},
f:edit_field {
fill_horizonal = 1,
width_in_chars = 20,
immediate = true,
value = LrView.bind( 'text' ), -- creates a key 'text'
-- the initial value of the new key is nil
-- setting its value (by entering text in the control)
-- puts it into the table
},
},
f:static_text {
place_horizontal = 0.5,
title = "This is only visible when there is text in the edit field",
visible = LrView.bind {
key = 'text', -- bind to the same key

Binding UI values to data values 108

CHAPTER 5: Creating a User Interface for Your Plug-in

transform = function( value, fromTable )
if fromTable then
return value ~= nil and value ~= '' -- check that key has a value
end
return LrBinding.kUnsupportedDirection
end,
}
},
}
local result = LrDialogs.presentModalDialog( -- invoke the dialog
{
title = "Binding Example",
contents = contents,
}
)
end )

Binding multiple keys
To specify even more complex bindings, between a property in a view object and multiple keys in one or
more bound tables, the value part of a binding key-value pair can be a table with these items:
keys

A table specifying one or more keys. The table can have these entries:
•

key : A key name in the bound table.

•

bind_to_object or object: Optional. The name of an observable table
which overrides both the default bind_to_object value and this
binding’s bind_to_object value.

•

uniqueKey: Optional. Because you can specify keys in different tables,

the names might overlap. This provides a unique name that is used to
identify this key in the values table passed to your operation function.

bind_to_object

—or—
object

Optional. An observable table which overrides the value of the
bind_to_object view property.

Binding UI values to data values 109

CHAPTER 5: Creating a User Interface for Your Plug-in

operation

Required. A function defining an operation to perform on the key values; the
result of this operation is passed to the transform function.
This function is called when any specified key value changes. The function
you define receives three parameters:
binder: For internal use.
values: A special look-up table of key-value pairs with the current values
of all specified keys. The key portion of the pair uses the uniqueKey

name, if provided. (This is not a general-purpose table; you cannot
iterate over the values.)

fromTable (Boolean): True if the change that triggered this notification
was in the bound table, false if the change was in the bound view
property.

This function is not called immediately, but at the end of an event cycle; this
means that, if the change is in the bound table, more than one key value can
have changed. If changes occur in both directions, the function is called
twice.
transform

Optional. A function that maps the return value of the operation function to
the local property value. See “Transforming values” on page 106.

This example shows multiple binding. The dialog contains two edit fields, each with its value bound to a
different key. A static text box below them has its visible property bound to both keys; the operation
makes it true only when both values are equal (meaning that the same text has been typed into both edit
fields, or they are both empty).
local LrBinding = import "LrBinding"
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrView = import "LrView"
LrFunctionContext.callWithContext( 'multiBindingExample', function( context )
local f = LrView.osFactory() -- get view factory
local properties = LrBinding.makePropertyTable( context ) -- make empty table
local contents = f:column { -- create view hierarchy
spacing = f:control_spacing(),
bind_to_object = properties, -- default bound table is the one we made
f:row {
fill_horizonal = 1,
spacing = f:label_spacing(),
f:static_text {
title = "Type anything:",
alignment = 'right',
width = LrView.share( 'label_width' ),
},
f:edit_field {
fill_horizonal = 1,
width_in_chars = 20,
immediate = true,
value = LrView.bind( 'text1' ), -- bind to the first key
},
},
f:row {
fill_horizonal = 1,

CHAPTER 5: Creating a User Interface for Your Plug-in

Determining layout

110

spacing = f:label_spacing(),
f:static_text {
title = "Type more:",
alignment = 'right',
width = LrView.share( 'label_width' ),
},
f:edit_field {
fill_horizonal = 1,
width_in_chars = 20,
immediate = true,
value = LrView.bind( 'text2' ), -- bind to the second key
},
},
f:static_text {
place_horizontal = 0.5,
title = "This is only visible when the text in the two fields are equal",
visible = LrView.bind {
keys = { 'text1', 'text2' }, -- bind to both keys
operation = function( binder, values, fromTable )
if fromTable then
return values.text1 == values.text2 -- check that values are ==
end
return LrBinding.kUnsupportedDirection
end,
},
},
}
local result = LrDialogs.presentModalDialog( -- invoke dialog
{
title = "Multi Binding Example",
contents = contents,
}
)
end )

Determining layout
Both the initial layout of a container, and subsequent automatic layout operations, use a set of parameters
set by properties in both the container and its child nodes. These values control the initial layout, and, if
the containing dialog is resizeable, the way the layout changes if the dialog size changes.
Properties control these broad categories of placement and sizing:
•

Spacing values determine how child nodes are placed relative to one another. See “Relative placement
of sibling nodes” on page 111.

•

Margin values determine how a node is placed and sized within its parent node. See “Placement
within the parent” on page 111.

•

You can obtain default layout values using “Factory functions for obtaining layout values” on
page 112.

CHAPTER 5: Creating a User Interface for Your Plug-in

Determining layout

111

Relative placement of sibling nodes
These properties determine how child nodes are placed relative to one another. They apply only to
containers. A margin is the interior margin of a container, the distance between the edge of the container
and its children; spacing is the distance between children. All numeric values are in pixels.
Layout property

Datatype

Description

place

string

The placement style. One of:
vertical (default): Children are placed in a column top down.
horizontal: Children are placed in a row left to right.
overlapping: Children are placed on top of one another.

margin

number

Space around children within the containing node.

margin_horizontal

number

Overrides the margin value for both the right and left sides.

margin_vertical

number

Overrides the margin value for both the top and bottom.

margin_left,
margin_right

number

Overrides the margin value for the left and right sides,
respectively.

margin_top,
margin_bottom

number

Overrides the margin value for the top and bottom,
respectively.

spacing

number

The amount of space placed between each child.
Ignored if place is overlapping.

Placement within the parent
These can be set on any view or control. These properties determine how child nodes are placed and sized
within the parent node. All numeric values are percentages, between 0 and 1.
Layout property

Datatype

Description

fill_horizontal
fill_vertical

number
[0..1]

The amount of free space that the node is sized to fill in
the given direction. These determine how a node is sized
relative to its siblings.
No node is made smaller than its minimum size. Each
child’s fill size is first treated as a proportion of the total
space desired; that is, 0.25 makes the node 25% of the
parent’s size.
If any of the child node fill needs cannot be met, they are
given a percentage of the extra space in the proportion
to how much they specified. For instance, if three nodes
specify 0.2, 0.2, and 0.4, and there is not enough extra
space, the nodes get 25%, 25% and 50% of the extra
space that is available.

CHAPTER 5: Creating a User Interface for Your Plug-in

Determining layout

112

Layout property

Datatype

Description

fill

number
[0..1]

The default fill value, if a specific horizontal or vertical
value is not provided.

place_horizontal
place_vertical

number
[0..1]

The place properties determine how a node is placed in
any extra space within its parent node; that is, extra
space available after the fill properties have been
considered. The percentage value determines how much
of the extra space is placed to the left or above the node.
Space allocated on a first-come first-served basis; if the
first child has a place_horizontal value of 1, it
consumes all of the extra horizontal space and there is
none left for its siblings.

width
height

number

The minimum size for this node in pixels, when it is
automatically resized.
If both are specified, the minimum size for the node is
not automatically calculated. If only one is specified, the
minimum size can be calculated in the other direction.

Factory functions for obtaining layout values
The LrView factory object defines a set of functions that you can use to obtain appropriate values for the
layout properties of individual containers and controls. For example, this sets a spacing property to a
recommended value for a control that is used either as a label or as the labeled object:
spacing = viewFactory.label_spacing()

Call these functions from the view factory passed to the sectionsForTopOfDialog or
sectionsForBottomOfDialog function, or obtained using the LrView namespace function
LrView.osFactory().
Default layout function

Description

dialog_spacing()

The number of pixels between elements that is appropriate for
top-level items in a dialog, such as views or group boxes.

control_spacing()

The number of pixels between controls or groups of controls.

label_spacing()

The number of pixels between a label and its control.

CHAPTER 5: Creating a User Interface for Your Plug-in

Determining layout

113

Layout examples
The following examples show how to build a basic dialog with an initial layout, how to make labels line up
properly, and how to set the dialog up to take advantage of automatic layout on resize.

Building a basic dialog
The following code creates a basic dialog within a function context. (See “Using function contexts for error
handling” on page 18.)
•

It creates a properties table with a plug-in defined property, url, which contains a URL.

•

It defines the contents of the dialog box using an LrView factory: a label, and an edit field that shows
the property value.

•

It invokes a modal dialog with LrDialogs.presentModalDialog(), passing in the defined view.
Based on the result of the invocation, it opens the web page using LrHttp.

This code demonstrates a very simple layout, where the topmost and only container is a row view, which
uses default values to place its two children, a label and an edit field.
local LrBinding = import "LrBinding"
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrHttp = import "LrHttp"
local LrView = import "LrView"
LrFunctionContext.callWithContext( 'dialogExample', function( context )
local f = LrView.osFactory() --obtain a view factory
local properties = LrBinding.makePropertyTable( context ) -- make a table
properties.url = "http://www.adobe.com" -- initialize setting
local contents = f:row {
-- create UI elements
spacing = f:label_spacing(),
bind_to_object = properties, -- default bound table is the one we made
f:static_text {
title = "URL",
alignment = 'right',
},
f:edit_field {
fill_horizonal = 1,
width_in_chars = 20,
value = LrView.bind( 'url' ),-- edit field shows settings value
},
}
local result = LrDialogs.presentModalDialog( -- invoke a dialog box
{
title = "Go to a URL",
contents = contents,
-- with the UI elements

CHAPTER 5: Creating a User Interface for Your Plug-in
actionVerb = "Go",

Determining layout

114

-- label for the action button

}
)
if result == 'ok' then -- action button was clicked
LrHttp.openUrlInBrowser( properties.url )
end
end )

Making labels line up
Typically, a dialog contains vertical sets of controls and their labels. The following code demonstrates how
make right-aligned labels on the left side of the dialog, with matching left-aligned controls on the right
side.

To make this happen, the example uses the alignment property and the LrView.share() function.
•

The alignment property determines whether a control is right-aligned, left-aligned, or centered. Since
at least one of these labels is wider than the text it is showing, the labels need to be right-aligned.
Labels should generally be right-aligned in any case, because if the dialog is translated, the size of the
text changes.

•

The namespace function LrView.share() binds a property value to an identifier that has no value of
its own, but indicates that this property value is to be shared across the hierarchy with other
properties that share the same identifier. In this case, the width of both labels is shared because they
use the same identifier, label_width. When layout occurs, the largest width value of the two labels is
used as the width for both of them.

local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrView = import "LrView"
LrFunctionContext.callWithContext( 'bindingExample', function( context )
local f = LrView.osFactory() -- obtain view factory
local contents = f:column { -- define view hierarchy
spacing = f:control_spacing(),
f:row {
spacing = f:label_spacing(),
f:static_text {
title = "Name:",
alignment = "right",
width = LrView.share "label_width", -- the shared binding
},
f:edit_field {
width_in_chars = 20,
},
},
f:row {

CHAPTER 5: Creating a User Interface for Your Plug-in

Determining layout

115

spacing = f:label_spacing(),
f:static_text {
title = "Occupation:",
alignment = "right",
width = LrView.share "label_width", -- the shared binding
},
f:edit_field {
width_in_chars = 20,
},
},
}
local result = LrDialogs.presentModalDialog( -- invoke the dialog
{
title = "Dialog Example",
contents = contents,
}
)
end )

Changing the contents of a view dynamically
This simple example of dynamic layout shows one set of controls and hides another set, based on the
selected value in a pop-up menu. The dialog contains the popup and three views, each containing an
alternate set of controls. When the user makes a selection in the pop-up menu, one of the views is shown,
and the other two are hidden. For example:

This technique makes use of the overlapping placement style, and demonstrates binding of a property in
one node to a property in another, so that changing one also changes the other.
The overlapping value for the place property causes all of the children of a node to be placed in the
same space. The parent views are made big enough to enclose the largest child in any view, and all of the
children are placed within that space.
If all of the children were visible at the same time, they would display on top of one another. To make sure
only one view is visible at a time, we bind the visible value of each alternative view to a unique value of
the pop-up menu. When the user makes the selection that has this value, the view bound to that value is
shown, and the other views (bound to different values) are hidden.
•

You only need to set the visibility of the parent view; when the parent is hidden, all of its child nodes
are also hidden, regardless of their individual visibility settings.

•

The LrBindings.whenKeyEquals() function sets visible to true only when the specified value of
the bound property is set. You could choose to bind the true value to, for example, a logical OR or AND
of several key values.

CHAPTER 5: Creating a User Interface for Your Plug-in

Determining layout

This example creates the overlapping views shown in the figure, where the controls shown below the
format pop-up depend on the selection in the pop-up menu.
local LrBinding = import "LrBinding"
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrView = import "LrView"
LrFunctionContext.callWithContext( 'bindingExample', function( context )
local f = LrView.osFactory() -- obtain the view factory
local properties = LrBinding.makePropertyTable( context ) -- make settings table
-- add some keys with initial values
properties.format = "jpeg"
properties.jpeg_quality = 80
properties.tiff_compression = "none"
local contents = f:column { -- define the view hierarchy
spacing = f:control_spacing(),
bind_to_object = properties, -- default bound table is the one we made
f:popup_menu {
items = {
{ title = "JPEG", value = "jpeg" },
{ title = "TIFF", value = "tiff" },
},
value = LrView.bind 'format', -- bind selection to the format key
},
f:column { -- place two views in the same space
place = "overlapping",
-- JPEG view
f:view {
-- shown only when format selection is JPEG
visible = LrBinding.keyEquals( "format", "jpeg" ),
margin = 3,
f:row {
spacing = f:label_spacing(),
f:static_text {
title = "Quality:",
},
f:slider {
min = 0,
max = 100,
value = LrView.bind 'jpeg_quality', -- sets a JPEG value
fill_horizontal = 1,
place_vertical = 0.5,
},
f:edit_field {
width_in_digits = 3,
min = 0,
max = 100,
precision = 0,
value = LrView.bind 'jpeg_quality', -- sets a JPEG value
},
},
},
-- TIFF view
f:view {
-- shown only when format selection is TIFF
visible = LrBinding.keyEquals( "format", "tiff" ),
margin = 3,
f:row {
spacing = f:label_spacing(),
f:static_text {

116

CHAPTER 5: Creating a User Interface for Your Plug-in

Determining layout

title = "Compression:",
},
f:popup_menu {
items = {
{ title = "None", value = 'none' },
{ title = "LZW", value = 'lzw' },
{ title = "ZIP", value = 'zip' },
},
value = LrView.bind 'tiff_compression',-- sets a TIFF value
},
},
},
},
}
local result = LrDialogs.presentModalDialog( -- invoke the dialog
{
title = "Dialog Example",
contents = contents,
}
)
end )

117

6

Writing a Web-engine Plug-in
This chapter describes the web-engine plug-in mechanism in the Lightroom SDK. This mechanism allows
you to define new HTML web engines for the Web module. A web engine controls how a photo gallery is
generated.
Web-engine plug-ins use a different architecture from standard plug-ins, and are not managed by the
Plug-in Manager dialog. All available web engines appear in the Engine panel at the upper right of the
Web module of Lightroom, including those predefined by Lightroom and any defined by plug-ins.
Your plug-in can also customize the control panels in the Web module, so that the controls map to
user-customizable features of your own web engine.

Creating a web-engine plug-in
A web-engine plug-in consists of:
•

A manifest file named manifest.lrweb, which maps LuaPage source files to the HTML output files
that make up a photo gallery. This file uses a special command set; see “Web SDK manifest API” on
page 130.

•

An information file named galleryInfo.lrweb, which defines the data model and customized UI for
your gallery type. See “Defining the data model” on page 119.

•

One or more web-page templates, in the form of LuaPages; that is, HTML pages with embedded Lua
code that is evaluated for display in the preview browser, or on publication, to generate dynamic
content. See “LuaPage syntax” on page 136.

•

Additional resources and supporting files, such as images, style sheets, string dictionaries for
localization, and code files that define special behaviors.

Collect these files into a single folder, which you must place in the following directory according to your
operating system:
IN MAC OS: userhome/Library/Application Support/Adobe/Lightroom/Web Galleries/
IN WINDOWS: LightroomRoot\shared\webengines
The name of the plug-in folder must end with .lrwebengine; for example, myWebPlugin.lrwebengine.

Folder contents
Here are the contents of a sample web-engine folder named default_html.lrwebengine:
Root

default_html.lrwebengine/

Template
information

manifest.lrweb
galleryInfo.lrweb

118

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

LuaPage
templates

about.html
detail.html
foot.html
grid.html
head.html

Resources

resources/

style sheets

css/ie6.css
ie7.css
master.css

JavaScript

js/live_update.js

images

misc/icon_fullsize.png
shadow-grid.gif
shadow.png

Localization
dictionaries

strings/
de/TranslatedStrings.txt
en/TranslatedStrings.txt
fr/TranslatedStrings.txt
ja/TranslatedStrings.txt

Iconic preview

iconic_preview/flash_gallery_preview.swf

source files (not
needed for
delivery)

119

flash_gallery_preview.as
flash_gallery_preview.fla

Defining the data model
The folder that defines your gallery type must define the data model in an information file named
galleryInfo.lrweb. The file defines various parameters for the gallery, using this simple Lua-table
format:
return {
property_name_1 = "value string",
property_name_2 = "value string",
...
}

Top-level property names are predefined, as shown in “GalleryInfo top-level entries” on page 120.
•

The top-level model property is extensible, containing both predefined and plug-in-defined sections
to create a complex data model. Sections are grouped, using brackets and dot notation to specify a
complex property name. See “Data model entries” on page 121.

•

The top-level views property is a function that customizes the user interface for your web engine,
creating UI controls in the Web module control panels and binding them to the data model that your
plug-in defines. See “Defining a UI for your model” on page 123.

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

120

GalleryInfo top-level entries
The following top-level properties are defined in the galleryInfo.lrweb file:
title

A localizable title string for the gallery type, which appears in the
Web module’s Engine list. You can localize the title string using the
LOC function.

id

Each gallery must have a unique identifying string. By convention,
use reverse-domain nomenclature, as for Java packages. For
example, com.myCompany.myDivision.myGallery.

galleryType

The type of gallery. Currently only one type is allowed:
•

"lua" — An HTML gallery that uses Lua Server Pages.

maximumGallerySize

The maximum number of photos this gallery can reasonably
display.

model

A table of user-configurable options for this web engine such as
colors, labels, dimensions, image quality settings, grid row and
column specifications, and so on.
The keys in this table are strings that use dot-separated notation
to break into separate areas; for example,
"model.nonDynamic.numRows".
See“Data model entries” on page 121.

views

A function that returns a table of view descriptions by name, with
entries for "labels", "colorPalette", "appearanceConfiguration", and
"outputSettings". Each of these corresponds to a panel in the Web
module, and each entry defines new UI controls to be added to
that panel.
See “Defining a UI for your model” on page 123.

iconicPreview

A table of information for controlling the live preview movie for a
gallery in the Preview panel.
See “Creating a preview” on page 128.

aboutBoxFile

The name of an HTML file to be displayed in the About box for this
web engine. The file must be simple, self-contained HTML that
does not reference any other resources (such as CSS or images).
The About box is displayed when the user chooses Web > About
[thisEngine].

supportsLiveUpdate

Boolean, true if this web engine supports the Live Update
mechanism. See “Web HTML Live Update” on page 142.

This example shows the top-level entries from the galleryInfo.lrweb file of the built-in HTML gallery:
return {
LrSdkVersion = 5.0,
LrSdkMinimumVersion = 2.0, -- minimum SDK version required by this plugin

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

121

title = LOC "$$$/AgWPG/Templates/HTML/Title=Lightroom HTML Gallery",
id = "com.adobe.wpg.templates.jardinePro",
galleryType = "lua",
maximumGallerySize = 50000,
aboutBoxFile = "about.html",
supportsLiveUpdate = true,
model = {...}
}

Here is the About box for the built-in HTML Web Gallery:

Data model entries
The model entry in the table returned by the galleryInfo.lrweb file defines the data model for your web
engine. The model entry contains both predefined sections such as photoSizes, and plug-in-defined
sections for local data, such as the one named metadata in the following example.
return {
...
model = {
[ "photoSizes.large.width" ] = 250,
...
[ "photoSizes.thumb.width" ] = 130,
...
["appearance.textColor.color"] = "#166AF2",
["appearance.textColor.cssID"] = ".textColor",
...
["lightroomApplication.identityPlateExport"] = "(main)",
["lightroomApplication.jpegQuality"] = 70,
...
["metadata.siteTitle.value"] = LOC
"$$$/Templates/HTML/Defaults/props/SiteTitle=Site Title",
...
}

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

122

}

Within the predefined photoSizes section, the size-class names (in this example, large and thumb) are
defined by the plug-in. Within each size class, however, there are a set of predefined properties such as
width and height.
Model properties can have simple number, string or color values, but to make a property dynamic, you can
make the value a function definition. See “Creating a dynamic data model” on page 127.
These are the predefined properties for the model table:
appearance.cssClass.cssProp
appearance.cssClass.cssID

For an HTML gallery, entries in the appearance section are
available in CSS form automatically, if they follow the correct
convention. Specify each key is in this format:
[ "appearance.cssClassName.cssPropertyName" ] = value

In addition, for each unique name, you must also add an entry
that tells Lightroom what CSS selector to use for that name, in this
form:
[ "appearance.cssClassName.cssID" ] = selectorName

For example, to control the background color of all elements that
belong to CSS class myClass, and provide an initial default value
of red, add these two entries to the model:
[ 'appearance.myClass.background-color' ] = "#ff0000",
[ 'appearance.myClass.cssID' ] = '.myColor',
photoSizes.sizeClass.property
width
height
maxWidth
maxHeight
metadataExportMode
tracking

These entries specify size classes of rendered JPEGs Lightroom
should create. Some galleries might have only one size, such as a
thumbnail-only gallery, but typically a gallery has layers with
different image sizes (such as thumbnail, small, full-size). The
size-class names are defined by your plug-in.
For each named size class, you can specify properties; for example:
[ "photoSize.small.width" ] = 50,

Each size class has these properties:
width, height—The size in pixels, as chosen by the user
maxWidth, maxHeight—The largest allowed size in pixels
metadataExportMode —What metadata to include, either

'copyright' or 'all'.
tracking—Binds to the image-size slider in the control
panel, so that the image can be resized interactively during
preview. Lightroom sets this to true while resizing is in
progress.

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

123

lightroomApplication.property
identityPlateExport
jpegQuality
useWatermark
outputSharpeningOn
outputSharpening

These properties control how Lightroom behaves when creating
the gallery:

perImageSetting.property
setting_names

A table that defines a per-image text description. Specifying one
of these entries customizes the Image Info panel in the Web
module. Each perImageSetting entry defines a checkbox, label,
and edit text control, like those for the built-in per-gallery Title
and Caption.

identityPlateExport—If your gallery can encorporate a
PNG version of the identity plate, use the value "(main)".
jpegQuality—The quality of the rendered JPEGs. Range is
[0..100], where 100 is the best quality.
useWatermark—True if rendered JPEGs should include a
copyright watermark.
outputSharpeningOn—True if rendered JPEGs should be
sharpened. Default is true.
outputSharpening—The type of sharpening, one of 1 (low),
2 (standard, the default), or 3 (high).

Each table has these entries:
title —The localizable display name of this setting, which
appears in the label.
value — Text to associate with each image. A string that can
contain text-token placeholders in double curly braces. The
user can edit this text.
enabled— When true, the checkbox is checked.

These values are stored as properties of image.metadata. Your
template for the image details page can reference the text in order
to display it with the image. For example, if you name a setting
description, access the value using
$image.metadata.description.value.
See “Customizing per-image text” on page 126.
plug-in-defined properties

You can define additional properties to store gallery-wide text
labels; for example, a site title or collection title. You can also
define properties to store appearance parameters that control the
look of the gallery, but do not work through CSS; for example,
how many rows or columns in the grid, or color properties that
need to be accessed dynamically by JavaScript. The names of such
properties are defined by your plug-in for its own use.

Defining a UI for your model
The views entry in the table returned by the galleryInfo.lrweb file defines the user interface for your
web engine. It is a function that is passed two arguments, a controller (which is an observable table that
contains your model data) and a webViewFactory object that allows you to create and populate UI
elements (as described in Chapter 5, “Creating a User Interface for Your Plug-in.")

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

124

The function returns a table of view descriptions by name, with entries that correspond to the control
panels at the right of the Web module.
labels

The Site Info panel, which allows users to specify text to be
associated with the site.

colorPalette

The Color Palette panel, which allows users to adjust the colors of
various elements of the site.

appearanceConfiguration

The Appearance panel, which allows users to adjust the appearance
of individual photos.

outputSettings

The Output Settings panel, which allows users to adjust various
output parameters such as image quality and metadata inclusion.

Plug-in-defined engine
Panels correspond to entries:
"labels"
"colorPalette"
"appearanceConfiguration"

"outputSettings"

Controls in each panel
bound to model data

Within each entry, you can use the view factory object to create UI controls. Set the bound table to be the
controller table, and bind control values to data values you have defined in your model.

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

125

Here is an example of the format of the views function for your web engine:
return {
...
views = function( controller, f )
local LrView = import "LrView"
local bind = LrView.bind
local multibind = viewFactory.multibind
return {
labels = f:panel_content { -- returned item identifies panel
bind_to_object = controller, -- bound table is passed controller
f:subdivided_sections {
f:labeled_text_input { -- create controls in the sections
title = "Site Title",
value = bind "metadata.siteTitle.value", -- bind to model data
},
...additional content...
},
colorPalette = f:panel_content {
bind_to_object = controller,
...define content...
},
appearanceConfiguration = f:panel_content {
bind_to_object = controller,
...define content...
},
outputSettings = f:panel_content {
bind_to_object = controller,
...define content...
},
},
}
end,
...
}

Using web view factories
Notice that the view factory passed to views function is an extension of the standard view factory
described in Chapter 5, “Creating a User Interface for Your Plug-in." It is an object of type
LrWebViewFactory, and it defines these additional functions for creating UI content suitable to the Web
module (see the Lightroom SDK API documentation for details):
panel_content

Creates a top-level panel in the Web module, which contains sections
divided by heavy black lines.

subdivided_sections

Creates a section within a panel in the Web module. Within the section,
control rows and columns are separated by light gray lines.

header_section_label

Creates a text label for a section within a panel, with suitable formatting.

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

126

content_column
slider_content_column
checkbox_and_color_row
color_content_column
content_section
header_section

These create column-style containers for controls within a section. Some
are generic, and some are specialized to particular types of row content,
with suitable formatting.

row
popup_row
slider_row
checkbox_and_color_row
label_and_color_row
checkbox_row
labeled_text_input

These create row-style containers within column-style containers. Some
are generic, and some contain specific sets of controls, with suitable
formatting.

metadataModeControl
warning_icon
identity_plate
row_column_picker

These create individual controls of types appropriate to web-engine
usage. These can be placed in unspecialized column or row containers.

Customizing per-image text
The Image Info panel allows the user to specify text for use in gallery pages. Each text label is named with
a label, such as Caption or Title, and can be enabled with a checkbox. A menu of preset values (the custom
settings menu) allows the user to get dynamic text from the current image’s metadata. The presets can be
further customized using the Text Template Editor, which allows users to define text that incorporates
dynamic values from metadata. The user can also save customized text templates as new presets.
Your page templates can access the user’s text choices using this syntax:
You can use the model entry perImageSetting to add text labels to your model. Each setting is identified
by a property name that you define. Each setting adds a row of controls to the Image Info panel, which
allows the user to choose the text value of that label.
Your page templates can access the user’s text choices for it using this syntax:
$image.metadata.propertyName

For example, the following defines a simple per-image description and title:
model = {
...
["perImageSetting.details"] = {
enabled = true,
value = "Default Custom-Text value",
title = LOC "$$$/WPG/HTML/CSS/properties/ImageDetails=Details",
},
["perImageSetting.datatext"] = {
enabled = true,
value = "Default Custom-Text value",
title = LOC "$$$/WPG/HTML/CSS/properties/ImageData=Metadata",
},
}

CHAPTER 6: Writing a Web-engine Plug-in

Defining the data model

127

This definition creates these controls in the Image Info panel:

The localized title text appears as the display name for the label. The checkbox and presets menu are
supplied by Lightroom. The value of the value entry appears as the default value for the Custom Text
preset choice.
To incorporate the user’s choice of text in the image-detail template page, use code like this:




$image.metadata.datatext, $image.metadata.details

Localizing the UI Strings that appear in the UI, either in predefined LIghtroom controls or menus, or in those you define, can be localized using the LOC function, as described in Chapter 7, “Using ZStrings for Localization. The LOC function looks up localized values in string dictionaries; your plug-in must supply these as part of the plug-in folder. To add string dictionaries to your plug-in, create a strings resource folder in your main plug-in folder, and name the subfolders with the appropriate language codes. For example: myWebPlugin.lrwebengine/strings/de/TranslatedStrings.txt myWebPlugin.lrwebengine/strings/fr/TranslatedStrings.txt ... Localization occurs when the user publishes the gallery. To get different language versions, the user must run Lightroom in the desired locale, and publish another version of the gallery. Creating a dynamic data model Model properties can have simple number, string or color values, but to make a property dynamic, you can make the value a function definition. When it needs to access the property, Lightroom executes the function and the result is returned as the property value. The evaluation context makes your data model available in the global scope. CHAPTER 6: Writing a Web-engine Plug-in Defining the data model 128 A typical use of dynamic data is to tie two properties together, so that changing one changes the other. For example, you might want to control the aspect ratio by making photoSizes.mySize.width to be equal to photoSizes.mySize.height. To do this, you can use a function definition as the value of one of the properties. For example: ["photoSizes.large.height"] = function() return photoSizes.large.width end, ["photoSizes.large.width"] = 450, This function simply accesses and returns the value of another property. You can, however, define a function to perform some transformation of the related value. You can, for instance, add formatting and logic using Lua's basic math and string manipulation functions. Lightroom also provides a function, LrColorToWebColor, that converts an LrColor object to a string representation suitable for use in CSS. Creating a preview The iconic preview for a web engine is an SWF movie of a gallery that can be shown in the "Preview" panel of the Web module. It presents a dynamic preview of the gallery using icons, rather than full-size images. You can use the iconicPreview top-level gallery-info entry to specify how the iconic preview for your gallery should be implemented. This entry references a simple Flash® movie (which you must implement and include in the web-engine folder) that renders an “iconic” representation of each web page, in order to convey the general look of the web gallery in a simple, stylized form. The iconicPreview entry is a table with two entries: flashMovie A string value, the relative path from the root web-engine folder to a compiled Flash movie (an SWF file). flashvars A function that returns a table of values to be used in the Flash movie. These are the model properties that you want represented in the iconic preview. Each entry in this table is available at the _root level of the Flash movie environment. Numbers and string values are passed through without any conversions. LrColor objects are converted to a string representation that is easy to parse in ActionScript™. Here is an example of an IconicPreview entry in the galleryInfo.lrweb file: return { ... iconicPreview = { flashMovie = "iconic_preview/flash_gallery_preview.swf" flashvars = function() local iconicData = { foregroundColor = appearance.textColor.color, showLogo = appearance.logo.display, cellBorderColor = nonCSS.cellBorderColor, cellRolloverColor = nonCSS.cellRolloverColor, cellBackgroundColor = nonCSS.cellColor, bodyBackgroundColor = appearance.body[ "background-color" ], numRows = nonCSS.numRows, numCols = nonCSS.numCols, } return iconicData end, ... } CHAPTER 6: Writing a Web-engine Plug-in Defining the data model 129 Creating the Flash movie Your web-engine folder must include a simple Flash movie that renders the "iconic" representation of each web page. The ActionScript file that defines your movie can access the global variables provided by the flashvar entry in iconicPreview, at the top level of the _root object. Your Flash movie should do these things: 1. Set the stage behavior: Stage.scaleMode = "noScale"; Stage.align = "tl"; This ensures that your preview renders without stretching or distortion. 2. Create an external interface callback called ready, which Lightroom will poll waiting for your preview to finish drawing: _root.ready = 'no'; _root.readyFunc = function(str:String) { return _root.ready; } ExternalInterface.addCallback("ready", _root, _root.readyFunc); Then at a later time (usually in a subsequent frame): _root.ready = 'yes'; Once your ready function returns "yes", Lightroom takes a screenshot of the Flash movie and terminates its execution (in order to reduce CPU usage) 3. Initialize default values, so that you can preview your movie without running it in Lightroom. var numCols; if( _root.numCols != null ) { numCols =parseInt( _root.numCols ); } else { // default value numCols = 4; } Do this for each model property you are using in your preview. 4. Draw the preview. This can be done by rearranging existing objects that you created in Flash, or simply by using the drawing primitives of the ActionScript programming language. For example: var cellSize = 10; for( x = 0; x < numCols; x++ ) { _root.beginFill( cellColor, 100 ); _root.moveTo(x*cellSize, y* cellSize ); _root.lineTo( (x+1)* cellSize, y* cellSize ); _root.lineTo( (x+1)* cellSize, (y+1)* cellSize ); _root.lineTo( x* cellSize,+ (y+1)* cellSize ); _root.endFill(); } This draws as many rectangle as are specified in the numCols Flash variable. CHAPTER 6: Writing a Web-engine Plug-in Web SDK manifest API 130 Web SDK manifest API The manifest is a Lua file in your plug-in’s root directory named manifest.lrweb. It maps LuaPage source files and template files to web-engine HTML output files using a set of commands for different kinds of pages and resource files. Define the mapping using these commands: AddPage Maps one source LuaPage file from the gallery template directly into the published gallery. AddResource AddResources Maps one resource file or a set of resource files from the gallery template directly into the published gallery. Resources can include image or icons, string dictionaries for localization, JavaScript files, and so on. AddPhotoPages Uses a LuaPage template to build a page for each photo in the current Lightroom selection. AddGridPages Uses a LuaPage template to build a page for each grid of photos in the current Lightroom selection. AddCustomCSS Generates a CSS file using the appearance properties of your data model. IdentityPlate Exports an identity plate as a PNG file. importTags() Adds custom tagsets to your gallery. AddPage Maps one source LuaPage file from the gallery template into the published gallery. The source file is interpreted by the LuaPage engine, resulting in an HTML file in the published gallery. Inputs filename The path to which to write the file in the published gallery. template The path to the source LuaPages file, relative to the folder containing this manifest. Example AddPage { filename = "content/pages/myWebPage.html", template = "myWebPage.html", } AddResource Maps one resource file from the gallery template directly into the published gallery. A resource is not interpreted, but is simply copied directly. CHAPTER 6: Writing a Web-engine Plug-in Web SDK manifest API 131 Inputs source The path to the resource file, relative to the gallery template. destination Optional. The path to the published gallery to which to copy the resource. By default, the destination path is the same as the source path. Example AddResource { source = "image.png", destination = "content/resources/image.png", } AddResources Copies a set of resource files from the gallery template directly into the published gallery. A resource is not interpreted, but is simply copied directly. Inputs source The path to the resource folder, relative to the gallery template. destination Optional. The path to the published gallery to which to copy the resources. By default, the destination path is the same as the source path. Example AddResources { source = "resources", destination = "content/resources", } Alternative syntax Instead of passing a table of named arguments, pass a single string to be used as the source: AddResources "resources" AddPhotoPages Uses a LuaPage template to build a separate page for each photo in the current Lightroom selection. Inputs filetype Optional. A file extension for the pages. Default is "html". variant Optional. A suffix to append to the file name. Useful if your gallery has several sizes of pages for each photo. Default is the empty string. destination The path to the published gallery to which to write the pages. template The path to the source LuaPage file. CHAPTER 6: Writing a Web-engine Plug-in Web SDK manifest API 132 LuaPages environment variables When executing the LuaPages for AddPhotoPages, the following variables are defined in the environment filename The file name of the current page. root The relative path to the root of the gallery. gridPageLink If grid pages have been added to the gallery, the relative path from this page to the corresponding grid page that contains this photo. pageType The page type, "photo". index The index position of the photo within the gallery. Example AddPhotoPages { template = 'detail.html', variant = '_large', destination = "content", } AddGridPages Uses a LuaPage template to build a page for each grid of photos in the current Lightroom selection. Inputs filetype (Optional) A file extension for the pages. Default is "html". destination The path to the published gallery to which to write the pages. template The path to the source LuaPage file. rows The number of rows in each grid. columns The number of columns in each grid. LuaPages environment variables When executing a LuaPage specified with AddGridPages(), the following variables are defined in the environment filename The file name of the current page. pageType The page type, "grid". page The position index of the current page among grid pages defined in the gallery. CHAPTER 6: Writing a Web-engine Plug-in Web SDK manifest API 133 In addition, if you use AddGridPages() to add any page, all of the LuaPages in your gallery can use these environment variables: numGridPages The number of grid pages in the gallery filenameOfGridPage( pageNumber ) A function that takes a grid page number and returns the file name string for that page. gridPageForPhotoAtIndex( photoIndex ) A function that take a photo index position and returns the file name for the grid page containing the photo. rows The number of rows on the grid pages. columns The number of columns on the grid pages. Example AddGridPages { destination='content', template='grid.html', rows=model.nonDynamic.numRows, columns=model.nonDynamic.numCols, } AddCustomCSS Generates a CSS file using the appearance properties defined in your data model. When you declare your data model in the galleryInfo.lrweb file, this command exports to CSS all entries that begin with "appearance.". Inputs filename (string) The path and name of the output file. Example To specify the background color of the body using CSS, you need a declaration like this: /* Desired CSS output */ body { background-color: #ff0000, } To make your web engine generate this: 1. Declare the intention to emit CSS in the manifest file, manifest.lrweb: AddCustomCSS { filename='content/custom.css', } 2. Define the required data model entries in the information file (galleryInfo.lrweb): return { ... CHAPTER 6: Writing a Web-engine Plug-in Web SDK manifest API 134 model = { ... ["appearance.body.background-color"] = "#ff0000", ["appearance.body.cssID"] = "body", ... }, ... } 3. To make this something the user can edit, add a corresponding control to one of the panel descriptions in the views section of your information file (galleryInfo.lrweb): return { ... views = { ... myViewFactory.label_and_color_row { bindingValue = "appearance.body.background-color", title = "Background", }, ... ... } IdentityPlate Exports an identity plate as a PNG file, if the user chooses to use it. During a Lightroom preview of the web gallery, the PNG file is always generated, to support a live update of the model-defined property that controls identity-plate use. If the user chooses not to use an identity plate, however, the PNG is not exported as part of any export, upload, or preview-in-browser operation. Inputs destination (string) The path to the published gallery to which to write the image file. enabledBinding (string) The plug-in-defined entry in the data model that controls whether to export the identity plate. Example The appearance section of the model defines a logo.display properties: ["appearance.logo.cssID"] = ".logo", ["appearance.logo.display"] = false, The views section of the model binds the property to the identityPlateExport checkbox (defined by the Lightroom application): myViewFactory:identity_plate { value = bind "lightroomApplication.identityPlateExport", enabled = bind "appearance.logo.display", }, CHAPTER 6: Writing a Web-engine Plug-in Web SDK manifest API 135 In the manifest, use the IdentityPlate command to enable this binding: IdentityPlate { destination='content/logo.png', enabledBinding = [[appearance.logo.display]], } When the user selects or deselects the checkbox, this binding causes the corresponding model property (logo.display) to be set to true or false, and thus the corresponding CSS property (.logo) to be set to the correct image (logo.png), or to none. If the user does not choose to export the identity plate, the file content/logo.png is not generated on upload. importTags() Adds custom tagsets to your gallery (see “Web SDK tagsets” on page 138). This is a function which takes two ordered parameters: prefix (string) A short prefix used to identify tags belonging to this tagset. For example, "lr". tagsetPath (string) A path to the tagset definition file. The special path "com.adobe.lightroom.default" loads the default tagset. Example 1. Create a tagset file called myTags.lrweb.: tags = { fancyQuote = { startTag = 'write( [[]] )', endTag = 'write( [[]] )', } } 2. In your manifest.lrweb file, import the tagset definition file by name: importTags( "xmpl", "myTags.lrweb" ) 3. Use that tagset in any LuaPages file, identifying each defined tag with the specified prefix: A wise man once said:
Don't count your chickens before they're hatched
4. This results in the following in the HTML output:
A wise man once said:
Don't count your chickens before they're hatched
CHAPTER 6: Writing a Web-engine Plug-in LuaPage syntax 136 LuaPage syntax A LuaPage is a Lua-language source file that is evaluated to produce one destination web page in your published gallery. In the manifest, use the AddPage command to map each source LuaPage to a destination file location. Environment variables available to LuaPages A LuaPage is evaluated in a context that provides many of the Lua functions of a default Lua installation, and also some special functions that are specific to the web photo gallery templating language. These read-only variables are available: Variable Description getImage(imageIndex) A function that returns an imageProxy. mode • When the gallery is being previewed inside Lightroom, the value is the string "preview". • During export, upload or preview in browser, it is set to "publish". numImages The number of photos in the gallery. string math Standard Lua namespaces. table A subset of the default Lua table namespace; contains the insert function. ipairs pairs type tostring Standard Lua functions LOC Text values can be localized. Use this function as a string value in order to specify a string by a unique identifier; your plug-in must provide a string dictionary in which to look up the display-string value for the current system language. See “Localizing the UI” on page 127." LrTagFuncs A table of private helper functions for the lr: tags CHAPTER 6: Writing a Web-engine Plug-in LuaPage syntax Variable Description includeFile() An execution-time function that allows a page to include another file using runtime logic to specify which file. For example: 137

My web gallery

This is the grid.html file.
Include a file using the include directive: <%@ include file="subdir/foo.html" %>
Include same file using the includeFile command: <% includeFile( 'subdir/foo.html' ) %>
Include a file that includes another file: <% includeFile( 'file1.html' ) %> LuaPage data types These data types are defined: imageProxy An object that has these properties: exportFilename (string) The base name string of a JPEG that will be written to disk for this photo. rating (number) The numeric rating for the image, or nil if it has no rating imageID (string) The id_global string for this image. renditions (array of object) An array of imageRendition objects for the renditions of this photo. metadata (table) A table of metadata settings, based on the perImage settings. colorLabel (string) The localized text for a photo’s colorLabel, such as "red", or nil. imageRendition An object that represents an image rendition for a photo. It has these properties: width (number) The width in pixels. height (number) The height in pixels. relPath (array of string) An array of directory names, in which the last entry is the file name. dir (array of string) An array of directory names. CHAPTER 6: Writing a Web-engine Plug-in cropMode Web SDK tagsets 138 How to size the image. One of: minimum — Fits the image within thephotoSize dimensions. maximum — Scales the image to be at least as big as both photoSize dimensions. metadataExportMode How to export metadata. One of: copyright — Export only copyright information. This is equivalent to the "Minimize Metadata" option in the Export dialog all — Export all metadata. Web SDK tagsets A tagset is an external file containing macro-like definitions that can be loaded by your web pages. These are similar to JSP Tag Libraries, but simpler. They allow you to extract common content and logic that appears on multiple pages into a custom set of tags. Once defined and imported, you can use the tags just like regular HTML tags. At run time, your LuaPage, replaces the tag with its Lua-language tag definition, which it then compiles and executes to product the HTML output. There is built-in set of tags included with the Lightroom SDK, which you can also include and use in your LuaPages. Defining custom tags To define a tagset in Lua, specify a tags table. This is a table of tables, where each element table defines one tag. The first element is the tag’s unique name, and the value is a table containing a startTag and endTag element: tags = { tagName = { startTag = "macroCode", endTag = "macroCode", }, } The value of the startTag and endTag element is a string containing Lua code. It can use global functions and constants defined in the same page using a globals table. This is again a table in which each element defines one function or constant: globals = { functionName = function( x ) _body of function_ end, } When the LuaPage is evaluated, the code for each tag is evaluated, and the result is substituted for the opening or closing named tag. For example, you could define code in this format in your tagset file: globals = { myOpenTagFunction = function( ) --body of function CHAPTER 6: Writing a Web-engine Plug-in Web SDK tagsets 139 end, myCloseTagFunction = function( ) --body of function end, } tags = { myTag = { startTag = "myOpenTagFunction()", endTag = "myCloseTagFunction()", } } If you import this tag into the xmpl namespace, your LuaPage would reference the tag like this: Helloworld At run time, when the LuaPage is evaluated, the tags are replaced with the Lua code, and the contents is simply written out: myOpenTagFunction() write( [[Helloworld]] ) myCloseTagFunction() This code is then evaluated to produce the final HTML for your web gallery page. Using custom tags To use a tagset that you have defined in your web-engine plug-in: 1. Include the tagset definition file or files in the root directory of your web engine. 2. Add a line to import the tagset in your manifest.lrweb file: importTags( "lr", "pathToTagsetFile" ) This includes all of the tags defined in the file under the namespace lr. The namespace definition prevents conflicts with tags of the same name defined in other tagset libraries. You can use any namespace for your own tags. 3. To load the built-in default tagset, substitute the special value "com.adobe.lightroom.default" for the path: importTags( "lr", "com.adobe.lightroom.default" ) By convention, the built-in tags are imported into the lr namespace. 4. To use the defined tags in your LuaPages, use the namespace prefix for both the opening and closing tag. For example: ... Custom tag example Here is an example that simply wraps some constant text around the text specified as the content of the tag: 1. Define the tag and its supporting function in the tagset file, myTags.lua: globals = { myFn = function( x ) CHAPTER 6: Writing a Web-engine Plug-in Web SDK tagsets 140 write( "You said, \"" ) x() write( "!\"" ) end, } tags = { exclaim { startTag = "myFn( function()", endTag = "end )", } } 2. Use the importTags() command in your web SDK manifest (manifest.lrweb) to import this into the "xmpl" namespace: importTags( "xmpl", "myTags.lua" ) 3. Reference the tag in a LuaPage source file: Helloworld 4. When the LuaPage file is converted into Lua code, this becomes: myFn( function() write( [[Helloworld]] ) end ) 5. When the Lua code is executed, this produces text as its HTML output: You said, "Helloworld!" Lightroom built-in tagset Lightroom includes a default set of tags, defined in the "com.adobe.lightroom.default" tagset. This tagset is typically imported into the lr: tagset namespace, but you can import it into any namespace using the importTags() command of your web SDK manifest. As for all imported tags, you must reference each opening and closing tag name with the namespace prefix. For example: ... The built-in tagset defines two groups of tags, for building thumbnail grids, and for defining navigation properties of a multi-page gallery. Thumbnail grid tags Use these tags to build a grid. This set of tags simplifies assembly of repeating units based on rows, columns, and the photo selection. You can use these tags only on pages that you specify in the manifest with AddGridPages. The ThumbnailGrid tag is a container for the other tags, which define cells within the grid. For example: CHAPTER 6: Writing a Web-engine Plug-in Web SDK tagsets 141 This defines a simple grid with only one cell, which displays a photo from the referenced file. It uses a variable, image, which is evaluated at run time as a reference to the currently selected photo. The following local variables are available in the context of the ThumbnailGrid tag: Variables available for grids cellIndex Contains the 1-based index for the current cell in the grid. row Contains the 1-based row number for the current cell. column Contains the 1-based column number for the current cell. image Contains the image proxy. This is a complex data type defined within the LuaPage environment; see “LuaPage data types” on page 137. The following grid tags are defined: Grid tags ThumbnailGrid Provides the definition of a thumbnail grid for pages in your gallery. Contains the remaining tags as children. GridPhotoCell Defines content to be repeated for each cell. Contained in a ThumbnailGrid tag; for example: GridEmptyCell Optional. Defines an empty cell in the grid. GridRowEnd Optional. Defines content to be placed at the end of each row. GridRowStart Optional. Defines content to be placed at the start of each row. Pagination tags This set of tags can be used to add page navigation buttons to your HTML pages. Predefined page-navigation buttons include one for the current page, one for direct access to other pages, and ones for the next and previous page, which can be disabled for the first and last pages. You can associate your own text or destination with each type of button. For example: <% if numGridPages > 1 then %> <% end %> The following local variables are available in the context of the Pagination tag: Variables available for pagination page link Contains the appropriate page number. • Within a CurrentPage tag, this is the current page number. • Within an OtherPages tag, this is the number of the corresponding page. Contains the URL to an appropriate page for a navigation button. For example, within a PreviousEnabled tag, the URL of the previous page. The following pagination tags are defined: Pagination tags Pagination Provides the definition of pagination properties for pages in your gallery. Contains the remaining tags as children. CurrentPage Defines an icon or text for the current page. OtherPages Defines an icon or value with which to navigate directly to other pages. PreviousEnabled Defines an icon or value with which to navigate to the previous page. PreviousDisabled Defines an icon or value for the previous-page button for the first page (the case in which there is no pervious page). NextEnabled Defines an icon or value with which to navigate to the next page. NextDisabled Defines an icon or value for the next-page button for the last page (the case in which there is no next page). Web HTML Live Update When you preview your web gallery in Lightroom, Lightroom opens a web browser which runs independently of the main application. If, during the preview, you make changes to the gallery parameters, Lightroom must communicate with the web browser in order to reflect those changes. CHAPTER 6: Writing a Web-engine Plug-in Web HTML Live Update 143 While a page from your gallery is being previewed in Lightroom, a user might change a model variable using the control panel. In order to reflect the change in the previewed page, the Lightroom browser normally needs to reload the page. Lightroom clears all cached copies of the page, tells the browser to reload, and builds new HTML and CSS files in response to the browser’s reload request. This process is time consuming, and can cause changes in color or other visually startling changes as the page loads. For a change as simple as a nudge in hue of a color slider, you might find this response unacceptably jarring. Live Update is intended to avoid browser reload, which disrupts the user experience. Live Update is a mechanism by which a web engine can intercept and prevent the reload operation, using DHTML/AJAX scripting techniques to alter the web page in place. DHTML/AJAX use JavaScript, which is executed in the context of the built-in web browser (rather than the Lua scripting environment of Lightroom in general). An HTML page in your web engine can incorporate JavaScript that uses Live Update to interact with Lightroom during a preview. This communication operates in both directions: • Lightroom sends messages to the page, making liveUpdate() JavaScript function calls into the page whenever the user alters a parameter in the gallery data model. If the call is successful, Lightroom does not request a page reload. • The page contains JavaScript that sends messages back to Lightroom in response to user events, such as a request for a text field edit, or to override a data model value. In order to enable this functionality, your plug-in must contain JavaScript implementations of the liveUpdate() functions and the event-handler callbacks. There is a sample implementation in the file live_update.js, which you can use or modify. It is part of the sample plug-ins provided with the SDK. To include the JavaScript file that implements Live Update in your pages, use a line such as this in your header.html template file: 5. We need to make this script part of the plug-in. To do this, we need to both provide the script, and tell the plug-in it’s there. • In the manifest.lrweb page, add this command: AddResources{ source="resources", destination="resources", } • Create a copy of the file live_update.js, which is part of the Lightroom SDK, and place it in the resources subfolder of the plug-in. This is a sample implementation of the update functions and callbacks needed for Live Update. Testing the plug-in 1. Save all of your changes and restart Lightroom. 2. Select some photos. 3. Go to the Web Gallery page and select the new gallery type. 4. Place the cursor over the “MySample” text that appears as the default title; you should be able to edit it. 5. Look in the Site Info section of the control panel, and try editing the title text from there. Adding a customized tagset A tagset for a web gallery is an external file containing macro-like definitions that can be loaded by your web pages; see “Web SDK tagsets” on page 138. We will create a tagset for this gallery that allows us to build up a complex string. Our tags will build up a complex string by combining random members of a list of predefined elements with some set text and with the content of the tag when it is included in a page. CHAPTER 11: Web Gallery Plug-ins: A Tutorial Example Adding a customized tagset 206 Define the tags 1. Create a file in the plug-in folder named myExampleTags.lrweb, and edit it to define this list of sayings: local sayings = { "A dish fit for the gods - Julius Caesar, Shakespeare", "Oh, that way madness lies - King Lear, Shakespeare", "A multitude of sins - James 5:20", "A knight in shining armour - The Ancient Ballad of Prince Baldwin", "Blood is thicker than water - Guy Mannering; or the astrologer, Sir Walter Scott" } 2. Add a local counter variable to keep track of which member is chosen: local randomSayingCount = 0 3. Define a function that selects one of the sayings. Make it a global variable that can be referenced from LuaPage templates: globals = { randomSaying = function () randomSayingCount = math.mod( randomSayingCount + 1, #sayings ) return sayings[ randomSayingCount ] end, } 4. Add the tag definitions: tags = { saying = { startTag = "write( 'Here is a saying: ' ) write( randomSaying() )", endTag = "write( [[And that's all.]] ) ", }, aQuote = { startTag = 'write( [[
]] )', endTag = 'write( [[
]] )', } } This defines two dynamic tags with the names saying and aQuote. The tags can be referenced from a LuaPage template using the prefix with which the tagset is imported, and the tag name in an opening and closing tag: ... The inner tag uses the global function we defined to construct some strings containing both static and dynamic text. These strings are output before and after the text content of the tag. The outer tag provides some style information for the text. Add the tagset to the gallery 5. Edit the manifest.lrweb file to include the tags defined in the new tagset definition file. Add this line: importTags( "xmpl", "myExampleTags.lrweb" ) CHAPTER 11: Web Gallery Plug-ins: A Tutorial Example Adding a customized tagset 207 This associates the prefix “xmpl” with the imported tagset, the tags can be referenced as: ... 6. Finally, we need to use the tags in one of the template pages. Edit the file large.html to add this code just before the footer: You know what they say:

....how interesting!
7. Save the plug-in and reload it, as described in “Testing the plug-in” on page 205. At the bottom of the browser, you should now see the constructed text at the bottom, which changes each time the page is displayed:

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
Linearized                      : No
XMP Toolkit                     : XMP Core 5.4.0
Marked                          : True
Copyright                       : Copyright 2012, Adobe Systems Incorporated, all rights reserved.
Producer                        : Acrobat Distiller 11.0 (Windows)
Title                           : Adobe Photoshop Lightroom SDK 4 Programmers Guide
Creator                         : Adobe Developer Technologies
Format                          : application/pdf
Description                     : Scripting Lightroom plug-ins for export services and web gallery extensions
Metadata Date                   : 2015:08:04 13:57:22-04:00
Create Date                     : 2013:05:17 11:08:31Z
Modify Date                     : 2015:08:04 13:57:22-04:00
Creator Tool                    : FrameMaker 11.0
Instance ID                     : uuid:8f302b20-82a9-4f06-813f-283a2f1ccd96
Document ID                     : uuid:37b0820d-21fb-40d7-9c70-5146198e8864
Bookmarks Page Index            : 11
Bookmarks Uuid                  : D9213387-482D-496F-9D77-E6D9DAF2A2D0
Page Count                      : 207
PDF Version                     : 1.4
Author                          : Adobe Developer Technologies
Subject                         : Scripting Lightroom plug-ins for export services and web gallery extensions
Keywords                        : Lightroom, scripting, Lua, plug-ins, export, services, web, gallery
Apple Keywords                  : Lightroom scripting  Lua plug-ins  export services web gallery
EXIF Metadata provided by EXIF.tools

Navigation menu