Yes, glad to help!
Firstly, I’d recommend using a copy of the CurrentPlaylist, like so:
var
plCurrent: IPlaylist;
…
begin
…
plCurrent := Factory.CreatePlaylist;
plCurrent.Assign(CurrentPlaylist);
…
end.
(this is Torben-recommended-and-approved ‘best practice.’ ;))
So from here on, you’re working with plCurrent where you previously used CurrentPlaylist:
var
i: integer;
plCurrent: IPlaylist;
currentItem: IPlaylistItem;
…
begin
…
plCurrent := Factory.CreatePlaylist;
plCurrent.Assign(CurrentPlaylist);
for i := 0 to plCurrent.GetCount - 1 do
begin
currentItem := plCurrent.GetItem(i);
…
end;
…
end.
And to finally get around to answering your original question :D, alphadevil: yes, things have changed. SaveMMD has been ‘promoted’ to become a method of IFilePlaylistItem, so the (again, Dr.W-approved) way—wrapped in a try/except/end block—is this:
const
SCRIPTNAME = 'WritePlaylistMMDs script: ';
…
var
i: integer;
plCurrent: IPlaylist;
currentItem: IPlaylistItem;
…
begin
…
plCurrent := Factory.CreatePlaylist;
plCurrent.Assign(CurrentPlaylist);
for i := 0 to plCurrent.GetCount - 1 do
begin
currentItem := plCurrent.GetItem(i);
try
IFilePlaylistItem(currentItem).SaveMMD;
except
SystemLog(SCRIPTNAME
+ 'ERROR trying to write item '
+ IntToStr(i + 1)
+ ' to MMD file.');
end;
end;
end.
Note that I added a bit of error logging there. Sorry about that, but it’s helpful to know. It’s also the only way to give any kind of feedback whatever to a user from your script. >shrug< Live with it. Oh, and a const for the script name: handy for error logging, so you only change it once if you rename the .mls file.
‘BUT we don’t want to give you that!’ as Chris Tarrant, host of the UK version of ‘Millionaire’ would say. It’s always a good idea when writing a script to ‘do something’ to every item in a playlist to first make sure that a) the playlist isn’t empty, and b) the playlist is NOT in AUTO mode (trust me: it prevents accidents! :D). So I would usually do that first, make what we’ve written so far into a procedure, and only run the procedure if a) and b) above check out.
Also, using GetCount in the for statement means it gets checked and one subtracted from it every time around the loop. Much better to calculate this ONCE, before and outside the loop, and set an int variable to that number to use in the for statement.
And it would also help the user to know whether everything worked properly, so let’s tally any errors and also give the user that count in a useful info. message when we shut up shop.
So the finished item would be something like this:
[code]// Write Playlist MMDs
// This script saves the Properties of all Playlist items as MMD filesPlaylist
// Written by alphdevil
// with some trivial assistance from Cad Delworth, Leith FM, Edinburgh, Scotland
const
// Name of script, used as a prefix to all SystemLog messages (default: 'WritePlaylistMMDs script: ')
// If you change this, keep a colon and space as the last two characters.
SCRIPTNAME = 'WritePlaylistMMDs script: ';
var
i, iErrorCount, iItemCount, iMax: integer;
sPlaylist: string;
plCurrent: IPlaylist;
currentItem: IPlaylistItem;
procedure ProcessCurrentPlaylist;
begin
plCurrent := Factory.CreatePlaylist;
plCurrent.Assign(CurrentPlaylist);
iErrorCount := 0;
// Remember iItemCount in the startup code down below?
// We re-use it here to set the loop limit
iMax := iItemCount - 1;
for i := 0 to iMax do
begin
currentItem := plCurrent.GetItem(i);
try
IFilePlaylistItem(currentItem).SaveMMD;
except
iErrorCount := iErrorCount + 1;
SystemLog(SCRIPTNAME
+ ‘ERROR trying to write item ’
+ IntToStr(i + 1)
+ ’ to MMD file.’);
end;
end;
end;
begin
// This is the playlist number, in case we need it for a message
sPlaylist := IntToStr(CurrentPlaybackControl.GetIndex + 1);
iItemCount := CurrentPlaylist.GetCount;
// Check that the playlist contains items
if iItemCount < 1 then
SystemLog(SCRIPTNAME
+ ‘Please put one or more items in Playlist ’
+ sPlaylist
+ ‘, then try again.’)
// Check that we are in ASSIST mode
else if CurrentPlaybackControl.GetAutomation = true then
SystemLog(SCRIPTNAME
+ ‘Please put Playlist ’
+ sPlaylist
+ ’ into ASSIST mode, then try again.’)
else
begin
ProcessCurrentPlaylist;
SystemLog(SCRIPTNAME
+ ‘Processing complete. ’
+ IntToStr(iItemCount - iErrorCount)
+ ’ items processed successfully (’
+ IntToStr(iErrorCount)
+ ’ items had errors).’);
end;
end.[/code]
Hope that helps. 8)
BFN
CAD