Mator

[xEdit] [Pascal] Multiple Element Value Replacement

Jul 14th, 2015
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.24 KB | None | 0 0
  1. {
  2.   Sample using ElementsByMIP to find and replace values on records.
  3. }
  4. unit userscript;
  5.  
  6. uses mteFunctions;
  7.  
  8. var
  9.   path, find, replace: string;
  10.  
  11. function Initialize: integer;
  12. begin
  13.   path := InputBox('Path', 'Enter a path to search on:', '');
  14.   find := InputBox('Find', 'Enter a value to search for:', '');
  15.   replace := InputBox('Replace', 'Enter a value to replace found values with:', '');
  16.   AddMessage('Searching "'+path+'".  Replacing "'+find+'" with "'+replace+'"');
  17. end;
  18.  
  19. function Process(e: IInterface): integer;
  20. var
  21.   lst: TList;
  22.   sl: TStringList;
  23.   i: integer;
  24.   val: string;
  25.   element: IInterface;
  26. begin
  27.   AddMessage('Processing '+Name(e));
  28.   // create lists
  29.   lst := TList.Create;
  30.   sl := TStringList.Create;
  31.  
  32.   // get elements and values
  33.   ElementsByMIP(lst, e, path);
  34.   mgeev(sl, lst);
  35.  
  36.   // replace values matching find
  37.   for i := 0 to Pred(sl.Count) do begin
  38.     element := ObjectToElement(lst[i]);
  39.     if Assigned(element) then begin
  40.       AddMessage('  "'+IndexedPath(element)+'" = '+sl[i]);
  41.       if sl[i] = find then begin
  42.         AddMessage('    Replacing value with '+replace);
  43.         SetEditValue(element, replace);
  44.       end;
  45.     end;
  46.   end;
  47.  
  48.   // free memory
  49.   lst.Free;
  50.   sl.Free;
  51. end;
  52.  
  53. end.
Advertisement
Add Comment
Please, Sign In to add comment