Skip to main content
Known Participant
May 7, 2011
Question

Writing to external files

  • May 7, 2011
  • 2 replies
  • 2157 views

Is there any documentation in addition to the standard SDK documet?

I have to challenges:

1. What LUA code do i use inside a typical "grid" to write seomthing to an external file ?

2. How can I change settings for the stahdard image files. For example, I like to output the large files with a different JPEG compression than the thumbnails.

This topic has been closed for replies.

2 replies

Known Participant
January 25, 2013

Probably a newbie question...

I tried the exampe from jarnoh above, but I get the error "Attempt to index local 'file' (a nil value).

This is my code:

local LrTasks = import 'LrTasks'

local LrApplication = import 'LrApplication'

local LrFunctionContext = import 'LrFunctionContext'

local LrProgressScope = import 'LrProgressScope'

local LrBinding = import "LrBinding"

local LrView = import "LrView"

local LrDialogs = import 'LrDialogs'

local LrPathUtils = import 'LrPathUtils'

local LrFileUtils = import 'LrFileUtils'

local LrStringUtils = import 'LrStringUtils'

local LrDate = import 'LrDate'

local catalog = import "LrApplication".activeCatalog()

function WriteExternalFile()

local file = io.open("example.txt", "w")

file:write("This is an test.")

file:close()

end

WriteExternalFile()

Inspiring
January 25, 2013

The example was not complete, as explained by Rob, the default working directory might not be writable, so opening fails and f=nil.

Try a writable directory, such as desktop:

local LrPathUtils = import "LrPathUtils"

local f = io.open(LrPathUtils.child(LrPathUtils.getStandardFilePath("desktop"), "output.txt"),"w")

f:write("something")

f:close()

Known Participant
January 25, 2013

Thank you, solved!

areohbee
Legend
May 7, 2011

There's tons of source code available as examples that write files.

Download the SDK for 2 docs: SDK guide (pdf), & API spec (html).

Look for LrFileUtils...

Source code here: Elare Framework

Rob

Known Participant
May 7, 2011

Thank you. Didn't see it in the SDK docs but will have a good look in th eother info you gave.

Inspiring
May 9, 2011

Writing to external file is standard lua, e.g.

local f = io.open("output.txt","w")

f:write("something")

f:close()

To write images, you have to use LrExportSession, which is documented in the SDK.