Script request: auto-generate number and add to field?

If you need help on how to use the program
Post Reply
Melmoth
Posts: 32
Joined: 2006-08-21 21:40:11

Script request: auto-generate number and add to field?

Post by Melmoth »

Now I’ve tasted blood … scripting is so great!

But there’s a new request:

Can I modify a field where I store some mixed information with that syntax:
  • “old box ID” “old number” | additional info 1 | additional info 2
and exchange it with the following values:
  • “new box ID” “new number” | rest has to be maintained
whereas the “new box ID” is a simple prefix and no problem for my scripting skills, but the “new number” has to be generated as a three digit number from 001 – end and it has to represent the position of a selection of movies sorted by their formatted title
a real line looks like that:
  • B 001 | FSK 16 | Director's Cut
and should become
  • A 127 | FSK 16 | Director's Cut
So - in short - my problem is:
  • - I want to modify (and replace) only some information of one field
    - I want to maintain the rest
    - And I want to generate a three digit number corresponding to the formatted title (so this number isn’t available in any other field) of a selection of movies (not all) and replace it with the old number
However, if anyone can give me a hint or even a solution I’d be very, very, very thankful (otherwise I have to re-number an awful bunch of movies by hand…),

Thanks in advance,

•=Melmoth=• :hihi:
antp
Site Admin
Posts: 9726
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Code: Select all

program NewScript;

uses
  StringUtils1;

var
  id: Integer;
  s, number: string;

begin
  id := id + 1;
  number := IntToStr(id);
  while length(number) < 3 do
  begin
    number := '0' + number;
  end;
  s := 'box id | ' + number + ' |' + TextAfter(GetField(fieldName), '|');
  SetField(fieldName, s);
end.
it will increase "id" for each movie, make a string with that number, add zeroes in front of it if needed (it could be done in a cleaner way than what I did, but I am not sure that the scripting engine has the required functions for that), then it creates a string with all the info, and appends to it the text that was after the first "|" in the field.
I did not test it, but it should work.
The only remaining problem is the order in which this will be processed. I am not sure that it will be possible to have the movies sorted by title.
If I am correct, movies are not sorted when a script is applied.
So if you first export the movies asking to sort them by formatted title, and then apply the script, it may keep the same order... I let you test that ;)
Melmoth
Posts: 32
Joined: 2006-08-21 21:40:11

Thanks again!!!

Post by Melmoth »

Wow, you're the >>Ineffable Master of Quick Replies<<! Thaks a lot!! :grinking:

Your forum's as good as your program! I'll give that script a try in the next few days (I'm too busy at the moment) and let you know!

Keep it up, thankfully yours, Melmoth.
Post Reply