local LrDialogs = import 'LrDialogs' local LrFileUtils = import 'LrFileUtils' local LrPathUtils = import 'LrPathUtils' local LrTasks = import 'LrTasks' local LrView = import 'LrView' local LrBinding = import 'LrBinding' local LrXml= import 'LrXml' local PortraitureExportProvider = {} PortraitureExportProvider.exportPresetFields = { { key = 'usePreset', default = false }, { key = 'presetGroup', default = 'Generic Presets' }, { key = 'presetID', default = '1936028737' }, { key = 'hide', default = false }, } function PortraitureExportProvider.parseXML( xml, names ) local values = {} local node = LrXml.parseXml( xml ) local type = string.lower( node:type() ) if type == 'element' and node:childCount() == 1 then node = node:childAtIndex( 1 ) type = string.lower( node:type() ) if type == 'element' then local count = node:childCount() for i = 1,count do local subnode = node:childAtIndex( i ) local subtype = string.lower( subnode:type() ) if subtype == 'element' and subnode.name and subnode.text then local nodename = subnode:name() local j = 1 while names[j] do local name = names[j] if name == nodename then values[name] = subnode:text() end j = j + 1 end end end end end return values end function PortraitureExportProvider.parseXMLFile( path, names ) local f = io.open(path, 'r') if not f then return {} end local xml = f:read('*a') f:close() return PortraitureExportProvider.parseXML(xml, names) end function PortraitureExportProvider.startDialog( propertyTable ) end PortraitureExportProvider.presetGroups = {} PortraitureExportProvider.presets = {} function PortraitureExportProvider.sectionsForTopOfDialog( viewFactory, propertyTable ) local prefsPath if WIN_ENV then prefsPath = LrPathUtils.child(LrPathUtils.parent(LrPathUtils.getStandardFilePath('documents')), 'Application Data\\Imagenomic\\PT\\2.0\\Settings') else prefsPath = LrPathUtils.child(LrPathUtils.getStandardFilePath('home'), 'Library/Application Support/Imagenomic/PT/2.0/Settings') end local prefs = PortraitureExportProvider.parseXMLFile(LrPathUtils.child(prefsPath, 'Preferences.xml'), {'PresetLocation'}) local presetsPath = prefs['PresetLocation'] if not presetsPath or presetsPath == '' then presetsPath = prefsPath end presetGroups = { 'Generic Presets' } presets = {} table.insert(presets, { ID = '1936028737', Name = 'Default', Group = 'Generic Presets', Description = 'Default settings applied to whole image with skintones selection set to Auto' }) table.insert(presets, { ID = '1936028738', Name = 'Smoothing: Normal', Group = 'Generic Presets', Description = 'Slightly more aggressive smoothing than default settings' }) table.insert(presets, { ID = '1936028739', Name = 'Smoothing: Medium', Group = 'Generic Presets', Description = 'Slightly more aggressive than Normal' }) table.insert(presets, { ID = '1936028741', Name = 'Smoothing: High', Group = 'Generic Presets', Description = 'Slightly more aggressive than Medium' }) table.insert(presets, { ID = '1936028743', Name = 'Enhance: Glamour', Group = 'Generic Presets', Description = 'Glamour settings applied to whole image for a soft, contrasty look' }) table.insert(presets, { ID = '1936028744', Name = 'Enhance: Tones', Group = 'Generic Presets', Description = 'Tonal enhancements applied to selected skintones only' }) table.insert(presets, { ID = '1936028746', Name = 'Enhance: High Key', Group = 'Generic Presets', Description = 'Enhancements to achieve a typical high key look' }) table.insert(presets, { ID = '1936028748', Name = 'Enhance: Low Key', Group = 'Generic Presets', Description = 'Enhancements to achieve more of a typical low key look' }) for presetPath in LrFileUtils.recursiveFiles( presetsPath ) do if string.match(presetPath, '.*[.]xml') and not string.match(presetPath, '.*Preferences.xml') and not string.match(presetPath, '.*LastUsed.xml') then local preset = PortraitureExportProvider.parseXMLFile(presetPath, {'ID', 'Name', 'Group', 'Description'}) if preset.ID and preset.ID ~= '' and preset.Name then if not preset.Group or preset.Group == '' then preset.Group = 'Custom Presets' end if not preset.Description then preset.Description = '' end local groupFound = false local i = 1 while presetGroups[i] and not groupFound do if presetGroups[i] == preset.Group then groupFound = true end i = i + 1 end if not groupFound then presetGroups[i] = preset.Group end table.insert(presets, preset) end end end local groupItems = {} local i = 1 while presetGroups[i] do table.insert(groupItems, { title = presetGroups[i], value = presetGroups[i] }) i = i + 1 end return { { title = 'Imagenomic Portraiture', viewFactory:row { spacing = viewFactory:control_spacing(), viewFactory:checkbox { title = 'Use preset:', value = LrView.bind('usePreset'), }, viewFactory:popup_menu { value = LrView.bind('presetGroup'), items = groupItems, enabled = LrBinding.keyEquals( 'usePreset', true ), }, viewFactory:popup_menu { value = LrView.bind('presetID'), items = LrView.bind( { key = 'presetGroup', transform = function(value, fromTable) if not fromTable then return LrBinding.kUnsupportedDirection end local presetItems = {} local i = 1 while presets[i] do if presets[i].Group == value then table.insert(presetItems, { title = presets[i].Name, value = presets[i].ID }) end i = i + 1 end return presetItems end }), enabled = LrBinding.keyEquals( 'usePreset', true ), }, }, viewFactory:row { spacing = viewFactory:control_spacing(), viewFactory:static_text{ title = LrView.bind( { key = 'presetID', transform = function(value, fromTable) if not fromTable then return LrBinding.kUnsupportedDirection end local i = 1 while presets[i] do if presets[i].ID == value then return presets[i].Description end i = i + 1 end return '' end }), enabled = LrBinding.keyEquals( 'usePreset', true ), width_in_chars = 128, }, }, viewFactory:row { spacing = viewFactory:control_spacing(), viewFactory:checkbox { title = 'Hide Portraiture window', value = LrView.bind('hide'), }, }, } } end function PortraitureExportProvider.processRenderedPhotos( functionContext, exportContext ) local exportSession = exportContext.exportSession local listpath = os.tmpname() local listfile = io.open(listpath, 'w') local delete = true local photopath = '' local progressScope1 = exportContext:configureProgress { title='Preparing' } local photoCount = exportSession:countRenditions() if listfile then local preset = nil local usePreset = exportContext.propertyTable.usePreset if usePreset then local presetGroup = exportContext.propertyTable.presetGroup local presetID = exportContext.propertyTable.presetID if PortraitureExportProvider.presets[1] then local i = 1 local presetFound = false while presets[i] and not presetFound do if presets[i].ID == presetID then presetFound = true if presets[i].Group == presetGroup then preset = presetID end end i = i + 1 end else preset = presetID end end local hide = exportContext.propertyTable.hide if not WIN_ENV then listfile:write('Imagenomic list file\n') if preset then listfile:write('Preset=' .. preset .. '\n') end if hide then listfile:write('Hide\n') end end local stopExport = false local preparedNumber = 0 for i, rendition in exportSession:renditions{ stopIfCanceled = true, progressScope=progressScope1 } do local success, pathOrMessage = rendition:waitForRender() if success then local path1= pathOrMessage listfile:write(path1 .. '\n') preparedNumber = preparedNumber+1 else stopExport = true end end if preparedNumber