Clear Field 1.3 - Updated 26/07/2014

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Clear Field 1.3 - Updated 26/07/2014

Post by trixmoto »

As requested (via my website) this script is very simple. It clears out a single field (as specified by the user) for all the selected tracks. This field name must be the SongData property values which can be found in the scripting helpfile - these normally match the column headings.

This script is useful when clearing out a field for a large number of tracks as it works in the background.

The installers are available from my website. :)

Code: Select all

'
' MediaMonkey Script
'
' NAME: ClearField 1.3
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 26/07/2014
'
' Thanks to Steegy for the SkinnedInputBox
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' [ClearField]
' FileName=ClearField.vbs
' ProcName=ClearField
' Order=50
' DisplayName=&Clear Field 
' Description=Clear field for selected tracks
' Language=VBScript
' ScriptType=0 
'
' FIXES: Added dropdown list of fields available
'        Fixed special case for Leveling and LevelingAlbum was case sensitive
' 

Option Explicit

Sub ClearField
  'get selected tracks
  Dim list : Set list = SDB.SelectedSongList 
  If list.count = 0 Then 
    Set list = SDB.AllVisibleSongList 
  End If 
  If list.count = 0 Then
    Call SDB.MessageBox("ClearField: There are no selected tracks.",mtError,Array(mbOk))
    Exit Sub
  End If 
  
  'get field name
  Dim data : data = "text"
  Dim flds : flds = "Actors~|~AlbumArtistName~|~AlbumName~|~ArtistName~|~Author~|~Band~|~Bitrate~|~Bookmark~|~BPM"
  flds = flds&"~|~Cached~|~CachedPath~|~Channels~|~Comment~|~Conductor~|~Copyright~|~Custom1~|~Custom2~|~Custom3~|~Custom4~|~Custom5"
  flds = flds&"~|~Date~|~DateAdded~|~DateDBModified~|~Day~|~DiscNumber~|~DiscNumberStr~|~Director"
  flds = flds&"~|~Encoder~|~EpisodeNumber~|~FileLength~|~FileModified~|~GaplessBytes~|~Genre~|~Grouping~|~InvolvedPeople~|~ISRC"
  flds = flds&"~|~LastPlayed~|~Leveling~|~LevelingAlbum~|~Lyricist~|~Lyrics"
  flds = flds&"~|~MarkPlayed~|~Media~|~MediaLabel~|~Month~|~Mood~|~MusicComposer"
  flds = flds&"~|~Occasion~|~OriginalArtist~|~OriginalLyricist~|~OriginalTitle~|~OriginalYear~|~OriginalMonth~|~OriginalDay"
  flds = flds&"~|~ParentalRating~|~Path~|~PeakValue~|~PlayCounter~|~PostGap~|~PreGap~|~Preview~|~PreviewPath~|~Producer~|~Publisher"
  flds = flds&"~|~Quality~|~Rating~|~RatingString"
  flds = flds&"~|~SampleRate~|~SeasonNumber~|~Series~|~SetPathByMask~|~SkipCount~|~SongLength~|~SongLengthString~|~StartTime~|~StopTime"
  flds = flds&"~|~Tempo~|~Title~|~TotalSamples~|~TrackOrder~|~TrackOrderString~|~TrackType~|~VBR~|~Year~|~(Other)"
  Dim temp : temp = SDB.IniFile.StringValue("Scripts","ClearField")
  Dim name : name = SkinnedDropdown("Please select a field:","ClearField",flds,temp,"ClearField")
  If name = "" Or name = "(Other)" Then
    name = SkinnedInputBox("Please enter field name:","ClearField",temp,"ClearField")
  End If
  SDB.IniFile.StringValue("Scripts","ClearField") = name
  
  'check field name
  If name = "" Then
    Call SDB.MessageBox("ClearField: No field name was specified.",mtError,Array(mbOk))
    Exit Sub
  Else
    On Error Resume Next
    Execute("temp = list.Item(0)."&name)    
    If Err.Number <> 0 Then
      Err.Clear
      Call SDB.MessageBox("ClearField: Invalid field name was specified.",mtError,Array(mbOk))
      Exit Sub
    End If
    Execute("list.Item(0)."&name&" = """"")
    If Err.Number <> 0 Then
      Err.Clear
      data = "numeric"
    Else
      Execute("list.Item(0)."&name&" = temp")
    End If
    On Error Goto 0
  End If

  'create progress bar
  Dim prog : Set prog = SDB.Progress
  prog.Value = 0
  prog.MaxValue = list.Count
  prog.Text = "ClearField: Awaiting user confirmation..."
  
  'get confirmation
  Dim s : s = "ClearField: Clear "&data&" field '"&name&"' from "&list.Count&" tracks?"
  Dim i : i = SDB.MessageBox(s,mtConfirmation,Array(mbYes,mbNo))
  If Not (i = mrYes) Then
    Exit Sub
  End If
  
  'process tracks
  For i = 0 To list.Count-1
    prog.Text = "ClearField: Processing track "&(i+1)&" of "&(list.Count)&"..."
    SDB.ProcessMessages
    If data = "text" Then
      Execute("list.Item(i)."&name&" = """"")
    Else
      If (UCase(name) = "LEVELING") Or (UCase(name) = "LEVELINGALBUM") Then
        Execute("list.Item(i)."&name&" = -999999")
      Else
        Execute("list.Item(i)."&name&" = -1")
      End if
    End If
    Dim l : Set l = SDB.NewSongList
    Call l.Add(list.Item(i))
    Call l.UpdateAll()
    prog.Increase
    If prog.Terminate Then 
      Exit Sub
    End If
  Next     
