Adding an image to an album

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

Adding an image to an album

Postby StoppingDown » Sat Aug 03, 2019 10:08 pm

I'm working to my second script. It imports a rather nested structure of albums from Lightroom into Capture One 12. I've been able to easily recreate the tree, but now I get an error when I try to add an image to the first album.

Code below with the description of the error in an inline comment.

Thanks.

PS I'm pretty sure that the image search can be optimised, but first I'd like to have the script working. Also, this script will be used only once: after the import will be correctly done, I'll forget Lightroom for what concerns collections, so optimal performance isn't needed.

Code: Select all
use framework "Foundation"
use scripting additions

set _collection to missing value

tell front document of application "Capture One 12"
   try
      set _baseImport to make collection with properties {kind:group, name:"__IMPORT__"}
   on error
      set _baseImport to collection named "__IMPORT__"
   end try
   
   tell collection "All Images"
      set _images to every image
      set _imageNames to the name of every image
   end tell
   
   set _srcFile to "macOs:tmp:collections.txt"
   tell application "System Events" to set _lns to paragraphs of (read file _srcFile as «class utf8»)
   
   repeat with _ln in _lns
      if _ln starts with " " then
         set _imageName to my trim(_ln)
         repeat with _i from 1 to count of _imageNames
            if item _i of _imageNames starts with _imageName then
               set _image to (item _i of _images)
               exit repeat
            end if
         end repeat

                        # AT THIS POINT I HAVE A VALID _collection WHICH IS AN album AND AND A VALID _image
                        # BUT THE CODE BELOW FAILS WITH error "Capture One 12 got an error: AppleEvent handler failed." number -10000
         tell application "Capture One 12" to add inside _collection variants {_image}
      else
                        -- code to create the album tree omitted
      end if
   end repeat
end tell
StoppingDown
 
Posts: 11
Joined: Wed Oct 01, 2014 11:02 am
Location: Genoa, Milan (Italy)

Re: Adding an image to an album

Postby Eric Nepean » Sun Aug 04, 2019 4:34 am

From the Capture One Dictionary (As reported by scriopt Debugger) I get the following listing:
Code: Select all
add inside
add inside (verb)Add one or more variants to an album collection. (from Capture One Suite)
COMMAND SYNTAX
add inside collection ¬
     variants list of variant
PARAMETERS
Parameter
Required
Type
Description
direct parameter   required   collection   An album collection to add the variants to
variants   required   list of variant   One or more variants to be added
CLASSES
The following classes respond to the add inside command:
collection

The last two lines are key. Based on this, you can't direct this commmand to the application, you have to direct it to a collection

So I think your code needs to read:
Code: Select all
tell application "Capture One 12" to to tell _collection to add inside _collection variants {_image}
Eric Nepean
 
Posts: 662
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Adding an image to an album

Postby StoppingDown » Sun Aug 04, 2019 12:58 pm

Thanks Eric, silly me.

But even with the fix I get the error (probably there's another issue).

This is what I read in the event log:

Code: Select all
tell application "Capture One 12"
   add inside collection id "8459" of collection id "8458" of collection id "8457" of collection id "8456" of collection id "8455" of document "Fabrizio's Catalog" variants {image id "19016" of collection id "2" of document "Fabrizio's Catalog"}
      --> error number -10000
Result:
error "Capture One 12 got an error: AppleEvent handler failed." number -10000


The collection ids make sense - it's a branch of four groups plus a final album, just created.
StoppingDown
 
Posts: 11
Joined: Wed Oct 01, 2014 11:02 am
Location: Genoa, Milan (Italy)

Re: Adding an image to an album

Postby Eric Nepean » Mon Aug 05, 2019 4:04 am

I think that I have given bad advice.

Your code seems to match my working code. I've seen this error 10000 recently and got round it, but I can't quite remember the details..

I checked my working code (a script that marks image sequences) , and found this (checked it just now)
Code: Select all
tell application "Capture One 12"
   add inside refSequenceAlbum variants selVariantsRefL
end tell

The event is this (there was no reply)
Code: Select all
add inside collection id "1633" of collection id "1629" of collection id "100" of document "TestStacks" variants {variant id "979" of collection id "101" of collection id "100" of document "TestStacks", variant id "980" of collection id "101" of collection id "100" of document "TestStacks", variant id "981" of collection id "101" of collection id "100" of document "TestStacks", variant id "982" of collection id "101" of collection id "100" of document "TestStacks", variant id "983" of collection id "101" of collection id "100" of document "TestStacks"}

I then created this test code, which works
Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Capture One 12"
   tell current document to set theTargetAlbum to collection "Album2" of collection "GroupA"
   tell current document to set selVariantsRefL to {variant 1} of collection "all Images"
   add inside theTargetAlbum variants selVariantsRefL
end tell

Its unclear to me what the problem with your code is.
Eric Nepean
 
Posts: 662
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Adding an image to an album

Postby StoppingDown » Mon Aug 05, 2019 4:25 pm

I suspect that the _image is not what is supposed to be, even though if it get logged as being the same.
I did a little change:

Code: Select all
tell application "Capture One 12" to set _imagesToAdd to {_image as image}
tell application "Capture One 12" to add inside _collection variants _imagesToAdd


That is, basically I forced a cast "as image" (I'm also using a temporary collection, but I suppose it doesn't matter). Now I'm getting:

Code: Select all
error "Can’t make image id \"41488\" of collection id \"188\" of collection id \"186\" of collection id \"47\" of collection id \"35\" of document \"Fabrizio's Catalog\" into type image." number -1700 from «class cimg» id "41488" of «class COcl» id "188" of «class COcl» id "186" of «class COcl» id "47" of «class COcl» id "35" of document "Fabrizio's Catalog" to «class cimg»


I don't know what «class cimg» is, but I presume - for analogy - that I should have a «class COimg», or something like that?
StoppingDown
 
Posts: 11
Joined: Wed Oct 01, 2014 11:02 am
Location: Genoa, Milan (Italy)

Re: Adding an image to an album

Postby StoppingDown » Mon Aug 05, 2019 4:45 pm

Ok, found it: my _image must be a variant, not an image... The command, after all, mention 'variants'.
StoppingDown
 
Posts: 11
Joined: Wed Oct 01, 2014 11:02 am
Location: Genoa, Milan (Italy)


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest