Oh, I misunderstood. Well, I'm glad that you got it working.
edit: This may work better (new tracks are inserted at the end):
Code:
# check if there are enough tracks for items, create more tracks if needed
needed = int(RPR_CountTracks(0) - trackIndex + 1 - len(selItemIdL))
if needed < 0:
for tr in range(abs(needed)):
# insert new track(s) at the end
RPR_InsertTrackAtIndex(RPR_CountTracks(0), 1)