End Sub

Function SkinnedInputBox(Text, Caption, Input, PositionName)
   Dim Form, Label, Edt, btnOk, btnCancel, modalResult 

   ' Create the window to be shown 
   Set Form = SDB.UI.NewForm 
   Form.Common.SetRect 100, 100, 360, 130 
   Form.BorderStyle  = 2   ' Resizable 
   Form.FormPosition = 4   ' Screen Center 
   Form.SavePositionName = PositionName 
   Form.Caption = Caption 
      
   ' Create a button that closes the window 
   Set Label = SDB.UI.NewLabel(Form) 
   Label.Caption = Text 
   Label.Common.Left = 5 
   Label.Common.Top = 10 
     
   Set Edt = SDB.UI.NewEdit(Form) 
   Edt.Common.Left = Label.Common.Left 
   Edt.Common.Top = Label.Common.Top + Label.Common.Height + 5 
   Edt.Common.Width = Form.Common.Width - 25 
   Edt.Common.ControlName = "Edit1" 
   Edt.Common.Anchors = 1+2+4 'Left+Top+Right 
   Edt.Text = Input 
       
   ' Create a button that closes the window 
   Set BtnOk = SDB.UI.NewButton(Form) 
   BtnOk.Caption = "&OK" 
   BtnOk.Common.Top = Edt.Common.Top + Edt.Common.Height + 10 
   BtnOk.Common.Hint = "OK" 
   BtnOk.Common.Anchors = 4   ' Right 
   BtnOk.UseScript = Script.ScriptPath 
   BtnOk.Default = True
   BtnOk.ModalResult = 1 
    
   Set BtnCancel = SDB.UI.NewButton(Form) 
   BtnCancel.Caption = "&Cancel" 
   BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width - 15 
   BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width - 10 
   BtnCancel.Common.Top = BtnOK.Common.Top 
   BtnCancel.Common.Hint = "Cancel" 
   BtnCancel.Common.Anchors = 4   ' Right 
   BtnCancel.UseScript = Script.ScriptPath 
   BtnCancel.Cancel = True
   BtnCancel.ModalResult = 2 
       
   If Form.showModal = 1 Then
     SkinnedInputBox = Edt.Text
   Else
     SkinnedInputBox = ""
   End If  
End Function

Function SkinnedDropdown(Text,Caption,flds,temp,PositionName)
  Dim Form, Label, Edt, btnOk, btnCancel, modalResult 

  ' Create the window to be shown 
  Set Form = SDB.UI.NewForm 
  Form.Common.SetRect 100, 100, 360, 130 
  Form.BorderStyle  = 4   ' Resizable 
  Form.FormPosition = 4   ' Screen Center 
  Form.SavePositionName = PositionName 
  Form.Caption = Caption 
      
  ' Create a button that closes the window 
  Set Label = SDB.UI.NewLabel(Form) 
  Label.Caption = Text 
  Label.Common.Left = 5 
  Label.Common.Top = 10
     
  Set Edt = SDB.UI.NewDropDown(Form) 
  Edt.Common.Left = Label.Common.Left 
  Edt.Common.Top = Label.Common.Top + Label.Common.Height + 5 
  Edt.Common.Width = Form.Common.Width - 25 
  Edt.Common.ControlName = "Edit1" 
  Edt.Common.Anchors = 1+2+4 'Left+Top+Right
  Call Edt.AddItem("Please select...")
  Edt.ItemIndex = 0
  
  Dim arr : arr = Split(flds,"~|~")  
  Dim i : i = 0
  For i = 0 To UBound(arr)
    Dim fld : fld = arr(i)
    Call Edt.AddItem(fld)
    If fld = temp Then
      Edt.ItemIndex = i+1
    End If
  Next
       
  ' Create a button that closes the window 
  Set BtnOk = SDB.UI.NewButton(Form) 
  BtnOk.Caption = "OK"
  BtnOk.Common.Top = Edt.Common.Top + Edt.Common.Height + 10 
  BtnOk.Common.Hint = "OK"
  BtnOk.Common.Anchors = 4   ' Right 
  BtnOk.UseScript = Script.ScriptPath 
  BtnOk.Default = True
  BtnOk.ModalResult = 1 
    
  Set BtnCancel = SDB.UI.NewButton(Form) 
  BtnCancel.Caption = "Cancel"
  BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width - 15 
  BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width - 10 
  BtnCancel.Common.Top = BtnOK.Common.Top 
  BtnCancel.Common.Hint = "Cancel"
  BtnCancel.Common.Anchors = 4   ' Right 
  BtnCancel.UseScript = Script.ScriptPath 
  BtnCancel.Cancel = True
  BtnCancel.ModalResult = 2 
       
  SkinnedDropdown = ""
  If Form.showModal = 1 Then
    Dim nam : nam = Edt.SelText
    If nam <> "Please select..." Then      
      SkinnedDropdown = nam
    End If
  End If  
End Function

Sub Install()
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("ClearField","Filename") = "ClearField.vbs"
    inif.StringValue("ClearField","Procname") = "ClearField"
    inif.StringValue("ClearField","Order") = "50"
    inif.StringValue("ClearField","DisplayName") = "&Clear Field"
    inif.StringValue("ClearField","Description") = "Clear field for selected tracks"
    inif.StringValue("ClearField","Language") = "VBScript"
    inif.StringValue("ClearField","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Last edited by trixmoto on Tue Nov 06, 2007 5:00 am, edited 2 times in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Vyper
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Post by Vyper »

You rock! Image
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Thanks! :D
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Post by Guest »

Thank you, Trixmoto!
Very nice script.
I'm trying it right now and it works.
May I suggest a little improvement for the next version? (Clear Field 1.1?)

Since there are a lot of SongData property values that can be used as fields and they not always match the column heading, could it be possible to redesign the input box so as to include a combo box that displays all fields (or at least the most common ones) in a list? Selecting one of them would be much easier than looking up the name of a particular field in the Scripting help file.

I hope you can make it.
Thanks
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

The reason I did not create a dropdown list was there are too many to sensibly put into a dropdown list. Also this would mean me re-releasing the script every time a field is added.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

An MM3 installation package for this script is now available from my website. :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Morten
Posts: 1092
Joined: Thu Aug 11, 2005 11:31 am
Location: Norway

Post by Morten »

Great to hear.
Best regards,
Morten
be4con
Posts: 17
Joined: Mon Nov 05, 2007 12:54 pm

Looks like exactly what I need but...

Post by be4con »

I can't seem to get this to work at all. If I enter Album as the field I get an Invalid Field Name error. I'm assuming this one is just different to the column heading and I need to look it up in the scripting help file, but I have to admit to opening that, looking slightly scared then closing it pronto :oops:

With other fields eg: the year field I get:

Error #13 - Microsoft VBScript runtime error
Type mismatch 'list.Item(...).year'
File: "C:\Program Files\Media Monkey\Scripts\ClearField.vbs", Line: 0, Column: 0

Any ideas what is going wrong here?

Thanks
nch74
Posts: 1
Joined: Tue Nov 06, 2007 12:35 am

Same Type Mismatch error !!!! PLEASE HELP

Post by nch74 »

This scipt seem so lovely...
I'm trying to remove Leveling and got the same erro message:
Error #13 - Microsoft VBScript runtime error
Type mismatch 'list.Item(...).leveling'
Please help !
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

New version (1.1) is now available from my website. Changes include...

- Fixed cannot clear numeric fields due to type mismatch errors
- Added special case for volume leveling field

@nch74 - this should fix your problems! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
be4con
Posts: 17
Joined: Mon Nov 05, 2007 12:54 pm

Post by be4con »

Wow, what a quick response! That's great I can get it to work now. Thanks.

I still can't figure out what to call some of the fields though, could you point me in the right direction of where exactly to look in the script help file? I'm lost.

Thanks
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I'm glad it's working for you. :)

In the scripting helpfile it's "Object SDBSongData > ISDBSongData Members" - any of the ones labelled "(Property)" should be valid. This hasn't been updated to include the new MM3 fields though, so I don't know what they are called if they are even accessible through scripting yet.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
be4con
Posts: 17
Joined: Mon Nov 05, 2007 12:54 pm

Post by be4con »

That's got it, thanks again!
spacefish
Posts: 1427
Joined: Mon Jan 14, 2008 7:21 am
Location: Denmark

Post by spacefish »

This script rocks. Thank you! :D
Image
MM Gold 3.0.3.1183 : Vista HP SP1 (x86) : Zen Stone (2GB)
Zekton: An original MM3 skin by Eyal.
Scripts in Use: Add/Remove PlayStat | Auto Album DJ | AutoRateAccurate | Backup
Case & Leading Zero Fixer | Classification & Genre Changer | Clean Scripts.ini | Clear
Field | Custom Report | Discogs Auto-Tag Web Search | Forget Crossfade | Invert
Selection/Select None | Last 100... | Lyricator | Lyrics to Instrumental | MonkeyRok
MusicBrainz Tagger | My Custom Nodes | Now Playing Art Node | Play History & Stats
Right Click for Reports | Right Click for Scripts | Right Click for Web | Stop After Current
WebNodes
Vyper
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Post by Vyper »

Does this clear the custom fields? If so, I must be typing the name in wrong. :(
Stop Button Freak
Post Reply