Adding an image to an album
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 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.
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
0
-
From the Capture One Dictionary (As reported by scriopt Debugger) I get the following listing:
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:
tell application "Capture One 12" to to tell _collection to add inside _collection variants {_image}0 -
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:
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.0 -
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)
tell application "Capture One 12"
add inside refSequenceAlbum variants selVariantsRefL
end tell
The event is this (there was no reply)
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
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.0 -
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:
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:
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?0 -
Ok, found it: my _image must be a variant, not an image... The command, after all, mention 'variants'. 0
投稿コメントは受け付けていません。
コメント
5件のコメント