# How difficult is it to write a plug-in?



## PhilBurton (Dec 26, 2015)

Aside from the official Adobe documentation, what resources are available to learn how to write and test plug-ins?  Anyone on this forum write plug-ins?  I know Adobe uses a relatively unknown scripting language called LUA.

If it matters, I am not a software developer by profession, but as a student and young professional, I wrote a lot of software for civil engineering applications, using Fortran :bluegrin: and PL/1, :bluegrin: :bluegrin:  so I understand how code works.

Phil


----------



## Tony Jay (Dec 26, 2015)

John Beardsworth is your go-to on this forum for plug-in's.
Adobe does publish a software development kit for Lightroom.
Lua is not unknown but it certainly has it's quirks.
A good knowledge of SQL is also required.

Basically, if you are prepared to learn Lua properly, study the SDK, and have a worthwhile idea that can be translated into a plug-in then it is a doable proposition.

Tony Jay


----------



## Hal P Anderson (Dec 26, 2015)

There's an Adobe forum for Lightroom plugins. Some of the threads talk about coding them. 

https://forums.adobe.com/community/labs/lightroomplugins/

Also see here for a LUA tutorial: http://lua-users.org/wiki/LuaTutorial


----------



## johnbeardy (Dec 27, 2015)

My experience was in less-hardcore languages like VB, PHP, JS, Flash Action Script, and for a long time I found Lua quite a struggle. So I put a lot of effort into learning it.

The problem is that this "relatively unknown scripting language called LUA" is indeed pretty obscure:

a) you don't get the wealth of learning material and range of examples that you get with other languages

b) documentation is limited to:
- Lua's own material which is very geeky
- Adobe's SDK documentation which is geared to trained programmers

c) Adobe don't provide a coding tool which would allow you to run and debug code, and while some Lua IDEs are available they too are oriented to trained programmers

I would start by reverse engineering the sample plugins in Adobe's SDK, then focussing on creating the plugin for your specific need and using that objective to concentrate your learning process.

You do not need any knowledge of SQL since plugins cannot access SQL directly - in fact, the active catalogue's SQLite database won't allow it. While you can dig around the SQL with a 3rd party tool, knowing the table structure won't help you much as it's not particularly relational and relies on lots of text fields containing unparsed blocks of text and Lua data. In fact, I had a lot of experience of SQL and stored procedures, so my first reaction to Lua was to give up and try to achieve my objectives by SQL. I found that a dead end.

It's important to add that it need not have been this way. Other Adobe  apps are automated by a mix of VB/AppleScript/JS, sometimes all three,  so you can bring existing skills to the party and have a wealth of  learning and sample material. Other apps such as iMatch included a  built-in VB environment, while Microsoft Office apps all have one. On the other hand, Lua has allowed plugin code  to be cross platform and has probably been an efficient (ie cheap) way for Adobe to  extend some automation capability in Lightroom.

Hope this helps. If I can do it....

John


----------



## PhilBurton (Dec 28, 2015)

John,

Thank you.  Are you a professional programmer?  I'm certainly not, but at least I recognize those various languages you mention and I know what an IDE is.  I also know "just a bit" of SQL, enough to know that I don't want to ever have to work directly with an SQL database.

Phil


----------



## johnbeardy (Dec 28, 2015)

Phil

No, I'm not a professional programmer. My professional qualification is equivalent to your CPA and 20 years ago I started writing Excel macros and found I had some aptitude. But I only use "consumer" languages like those I mentioned, not real programming like C+. For the reasons I mentioned before, learning to write plugins struck me as more like the latter, and for a long time I found it very frustrating indeed.

Maybe look at this script? Apart from showing you the syntax, it shows you can automate some tasks without creating complete plugins.

John


----------



## PhilBurton (Dec 29, 2015)

johnbeardy said:


> Phil
> 
> No, I'm not a professional programmer. My professional qualification is equivalent to your CPA and 20 years ago I started writing Excel macros and found I had some aptitude. But I only use "consumer" languages like those I mentioned, not real programming like C+. For the reasons I mentioned before, learning to write plugins struck me as more like the latter, and for a long time I found it very frustrating indeed.
> 
> ...



John,

WHEN I did programming, _mumble-mumble  _years ago, I did the equivalent of C or C++, but only for my use in university or my engineering company.  

I looked at your script, and there seems to be some level of complexity there.  

It would seem that one must learn Lua and also the data structures used in Lightroom. Is it reasonable (perhaps in the future, not now) to continue this discussion of programming in Lua in this group, or is that better discussed in a different venue?  Moderators?

Phil


----------



## johnbeardy (Dec 29, 2015)

PhilBurton said:


> John,
> It would seem that one must learn Lua and also the data structures used in Lightroom. Is it reasonable (perhaps in the future, not now) to continue this discussion of programming in Lua in this group, or is that better discussed in a different venue?  Moderators?
> Phil



I don't think the group is the problem, Phil, as it is called Extending Lightroom. The problem is that unless I am mistaken, there's only me who has spent much time on this topic. The alternative, Adobe's SDK forum, is pretty quiet and its main participant disappeared a year ago.

One has to learn Lua, but I don't mean Lua in general. Instead, I think of the process as looking at what Adobe's SDK allows you to automate and how it exposes data, then learn the Lua needed to work with it. So I'd suggest you need to do a bit of reverse engineering with that script and with some of the sample plugins in the SDK. 

But that may just reflect how I learn how to program when faced with documentation that looks like it must be way over my head!

John


----------



## happycranker (Dec 30, 2015)

Hmmm all very interesting thank you John and Phil for the Lua discussion, I had looked at this myself as an ex SQL programmer, I now thinking again as the structure looks completely different to a relational db, which I am use to?


----------



## PhilBurton (Dec 30, 2015)

johnbeardy said:


> I don't think the group is the problem, Phil, as it is called Extending Lightroom. The problem is that unless I am mistaken, there's only me who has spent much time on this topic. The alternative, Adobe's SDK forum, is pretty quiet and its main participant disappeared a year ago.
> 
> One has to learn Lua, but I don't mean Lua in general. Instead, I think of the process as looking at what Adobe's SDK allows you to automate and how it exposes data, then learn the Lua needed to work with it. So I'd suggest you need to do a bit of reverse engineering with that script and with some of the sample plugins in the SDK.
> 
> ...



John,

The reason I asked is that I don't want to hijack a group just because I *may *decide to write a plug-in or two.  However, happycranker's response indicates that there may be other people on this forum who might be interested.

I guess I just have to carve out some quality time to study the Adobe SDK.  Of course, first I need to get much deeper into Lightroom so that I know if I even need to write any plug-ins. From what I can tell so far, my needs around metadata are not fully addressed with stock Lightroom.  I'll have to explore some of the available plug-ins to see if any meet my needs or if I can modify them to meet my needs.

Phil Burton


----------



## wirrah (Dec 30, 2015)

I have written several plugins to suit the searching/editing/access of metadata I want to do. Like suggested above, I grabbed an example and worked with that to learn Lua and the objects Lightroom presents. Even though I am a software developer by trade I always start with an example to familiarise myself with a new coding environment.

John's "path to keyword" script was helpful as, before looking at it, I had not been familiar with Lua "captures". Now I've removed several loops in some of my own code. And that's a good example of learning from functioning code to get started rather than just dive into the documentation.


----------



## johnbeardy (Dec 30, 2015)

wirrah said:


> I have written several plugins to suit the searching/editing/access of metadata I want to do.
> John's "path to keyword" script was helpful as, before looking at it, I had not been familiar with Lua "captures".



Funnily enough, as a self-taught programmer I don't even know what "Lua 'captures' " are!

John


----------



## johnbeardy (Dec 30, 2015)

PhilBurton said:


> From what I can tell so far, my needs around metadata are not fully addressed with stock Lightroom.  I'll have to explore some of the available plug-ins to see if any meet my needs or if I can modify them to meet my needs.



Look at my BigNote plugin, Phil. 

John


----------



## wirrah (Dec 30, 2015)

johnbeardy said:


> Funnily enough, as a self-taught programmer I don't even know what "Lua 'captures' " are!
> 
> John



Neither did I until I saw

 local fpat = "(.-)" .. pat
...
 local s, e, cap = str:find(fpat, 1)


----------



## PhilBurton (Dec 30, 2015)

johnbeardy said:


> Look at my BigNote plugin, Phil.
> 
> John



John,

Almost there. But for the fact that, quoting from the BigNote web page:

_*Any information entered in the Big Note field is stored in the Lightroom  catalogue. It is never written to the images’ XMP files and is not  included in files exported from LR. That’s because Lightroom doesn’t yet  permit a plug-in to use its XMP-writing engine,*

_This restriction is a major, major bummer for me.  Since custom metadata is important for me, that I can share with others, this statement confirms that I will need to use another application for cataloging, probably Photo Supreme (was IDImager).  The UI is not exactly great, and the documentation is sparse, but it has very powerful metadata management, including custom metadata.  If/when/ever Adobe allows access to the XMP-writing engine, then I could live my photo life entirely inside Lightroom and its plugins.

Phil


----------



## PhilBurton (Dec 30, 2015)

Tony Jay said:


