メインコンテンツへスキップ

⚠️ Please note that this topic or post has been archived. The information contained here may no longer be accurate or up-to-date. ⚠️

Slow enumeration of images in collection

コメント

9件のコメント

  • Fabrizio Giudici (stoppingdown)
    Ok, i did it (so I changed the subject). It didn't work because it needed another "tell application ..." (which of course is in the main code, but i didn't get it must be repeated in a handler).

    My problem now is that the code executes slowly, approximately 2 images per second... Ideas?


    on createImagesXml(_collection)
    set _r to "<?xml version="1.0" encoding="UTF-8"?>" & CRLF & "<gallery>" & CRLF & " <album>" & CRLF

    tell application "Capture One 12"
    set _kind to (kind of _collection) as string
    # FIXME assert _kind is album
    tell _collection to set _images to variants
    repeat with i from 1 to length of _images
    set _image to item i of _images
    set _imageProperties to properties of _image
    set _imageName to name of _imageProperties
    set _r to _r & " <img src="" & _imageName & ".jpg"/>" & CRLF
    my trace("IMAGE: " & _imageName)
    end repeat
    end tell

    set _r to _r & " </album>" & CRLF & "</gallery>" & CRLF
    end createImagesXml
    0
  • Fabrizio Giudici (stoppingdown)
    I made the whole source available on BitBucket:

    https://bitbucket.org/fabriziogiudici/c ... pplescript
    0
  • Eric Valk
    Hi Fabrizio
    500ms per image seems unexpectedly slow side.

    Part of the explanation may be that the Apple events that communicate between processes are slow communication. I'd open up the Script Editor log history window, select Replies, and see how many events are being sent, and how many replies. It could be you have much redundant messaging.

    The secret of speeding up Applescript is to to ask for information about as many objects as possible as possible in one message. Asking Capture One for long complex records, like properties, can be slow. Processing such records can also be quite complex. I tend not ask for "properties of ..." unless I'm debugging.

    I would write your code like this:
    tell application "Capture One 12" to set _ImageNames to name of images
    set _ImageCount to count of _ImageNames
    tell application "Capture One 12" to tell current document to tell current collection to set {_albumName, _albumKind} to {(its name), ((its kind) as text)}

    An Image may have one or many Variants so in your case you need identify and count images.
    0
  • Eric Valk
    After reading your whole source, a bit more code. Runs almost instantly for me in a test collection with about 20 Images.


    tell application "Capture One 12" to set {_ImageNames, _ImageVariantRating, _ImageCaptureDate} to {(name of images), ((rating of variant) of images), (EXIF capture date of images)}
    tell application "Capture One 12" to tell current document to tell current collection to set {_albumName, _albumKind} to {(its name), ((its kind) as text)}

    set _ImageCount to count of _ImageNames
    set _ImageVariantCount to {}
    set _ImageMaxRating to {}
    repeat with theVariantRatingsL in _ImageVariantRating
    set maxRating to 0
    repeat with theRating in theVariantRatingsL
    if maxRating < (get theRating as integer) then set maxRating to (get theRating as integer)
    end repeat
    set end of _ImageMaxRating to maxRating
    set end of _ImageVariantCount to count of theVariantRatingsL
    end repeat
    0
  • Fabrizio Giudici (stoppingdown)
    Thanks! Problem fixed - now it runs in just a few seconds.

    This is the change in details (I'm just extracting image names instead of the whole thing, as you suggested):

    https://bitbucket.org/fabriziogiudici/c ... e5a9e67879
    0
  • Eric Valk
    I think you are still making one subtle error, you are getting name of variants. It’s ok now but in the long run will result in over counting the number of images, and number variants will not match the number of images.

    I recommend that you get name of images. Besides the number of items, the name of the image includes the the file extension, which is not part of the name of the variant.
    0
  • Fabrizio Giudici (stoppingdown)
    Thanks. Actually, for the way I'm working, at the moment there's no difference - I'm running the script on albums of photos to be published, and I put in them a single variant for image; furthermore what I need is the name of the image without extensions, to which I append ".jpg" because that's the way the images are exported.

    But I've added a TODO in my notes to fix it, because I could change my conventions in future. My priority is now to fix an issues with the manipulation of some XML files related to the job (this is plain Applescript, not related to Capture One).
    0
  • Eric Valk
    I'm working on something similar.

    In newer versions of OSX, a n application is required to be re-"approved" after modifying itself.
    As a consequence saving current settings and states in Globals and Properties will no longer be practical.

    System Events, in its Property list suite has a couple of comands that generate and modify PLIST ot property list files.
    There are nothing but a file containing an XML structure, and the commands are there to move records to the XML structure and read them back.


    Some comments here about XML Libraries


    I use their Script Degugger tool which is much better than Script Editor.
    0
  • Rick Allen
    I try to avoid declaring variables that start and/or end with an underscore. I dont recall the full reason (obj-C uses it) but its a good general rule.
    0

投稿コメントは受け付けていません。