How to find all Version Sets with exactly N files?

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

How to find all Version Sets with exactly N files?

Post by David Grundy » 02 Aug 13 16:47

Is there a quick way to find all the Version Sets which have exactly N files in them, where N is 1, 2, 3, or some larger number?

(I don't think there is, so I devised an algorithm which is unfortunately slightly beyond my current knowledge of scripting. But when I was halfway through writing a question asking for help on scripting for this, it occurred to me that I might be missing something obvious. It has happened before. Hence the question ... and if the answer is "no", then I will ask for the scripting help. 8) )

... David

Hert
Posts: 5863
Joined: 13 Sep 03 7:24

Re: How to find all Version Sets with exactly N files?

Post by Hert » 02 Aug 13 16:59

David Grundy wrote:Is there a quick way to find all the Version Sets which have exactly N files in them, where N is 1, 2, 3, or some larger number?
No there's not...
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

Re: How to find all Version Sets with exactly N files?

Post by David Grundy » 02 Aug 13 17:17

To the coding experts ...
I have thought of an algorithm to count the number of Managed Versions in each set, but I don't know how to code the necessary script.
Here's the method I thought of ...

A. Before I start I need to create some labels:
  • DBManagement/VersionCount00
  • DBManagement / VersionCount01
  • DBManagement / VersionCount02
  • DBManagement / VersionCount03
  • DBManagement / VersionCount04
  • DBManagement / VersionCount05
I think that's enough; I don't mind manually looking through all version sets with at least 5 files in them. (I'm pretty sure there are only two such sets in my database.)

B. Algorithm:

1. Search for all versioned images and show them all in the CV
(My current preferred way is to search for all Version Sets, select all, then ctrl-alt-V to show all the Versions)

2. Select all files in the CV.

3. Apply the label VersionCount00 to all files. Remove all other VersionCount## labels.

4. Run through all these files, one at a time, with a script which does this:
  • If VersionCount04 is currently assigned, then unassign VersionCount04 and assign VersionCount05.
  • If VersionCount03 is currently assigned, then unassign VersionCount03 and assign VersionCount04.
  • If VersionCount02 is currently assigned, then unassign VersionCount02 and assign VersionCount03.
  • If VersionCount01 is currently assigned, then unassign VersionCount01 and assign VersionCount02.
  • If VersionCount00 is currently assigned, then unassign VersionCount00 and assign VersionCount01.
My thinking is that if this is done for each image (once per image, in any order) then I will end up with the correct VersionCount## label applied to each version set.

C. Questions

All great in theory, but unfortunately I'm a scripting novice: I don't know how to construct this script.
  • I don't know how to properly begin and end a script which is going to be run for each selected file;
  • I don't know how to check whether a label has been assigned to an image; and
  • I don't know how to unassign one label and assign another.
Any suggestions would be much appreciated!
Thanks
... David

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

Re: How to find all Version Sets with exactly N files?

Post by David Grundy » 02 Aug 13 17:52

I should add ... I'm asking for help partly because I'd like to answer the immediate question, but also because this will give me a starting point for some other scripts I'd like to be able to write.

tstoddard
Posts: 578
Joined: 07 Sep 12 12:51

Re: How to find all Version Sets with exactly N files?

Post by tstoddard » 02 Aug 13 18:54

David,

I don't know enough to create my own scripts but I've been able to look at some samples and use them on occasion. One thing I've seen is the use of a method (or function) that returns a collection of versions for the selected item. Once you have that collection, all you need to do is get its "count" property to find out how many versions are in the set.

Here's a clip from the Version Basher Script that you can download from Idimager Script Repository:

Code: Select all

     begin
        // Clear the exist temporary container class
        AVersions.Clear;

        // destroy the version stack for this main version
        Catalog.EnumVersionsForItem (AMain, AVersions);

        // remove all existing versions
        for j := 0 to AVersions.Count - 1 do
        begin
          //say (AVersions.Items[j].FileName);
          Catalog.DeleteVersionItem (AVersions.Items[j]);
        end;
It appears that in the script above, "Catalog.EnumVersionsForItem (AMain, AVersions);" populates AVersions with all versions of AMain. AVersions.count + 1 should give you the total number of versions in the set, including AMain. If I'm correct, this means that you shouldn't have to do the Ctr + Alt + V step before iterating through each selected item.

Also, from looking at other documentation, there appears also to be a function named "EnumVersionsForStack", which would return all versions inclusive so you wouldn't have to add the 1 to get the total count.

I don't know if any of this actually works in PSU since it came from old Idimager scripts but it might help to get you started or at least encourage some others to chime in with some help.
Tom Stoddard

tstoddard
Posts: 578
Joined: 07 Sep 12 12:51

Re: How to find all Version Sets with exactly N files?

Post by tstoddard » 02 Aug 13 19:27

David,

After a little more searching I found reference to a VersionCount property that every CatalogItem has. You should be able to just return that property for each item in your selection and get an integer representing the number of verions for that item. Then you just need to create your label name by concatenating the integer (padded with a zero) to "VersionCount" and assign it to the item. I have no idea how to do any of that.

I also have no idea why you would want to do this and I'm not going to ask. I'm just interested in this for the exercise of learning more about scripting.
Tom Stoddard

Hert
Posts: 5863
Joined: 13 Sep 03 7:24

Re: How to find all Version Sets with exactly N files?

Post by Hert » 02 Aug 13 21:25

You could make this a filter script. Use the property VersionCount as Tom pointed out.
There are a few filter scripts provided with he app that show how a filter script is structured...pretty straight forward
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

Re: How to find all Version Sets with exactly N files?

Post by David Grundy » 03 Aug 13 2:46

Thanks Tom and Hert
I will have a go using those pointers.

Tom, my purpose, even though you explicitly aren't asking:

Primarily, I want to understand scripts better. While I dislike repetitive manual tasks, and I tend to make mistakes, I enjoy the thinking process involved in automating a task. I'd rather spend 20 hours working out how to do something in an automated way (which is interesting and makes it easier to do similar things next time), than 10 hours doing it manually (which is boring, and if it turns out I got it slightly wrong then I have another 10 hours ahead of me ...). (I follow the same approach at work: I'm quite slow at doing one-off tasks, but if it turns out we need to tweak the basis of calculation, I can quickly make the changes.)

This comes up now because I am trying to tidy things up a bit. Example: my directories include a mess of (at my wild guess) 10,000 unmanaged versions. Some of these are unique files, some are copies of other files stored in specific directories as portfolios. A lot of these don't need to be separate copies, but I want to get the portfolio information and unique captions appropriately stored in the related copies in PSu before deleting unneeded copies. Before I start trying to deal with this, I want to make sure I have the tools in place to be able to do what needs to be done, to see what is happening and to check that everything is happening the way I expect. I expect I need partly to know what can already be done in PSu, and partly to know how to write a script to find any particular problem or to fix particular problems.

I anticipate a collection of related maintenance problems: How to efficiently find cases where something unexpected has happened in Versioning, whether through user error (likely) or some other reason. When I'm in the middle of something, and suspecting that it isn't working out the way I expected, I'd rather already know sufficient to work out how to diagnose and fix it myself, than have to post a question and wait for someone to kindly provide suggestions.

So this question about counting versions actually addresses something I want to be able to do anyway, but I thought I might also use it as a simple example to try to understand how to look at labels in a script, and how to structure a script that unassigns and assigns labels for all selected files. Apparently this question is easier than I expected so for this purpose I don't actually need the structures that I was hoping to learn. That's good and bad, from my point of view!

Expect more questions.
... David

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

Re: How to find all Version Sets with exactly N files?

Post by David Grundy » 03 Aug 13 6:33

The VersionCount property works as a component of (say) a thumbs info script. So that bit is fine.

But ...
(Hert, I would say it's NOT AT ALL obvious how this works! It's probably straight forward once you know ... but I DON"T know!)

How do I actually use a filter script? What's the sequence of steps to apply it?
I can't even work out how to use the example script "Filter on Active Selection"
Do I highlight some files in the CV, then load this script in the scripter and run it? --> Nothing happens at all
Do I try to load it in the "Macro" box of the "Filter by Macro Command" in the Filter menu? --> Nothing happens at all

??? How does this work!! ???
... David

Hert
Posts: 5863
Joined: 13 Sep 03 7:24

Re: How to find all Version Sets with exactly N files?

Post by Hert » 03 Aug 13 17:22

David,

Filter Scripts are selected in the Filter bar's FILTER button drop down. Like any filter operation, they work on the active set of thumbs.

Filter scripts must have a Filter method implemented. All your script have to do is return if the VersionCount, of the item that is passed to it, is greater than the number you need or not.

Hert
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

Re: How to find all Version Sets with exactly N files?

Post by David Grundy » 03 Aug 13 17:54

Which line?
FilterDrop.PNG
FilterDrop.PNG (174.65 KiB) Viewed 3787 times
Or ... suddenly a light dawns ... Do I have to save the script in the filterscripts folder? That would make sense. But right up until this moment that never occurred to me; I had assumed I had to paste the script into somewhere in a dialogue, something like the custom thumbs info or the filter by macro command.

Hert
Posts: 5863
Joined: 13 Sep 03 7:24

Re: How to find all Version Sets with exactly N files?

Post by Hert » 03 Aug 13 18:06

That is correct David. A filter Script are script files in that folder and they are included in the Drop Down. See the two filter scripts in the drop down screenshot that you posted?

Btw; "Filter by Macro Command" IS a filter script, as is the Filter on Active Selection. The latter works best as the base for your filter, mainly due to its simplicity, almost comparable to what you want with the VersionCount
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

Re: How to find all Version Sets with exactly N files?

Post by David Grundy » 03 Aug 13 18:21

Sorry Hert, not having much luck here.

Exactly from the Filter By Active Selection script, with just one change as marked.

Code: Select all

function Initialize: Boolean;
begin
  result := True;
end;

procedure Finalize;
begin
end;

function Filter(AItem: TImageItem): Boolean;
begin
//Comment out the code from Filter by Active Selection:
//Original Code:  result := not AItem.Marked;

//Try to use VersionCount instead - first let's just check whether =1 will work
  result := AItem.VersionCount = 1 ;
end;  
Returns this:
Syntax error
Source position 1,1(0)



Similarly when I tried less:

Code: Select all

begin
//Comment out the code from Filter by Active Selection:
//Original Code:  result := not AItem.Marked;

//Try to use VersionCount instead - first let's just check whether =1 will work
  result := AItem.VersionCount = 1 ;
end;  
I got that same message, then followed by Access Violation(0).

BTW - regarding that last error - I am running as administrator.

... David

David Grundy
Posts: 241
Joined: 13 May 07 16:40
Location: Hong Kong

Re: How to find all Version Sets with exactly N files?

Post by David Grundy » 03 Aug 13 18:32

I thought maybe the problem was that AItem is not the right sort of object so I took a punt that maybe I needed to find the catalog entry that corresponds to AItem, somehow similar to the way it's done in the thumbnail info scripts. So I borrowed that code.

Code: Select all

function Initialize: Boolean;
begin
  result := True;
end;

procedure Finalize;
begin
end;

function Filter(AItem: TImageItem): Boolean;
var
  ACatItem: TCatalogItem;
begin
  ACatItem := TCatalogItem.Create(nil);
  if Catalog.FindImageCombined (AItem, ACatItem, False, vptNone) then
  begin

    result := ACatItem.VersionCOunt = 1;
  end;
end;    
However it still fails with the same message. :( Presumably I am consistently doing something wrong in a very basic way.

Hert
Posts: 5863
Joined: 13 Sep 03 7:24

Re: How to find all Version Sets with exactly N files?

Post by Hert » 03 Aug 13 19:13

To filter out all images without versions....

Code: Select all

function Initialize: Boolean;
begin
  result := True;
end;

procedure Finalize;
begin
end;

function Filter(AItem: TImageItem): Boolean;
begin
  result := (AItem._VersionCount = 0);
end;

To filter out all images with less than 2 versions;

Code: Select all

  result := (AItem._VersionCount < 2);
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

Post Reply