Mator

[Pascal] [xEdit] Get cell and worldspace child records

Aug 21st, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.54 KB | None | 0 0
  1. {
  2.   Gets all the child records in CELL and WRLD records.
  3. }
  4.  
  5. unit UserScript;
  6.  
  7. uses mteFunctions;
  8.  
  9. const
  10.   verbose = true;
  11.  
  12. procedure GetRecords(var RecordsList: TList; var g: IInterface);
  13. var
  14.   i: Integer;
  15.   e: IInterface;
  16. begin
  17.   // exit if the group/container isn't assigned
  18.   if not Assigned(g) then exit;
  19.   if ElementType(g) = etMainRecord then begin
  20.     if verbose then AddMessage('Found etMainRecord '+Name(g));
  21.     if (Signature(g) = 'CELL') or (Signature(g) = 'WRLD') then
  22.       GetRecords(RecordsList, ChildGroup(g))
  23.     else
  24.       RecordsList.Add(g);
  25.   end
  26.   else begin
  27.     if verbose then AddMessage('Processing '+IntToStr(ElementCount(g))+' child elements in '+Name(g));
  28.     for i := 0 to Pred(ElementCount(g)) do begin
  29.       e := ElementByIndex(g, i);
  30.       GetRecords(RecordsList, e);
  31.     end;
  32.   end;
  33. end;
  34.  
  35. function Initialize: Integer;
  36. var
  37.   sig: string;
  38.   f, g, e: IInterface;
  39.   RecordsList: TList;
  40.   sl: TStringList;
  41.   i: Integer;
  42. begin
  43.   RecordsList := TList.Create;
  44.   f := FileSelect('Select the file you want to get records from.');
  45.  
  46.   // get the records from WRLD and CELL groups
  47.   g := GroupBySignature(f, 'WRLD');
  48.   GetRecords(RecordsList, g);
  49.   g := GroupBySignature(f, 'CELL');
  50.   GetRecords(RecordsList, g);
  51.  
  52.   // save record names to file
  53.   sl := TStringList.Create;
  54.   for i := 0 to Pred(RecordsList.Count) do begin
  55.     e := ObjectToElement(RecordsList[i]);
  56.     sl.Add(Name(e));
  57.   end;
  58.   sl.SaveToFile('Get REFR Records.txt');
  59.  
  60.   // clean up
  61.   sl.Free;
  62.   RecordsList.Free;
  63. end;
  64.  
  65. end.
Advertisement
Add Comment
Please, Sign In to add comment