Create collection from Textfile with names?

Discussion regarding all scripting related questions
Please DO NOT post to this thread anything that is not directly related to scripting of Capture One.

Create collection from Textfile with names?

Postby RobiWan » Thu Aug 23, 2018 9:57 am

Hi,

is there a way to create a collection from a textfile with list of file names (fullpath like "/Path/To/My/Image.raw"?
RobiWan
 
Posts: 392
Joined: Fri Mar 30, 2012 1:42 pm

Re: Create collection from Textfile with names?

Postby Eric Nepean » Sat Aug 25, 2018 3:40 am

Very likely possible.

The lines in the text filepoint to image files - in your view have these image files already been imported into C1, or are they yet to be imported?

How do the paths to the image files get into the text file?
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 553
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create collection from Textfile with names?

Postby RobiWan » Sun Aug 26, 2018 12:07 pm

Hi Eric,

its for Files that are already in catalog.

I do not understand what do you mean with "How do the paths to the image files get into the text file?". I know where my files are stored. My text file and C1 point to the same paths and files.
RobiWan
 
Posts: 392
Joined: Fri Mar 30, 2012 1:42 pm

Re: Create collection from Textfile with names?

Postby Eric Nepean » Sun Aug 26, 2018 4:05 pm

Hi Robert
Each data in the textfile is the path to the image, and is likely the same as a CaptureOnes images "path" property. If not identical, a small adjustment will make it so.

For example when the CO selected variant belongs to an image file on drive "SSD_ss1"
Code: Select all
tell application "Capture One 11" to get path of parent image of primary variant
--returns  "/Volumes/SSD_ss1/evSSD/Photos/2014 GX7/GX7-14_0284.RW2"
--properties "id" and "path" give the same result

As a first draft outline, the Applescript should:
  • Open the textfile in TextEdit
  • tell C1 to make a new collection with a similar name as the TextFile
  • Read the Textfile line by line
  • for each line
    • Copy the line to a variable "theSearchPath"
    • tell C1 to find image whose path is theSearchPath"
    • tell C1 to set "foundVariant" to one of the variants of the "foundImage"
    • tell C1 to add "foundVariant" into the collection

Now implement this in Applescript

"Open the textfile in TextEdit"
Code: Select all
set theTextFileAlias to choose file with prompt "Choose TextFile:" of type {"public.text"} without invisibles
tell application "TextEdit" to activate
tell application "TextEdit" to set Input_Doc_ref to open theTextFileAlias


"tell C1 to make a new collection with a similar name as the TextFile"
Code: Select all
tell application "TextEdit" to set theCollectionName to "TextList_" & (get name of Input_Doc_ref)
tell application "Capture One 11" to tell current document to set ref2ResultAlbum to make new collection with properties {kind:album, name:theCollectionName}

If you wanted to make that a little more robust (i.e. doesn't crash if the collection already exists) then you might do this:
Code: Select all
tell application "TextEdit" to set theCollectionName to "TextList_" & (get name of Input_Doc_ref)
tell application "Capture One 11" to tell current document
   if not (exists collection named theCollectionName) then
      set ref2ResultAlbum to make new collection with properties {kind:album, name:theCollectionName}
   else
      if ("album" = (kind of (get collection named theCollectionName) as text)) then
         set ref2ResultAlbum to collection named theCollectionName -- if the album already exists then use it
      else
         error ("A collection named \"" & theCollectionName & "\" already exists, and it is not an album.")
                        -- if the collection already exists but it is not an album then crash
      end if
   end if
end tell

Now create a loop which reads lines of the text file
Code: Select all
tell application "Capture One 11" to tell current document to set current collection to collection named "All Images"
tell application "TextEdit" to tell Input_Doc_ref to set paraCount to count of paragraphs of text
repeat with paracounter from 1 to paraCount
   tell application "TextEdit" to tell Input_Doc_ref to set theSearchPath to paragraph paracounter of text
   ## Put remaining code here
   ## Put remaining code here
end repeat


Now the remaining code (this goes inside the repeat loop
  • tell C1 to find image whose path is theSearchPath"
  • tell C1 to set "foundVariant" to one of the variants of the "foundImage"
  • tell C1 to add "foundVariant" into the collection
Code: Select all
tell application "Capture One 11"
   set foundImage to first image whose path is theSearchPath
   set foundIVariants to variants of foundImage
   add inside ref2ResultAlbum variants foundIVariants
end tell

When you debug all that and ensure that its working, then that last bit of code (5 lines of "remaining code") can be replaced by one line:
Code: Select all
tell application "Capture One 11" to add inside ref2ResultAlbum variants (get variants of (get first image whose path is theSearchPath))
Last edited by Eric Nepean on Sun Aug 26, 2018 4:37 pm, edited 1 time in total.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 553
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create collection from Textfile with names?

Postby Eric Nepean » Sun Aug 26, 2018 4:34 pm

Hi Robert

Further to the previous message and your comments, I wonder what your process is, and how much work it is, to enter the path information into that text file.

If it's considerable work, then perhaps that step could be bypassed altogether, potentially the AppleScript could be simpler or even eliminated.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 553
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create collection from Textfile with names?

Postby RobiWan » Sun Aug 26, 2018 9:42 pm

Hi Eric,

thank you very much. I will test it

Now my workflow or why I need it. My proffered system is Windows but C1 is with large catalog on windows not usable. So I switched to Photo Supreme as my DAM System. But I hope Phase One will fix the bugs in the future so I can use C1 as RAW Editor and DAM System.

For now I will only read changed Metadata for selected files. I can change some Metadata in Photo Supreme and with Pascal Script (witch is Photo Supreme scripting language) I can put all selected files with path into textfile and import changed Metadta only for this selected files.
RobiWan
 
Posts: 392
Joined: Fri Mar 30, 2012 1:42 pm

Re: Create collection from Textfile with names?

Postby RobiWan » Mon Aug 27, 2018 8:17 pm

Eric Nepean wrote:Now create a loop which reads lines of the text file
Code: Select all
tell application "Capture One 11" to tell current document to set current collection to collection named "All Images"
tell application "TextEdit" to tell Input_Doc_ref to set paraCount to count of paragraphs of text
repeat with paracounter from 1 to paraCount
   tell application "TextEdit" to tell Input_Doc_ref to set theSearchPath to paragraph paracounter of text
   ## Put remaining code here
   ## Put remaining code here
end repeat



This part won't work

Code: Select all
error "„TextEdit“ hat einen Fehler erhalten: „every paragraph of text“ kann nicht gelesen werden." number -1728 from every paragraph of text


This is my example textfile
Code: Select all
/Volumes/DSLR/DSLR/ExtHDD 2503/EOS5DMKIII/RAW/2013/06/13/_z2a5452.cr2
RobiWan
 
Posts: 392
Joined: Fri Mar 30, 2012 1:42 pm

Re: Create collection from Textfile with names?

Postby rapdigital » Mon Aug 27, 2018 9:32 pm

Have you tried this. Select the all images collection and then paste the list into the select by filename list which is under the edit menu. From there you could make a new collection.
rapdigital
Certified Professional
Certified Professional
 
Posts: 177
Joined: Mon Feb 02, 2009 1:52 pm

Re: Create collection from Textfile with names?

Postby Eric Nepean » Mon Aug 27, 2018 10:17 pm

IHi Robert

Try changing from this
Code: Select all
tell application "TextEdit" to tell Input_Doc_ref to set paraCount to count of paragraphs of text

to this (i.e. deleteing "of text")
Code: Select all
tell application "TextEdit" to tell Input_Doc_ref to set paraCount to count of paragraphs


Also, this line should be changed in the same way:
Code: Select all
tell application "TextEdit" to tell Input_Doc_ref to set theSearchPath to paragraph paracounter of text

to:
Code: Select all
tell application "TextEdit" to tell Input_Doc_ref to set theSearchPath to paragraph paracounter

This worked for me; I think the Applescript dictionary for TextEdit is a little wrong.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 553
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create collection from Textfile with names?

Postby Eric Nepean » Mon Aug 27, 2018 11:55 pm

I'm going to be away for a few days so here is a debugged and optimised version. The success path is tested and working.

Code: Select all
use AppleScript version "2.5"
use scripting additions

set theTextFileAlias to choose file with prompt "Choose TextFile:" of type {"public.text"} without invisibles
tell application "TextEdit" to activate
tell application "TextEdit" to set Input_Doc_ref to open theTextFileAlias

tell application "TextEdit" to set theCollectionName to "TextList_" & (get name of Input_Doc_ref)
tell application "Capture One 11" to tell current document
   if not (exists collection named theCollectionName) then
      set ref2ResultAlbum to make new collection with properties {kind:album, name:theCollectionName}
   else
      if ("album" = (kind of (get collection named theCollectionName) as text)) then
         set ref2ResultAlbum to collection named theCollectionName -- if the album already exists then use it
      else
         error ("A collection named \"" & theCollectionName & "\" already exists, and it is not an album.")
         -- if the collection already exists but it is not an album then crash
      end if
   end if
end tell

tell application "Capture One 11" to tell current document to set current collection to collection named "All Images"
tell application "TextEdit" to tell Input_Doc_ref
   set paraList to every paragraph
end tell

repeat with thisPara in paraList
   set theSearchPath to get removeLeadingTrailingSpaces(removeTrailingCRLF(thisPara)) as text -- editted (1)
   try -- gracefully handles the case where the image cannot be found
      tell application "Capture One 11" to ¬
         add inside ref2ResultAlbum variants (get variants of (get first image whose path is theSearchPath))
   on error errormess
      log errormess
   end try
end repeat

on removeLeadingTrailingSpaces(theString)
   ## Public Domain, modified
   repeat while theString begins with space
      -- When the string is only 1 character long, then it is exactly 1 space, and the next operation willl crash. So return ""
      if 1 ≥ (count of theString) then return ""
      set theString to text 2 thru -1 of theString
   end repeat
   repeat while theString ends with space
      set theString to text 1 thru -2 of theString
   end repeat
   return theString
end removeLeadingTrailingSpaces

on removeTrailingCRLF(theText) -- editted (2)
   set crlfChar to {return, linefeed, character id 8233, character id 8232, " ", tab, character id 0}
   repeat while crlfChar contains the last character of theText
      if (1 = (count of theText)) then
         set theText to ""
         exit repeat
      else
         set theText to (get text 1 thru -2 of theText) as text
      end if
   end repeat
   return theText
end removeTrailingCRLF


** Editted Twice
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 553
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create collection from Textfile with names?

Postby RobiWan » Thu Aug 30, 2018 5:35 pm

Many Thanks Eric :top:

It works perfect, unfortunately my catalog I converted from Windows to OSX is very, very slow if I try search anything and Phase One can not or will not make it usable - I have a ticket with last entry 3 weeks ago "my colleague is showing what he can do" :(
RobiWan
 
Posts: 392
Joined: Fri Mar 30, 2012 1:42 pm

Re: Create collection from Textfile with names?

Postby Eric Nepean » Fri Aug 31, 2018 2:51 am

I know that they are having issues with Catalogs converted from Windows to OSX.

I wonder if creating a blank catalog, and importing the converted Windows catalog into it, will result in a more useable catalog. The catalog structure is hopefully completely completely re-written when that is done.

Another trick is to remove the "Filter Tool" from the Library tab.

Filter tool consumes a lot of CPU if there are IPTC tags which are unique for every image, e.g. a date or an original file name, and there are 10s of 1000's of images.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 553
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create collection from Textfile with names?

Postby RobiWan » Fri Aug 31, 2018 9:01 am

Eric Nepean wrote:I know that they are having issues with Catalogs converted from Windows to OSX.

I wonder if creating a blank catalog, and importing the converted Windows catalog into it, will result in a more useable catalog. The catalog structure is hopefully completely completely re-written when that is done.


I have tried several things - last time I have removed all previews and all metadata from catalog. Speed was OK but without metadata is this no wonder. Then ca. 14 days long created all previews and imported Metadata from xmp files. If I select something from filter tool I have to wait some minutes for result - beach ball :(

I don't believe in it anymore but with version 12 I will give C1 a chance for the last time. Then I will finally switch to ON1 Photo RAW as RAW editor.
RobiWan
 
Posts: 392
Joined: Fri Mar 30, 2012 1:42 pm

Re: Create collection from Textfile with names?

Postby Eric Nepean » Fri Aug 31, 2018 3:55 pm

Filter Tool is the issue then.

There is a reason Filter Tool is not in any other imaging product - it is very hard to do efficiently. The equivalent to Filter Tool is not in Aperture, not in ON1, not in XNview, I think it is not in Light Room nor in Media Pro.

Since the action of Filter Tool can be controlled, the logic of switching to another application to avoid Filter Tool delays is not clear.

If it is on the active Tool Tab (i.e. visible), Filter Tool makes a sorted list of all unique values of every Metadata field.

Consider that you have a folder with 10,000 images --- the browser sees 10,000 images.

Consider that just one IPTC data field has a unique string for most of these images. Perhaps the original file name is copied to the IPTC Title.

Referring to this one IPTC data field:
Start by assuming that the IPTC data of the first image is unique.
The IPTC data of the second image must be compared to the first IPTC data ==> 1 string comparison
The IPTC data of the third image must be compared to the first 2 IPTC data ==> 2 string comparisons
The IPTC data of the fourth image must be compared to the first 3 IPTC data ==> 3 string comparisons
...................
The IPTC data of the last image must be compared to the first 9999 IPTC data ==> 9999 string comparisons

Total: 49,995,000 string comparsions. The number of string comparisons is: 0.5*(number of images)^2
Perhaps CaptureOne uses more efficient sorting algorithms - but the theoretical limit is approximately n*log(n) or 40,000 string comparisons for 10,000 images.

If you have several problem IPTC Data fields the delay will be very long indeed.

To avoid the delay of Filter Tool I remove it from the "Library" Tab, and make a custom tab for it named "Filter Tool". I only activate this tool tab in smaller collections, not the "All Images" Collection of large catalogs.

In the large collections, I use the "Advanced Search" tool, which is much faster and has more flexibility.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 553
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Create collection from Textfile with names?

Postby rapdigital » Sat Sep 01, 2018 6:58 am

Eric you could also

Code: Select all
open for access file


So that you dont need to be flicking between text editor
rapdigital
Certified Professional
Certified Professional
 
Posts: 177
Joined: Mon Feb 02, 2009 1:52 pm

Next

Return to Scripting



Who is online

Users browsing this forum: No registered users and 0 guests