How to find all Version Sets with exactly N files?

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 » 04 Aug 13 2:51

Thanks Hert.

A. Code structure
I see some sort of magic underscore :) in the code. It would never have occurred to me that I needed an underscore leading the VersionCount property name, since ACatItem.VersionCount (without the underscore) works in a custom thumbs script. Could you explain a bit as to why the underscore is needed in one place and not the other?

B. Continuing errors

Much to my surprise I'm still getting the same error message even with your code.

What I did to create the script:
  1. Open the scripter
  2. Delete everything in the scripter window
  3. Paste your text into the scripter
  4. Save as Filter VersionCount eq 1 Hert.psc
What I did to run it:
  1. Working in the CV
  2. Click on the Filter Button to enable the filter bar
  3. Click on the Filter Dropdown
  4. Select the line Filter VersionCount eq 1 Hert.psc
What happens:
FilterFail.PNG
FilterFail.PNG (116.94 KiB) Viewed 2040 times
What happens next:
  1. No filtering happens.
  2. Also, then I can't clear the tickmark next to the script selection in the Filter dropdown. If I click on Reset Filter at the bottom of the drop list, the tickmark is not cleared. In order to clear it I have to disable the filter bar, then reenable it.
Code comparison:

Code that works as expected (Filter Active Selection Orig.psc) to filter active selection:

Code: Select all

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

procedure Finalize;
begin
end;

function Filter(AItem: TImageItem): Boolean;
begin
  result := not AItem.Marked;
end;
Code that doesn't work at all (Filter VersionCount eq 1 Hert.psc), and produces an error message:

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;
... David

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

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

Post by Hert » 04 Aug 13 6:18

Are you sure that you saved your file as a plain ASCII file? If you think it is, then attach our file here

The underscore is typically used to define properties that are "temporary". The AItem passed to the method is a TImageItem and not a TCatalogItem. A TImageItem is not database related while a TCatalogItem is derived directly from the catalog database.
Officially you should do the extra lookup in the database to retrieve the Tcatalogitem for that TImageItem but that will slow down, while the required info (version count) is also cached in the _VersionCount of a TImageItem, but nog when that TImageItem is directly derived from the database.
Underscore properties/variables typically indicate "DO NOT USE, UNLESS YOU KNOW WHAT YOU'RE DOING". In this case I know that the cache property _VersionCount will always contain the correct value in this context of the application. I should have recommended you to do the slow database lookup, but using the cached var is there for performance reasons so why not use it here...
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 » 04 Aug 13 7:35

Thanks Hert, I appreciate the quick explanation of the underscore.
(I had previously noted some underscores in old IDI scripts, and previously thought the underscore vs no underscore was somehow a change made in going from IDI to PSu. Now I think I understand better. I would put myself in the class of "DO NOT KNOW WHAT I AM DOING" so thanks for the advice! ;))

When I saved the script files I saved using the scripter's save functions.

Now in my tests I find:
If I save the script from the PSu scripter, the resulting script doesn't work.

If I save the script from WordPad, the resulting script does work.
Filter VersionCount gt 0 WordPadSaved.psc
(194 Bytes) Downloaded 61 times
If I load the working script (the file attached above) in Scripter, and save it without any changes to a file with a new name, the resulting script (attached below) does not work.
Filter VersionCount gt 0 ScripterSaved.psc
(394 Bytes) Downloaded 66 times
Finally, I note that the specification in the filter seems to be the opposite of what I expected: that is, it appears that a "True" value leads to the file being excluded from the results rather than included. That's fine, just something to be aware of.

... David

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

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

Post by Hert » 04 Aug 13 8:51

Thank you David. That was a bug. Scripts saved from the Scripter were saved in UNICODE format, but they should be saved in ASCII format. That's already fixed for the next update, so no need to log a ticket anymore.
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 » 04 Aug 13 9:39

Thanks Hert. In the meantime I'll save any script files via a text editor.
The discussion in this thread has been very useful to me. Experiments will continue (*) and will no doubt result in more questions, but this one now seems to be answered.
... David

(*) ... but for the rest of today I should catch up on work.

PS I guess that finding this bug now probably means that there are not many user-generated scripts floating around until now.

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

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

Post by Hert » 04 Aug 13 9:57

PS I guess that finding this bug now probably means that there are not many user-generated scripts floating around until now.
This only happens with FilterScripts, and afaik nobody creates FilterScripts. Normal Scripts are loaded in the Scripter there this is no issue.
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 » 04 Aug 13 9:59

OK, that makes sense.

Post Reply