> John Beardsworth is your go-to on this forum for plug-in's.
> Adobe does publish a software development kit for Lightroom.
> Lua is not unknown but it certainly has it's quirks.
> A good knowledge of SQL is also required.
> ...



John and Jay,

I have been downloading plugins for eventual use in LR, but I also looked at the text files that are part of every plugin.  Mostly I found files with Lua code, but at least one plugin had text files with a *.pl file type, probably meaning perl script.  (another language I don't know.)  I just tried to find that plugin on my system, but I can't right now.  I thought that Lua was the only supported language for plugins.  Not that I'm looking to make this situation more complicated than it is already.

Phil


----------



## johnbeardy (Dec 31, 2015)

PhilBurton said:


> Mostly I found files with Lua code, but at least one plugin had text files with a *.pl file type, probably meaning perl script.  (another language I don't know.)  I just tried to find that plugin on my system, but I can't right now.  I thought that Lua was the only supported language for plugins.



Correct. But a Lua script can send commands to the shell and maybe to Perl or Python (never used them). IIRC Adobe's own Aperture import plugin uses .pl files.



PhilBurton said:


> Almost there. But for the fact that, quoting from the BigNote web page:
> _Any information entered in the Big Note field is stored in  the Lightroom  catalogue. It is never written to the images’ XMP files  and is not  included in files exported from LR. That’s because Lightroom  doesn’t yet  permit a plug-in to use its XMP-writing engine,
> _



One can make Exiftools write directly to files or xmp sidecars by sending command line instructions from Lua. As well as my Capture Time to Exif which does this, I actually have a plugin called jbMetadata which defines a number of custom fields and uses Exiftools to read and write to my own xmp namespace. Don't go Googling for it though! While I believe the plugin is reliable and find it useful for my DAM, I consider it too risky to make it available and I've only implemented it in consulting jobs.

Extensis Portfolio had excellent support for custom metadata, allowing you to add custom fields and point them to your own xmp namespace and field names. Bridge allows it too, if you can figure out the method to create your own custom panels and are prepared for Adobe changing that method every other version. Other apps (eg Aperture, MediaPro standalone) tend to offer them in the UI but then don't make the data available to xmp and thence to other apps, and I really don't expect custom fields to become more widely available. As you can see with the people fields, where Adobe chose to use keywords rather than the IPTC extension's Person Shown, Adobe expect people will just use keywords for everything.....

John


----------



## PhilBurton (Jan 3, 2016)

johnbeardy said:


> Correct. But a Lua script can send commands to the shell and maybe to Perl or Python (never used them). IIRC Adobe's own Aperture import plugin uses .pl files.
> 
> 
> 
> ...



John,

I appreciate your replies.  For me, the issue is that the Lightroom catalog doesn't support custom metadata, which is important for me, and why I need to use another program for that purpose and that purpose alone.  Having to maintain two catalogs in sync does create some operational issues.

It's ironic that Adobe "expects people will just use keywords for everything."  Adobe created XMP.  I suspect that when Gunar Penakis left Adobe, that was the end of Adobe's interest in custom metadata.  Sad.

One final question about Lua, if you don't mind, actually two.  If I open a Lua module in Notepad, I don't see any line breaks.  I need to open that file in Microsoft Word to see line breaks.  Is that because Lua follows the UNIX newline convention rather than the DOS/Windows convention?  Also, most of the Lua modules I've looked at clearly contain non-ASCII text, unlike other scripting languages I've looked at.  Is Lua compiled?

Thanks,

Phil


----------



## johnbeardy (Jan 3, 2016)

Phil

Lua files can be either in text or compiled (using Luac). I would use something other than Notepad (word wrap setting?) as you'll get some syntax highlighting. My preference is Adobe's own ExtendScript Toolkit which should be installed with Photoshop and Bridge. I don't understand line endings from a technical viewpoint but I have had trouble in the past, and all I know is that in ESTK's prefs I've set Windows line endings and never to write a UTF8 signature.

Yes, Gunar was far-sighted in pushing xmp but I don't think Adobe is particularly unusual in not taking custom metadata as far as it could go!

John


----------



## javari (Dec 2, 2017)

Hello, I would like to be able to export stacks of images as layers to Photoshop, perform an action to the layers and re-import the result to Lightroom.
Would something like that be possible by writing a plugin? And if so, would that be possible for someone with no experience in programming?

Thanks in advance.


----------



## PhilBurton (Aug 6, 2020)

I just found this old thread, which I started over four years ago. 

Are there any other people here who might be interested in learning Lua and writing plug-ins?  Maybe we could organize some group "study sessions" or something similar using Zoom?  (As though most of us aren't already "zoomed out."


----------

