Jump to content

Automation Tools for TES5Edit - Suggestions Thread


matortheeternal

Recommended Posts

  • Replies 446
  • Created
  • Last Reply

Top Posters In This Topic

A little offtopic.

What is IwbMainRecord and IwbContainer?

 

Internal TES5Edit designation for types of elements. IwbMainRecord is an element that is a record. IwbContainer is an element that can contain other elements.

 

Edit: I could be wrong about IwbContainer. I think it may go from element -> record -> group -> file.

Edited by matortheeternal
Link to comment
Share on other sites

Mator,

 

I got 2 small questions regarding that small .pas script I've made. I am hoping you would be able to help, as I searched a lot but I cannot find the answer, and I do not know who else to ask. If the solution is long and complicated, then I don't want to waste your time. I just hope it is a couple of lines I can add or fix :tongue:

 

Here is the full script:

 

 

 
{
Print FULL NAME records of selection.
 
Hotkey: Ctrl+P
}
 
Unit Userscript;
 
var
  FName: string;
  slPrint: TStringList;
 
//===========================================================================
 
Function Initialize: Integer;
 
Begin
  slPrint := TStringList.Create;
End;
 
 
//===========================================================================
 
Function Process(e: IInterface): Integer;
 
Begin
// Full Name:
  slPrint.Add(GetElementEditValues(e, 'FULL'));
End;
 
//===========================================================================
 
Function Finalize: Integer;
 
Begin
  FName := ProgramPath + '-- Export.txt';
  slPrint.SaveToFile(FName);
  AddMessage('>>> Saving list to ' + FName);
  slPrint.Free;
End;
 
End.

 

 

 

1. FName := ProgramPath + '-- Export.txt';

This will create the file in the program directory. Is there a way to create it in another path, like in "My Documents"?

 

 

2. s1Print.Add(GetElementEditValues(e, 'FULL'));

This gets the values but in REVERSE order of what is currently showing on my screen in TES5Edit. So, if my list is showing A>Z, this saves/prints it as Z>A.

I have to click the Menu sort button on top to resort the list in Z>A to print it in proper A>Z alphabetical order.

Any way to make this get the values in the order they are showing?

Edited by Treplos
Link to comment
Share on other sites

1. FName := ProgramPath + '-- Export.txt';

This will create the file in the program directory. Is there a way to create it in another path, like in "My Documents"?

Try using environmental variables. E.g.

 

FName := '%USERPROFILE%\My Documents\Export.txt';

 

 

2. slPrint.Add(GetElementEditValues(e, 'FULL'));

This gets the values but in REVERSE order of what is currently showing on my screen in TES5Edit. So, if my list is showing A>Z, this saves/prints it as Z>A.

I have to click the Menu sort button on top to resort the list in Z>A to print it in proper A>Z alphabetical order.

Any way to make this get the values in the order they are showing?

You're doing this in a process function, which natively goes backwards.

 

The best route to take would be to reverse the list after the entries have been added.

 

Alternatively, you could use

slPrint.Sorted := True;

 

Which will alphabetize the entries as they're added.

 

Or you could use

slPrint.Sort;

 

To sort the entries after they've been added.

Link to comment
Share on other sites

The path suggestion did not work. It keeps trying to start from the program path:

exception message : Cannot create file "G:\TES5Edit\%USERPROFILE%\My Documents\-- Export.txt".
The system cannot find the path specified.

Any other suggestions?

 

 

As for the sorting, I had the same idea and thought the function "ReverseElement" would help, but I had no clue if it was for this or how it worked lol

 

Both sort functions work btw :laugh:. The 1st in the "Function Initialize". The 2nd in "Function Finalize".

This sorting works perfectly from A>Z, even across all the sections of a mod.

 

But Is there a way to properly sort Z>A, like a reverse sort?

I am asking because the default reverse sorting is actually not proper, and does not seem to sort well across section.

 

Btw, are there any resources to read about this? About the functions, commands and whatnot?

The TES5Edit Pascal seems a bit different from the regular Pascal from what I can see on the net.

 

 

As always, ty buddy :thumbsup:.

Edited by Treplos
Link to comment
Share on other sites


unit userscript;

procedure ReverseSort(sl: TStringList);
var
i: integer;
s: string;
begin
sl.Sort;
for i := 0 to sl.Count div 2 - 1 do begin
s := sl[i];
sl[i] := sl[sl.Count-i-1];
sl[sl.Count-i-1] := s;
end;
end;

function Initialize: integer;
var
sl: TStringList;
begin
sl := TStringList.Create;
sl.Add('A');
sl.Add('B');
sl.Add('C');
ReverseSort(sl);
AddMessage(sl.Text);
sl.Free;
Result := 1;
end;

end.
Link to comment
Share on other sites

Unfortunately I'm unable to write script "Copy from all records". I totally forgot Pascal syntax I studied at school and there is very little documentation about Tes5edit scripts except this single page

http://www.creationkit.com/TES5Edit_Scripting_Functions

So... I give up. Perhaps someone here may do this for me because it doesn't look difficult for someone who has some experience. Here is the algorithm I wanted to implement.

1)Ask user about path of the element which must be changed for every record;

2)Ask user about name of the file from which they must be copied.

3)A string "Celement" gets value of the needed element we want to copy (from the record with same FormID/EditorID, but from the other file).

4)Set edit value of the element we have to the "Celement"

Something like that.

Link to comment
Share on other sites

But Is there a way to properly sort Z>A, like a reverse sort?

I am asking because the default reverse sorting is actually not proper, and does not seem to sort well across section.

 

You could sort A-Z then load the values into a stringlist backwards. So with slTest not yet sorted you'd have:

 

slTest.Sort;
for i := slTest.Count - 1 downto 0 do
  slBackwards.Add(slTest[i]);

Alternatively you could use Zilav's reverse sort function, which would save you a variable.

 

--

Of course, because of this you could also just use a downto for loop to effectively use the A-Z stringlist as a Z-A stringlist.

 

 

Btw, are there any resources to read about this? About the functions, commands and whatnot?

The TES5Edit Pascal seems a bit different from the regular Pascal from what I can see on the net.

 

TES5Edit pascal is almost exactly like regular pascal asides from the custom functions in it.

 

TES5Edit functions

 

General Pascal Resource

 

Basic Pascal Lessons

 

Free Pascal Wiki

 

 

Unfortunately I'm unable to write script "Copy from all records". I totally forgot Pascal syntax I studied at school and there is very little documentation about Tes5edit scripts except this single page

http://www.creationkit.com/TES5Edit_Scripting_Functions

So... I give up. Perhaps someone here may do this for me because it doesn't look difficult for someone who has some experience. Here is the algorithm I wanted to implement.

1)Ask user about path of the element which must be changed for every record;

2)Ask user about name of the file from which they must be copied.

3)A string "Celement" gets value of the needed element we want to copy (from the record with same FormID/EditorID, but from the other file).

4)Set edit value of the element we have to the "Celement"

Something like that.

 

That page is more than I had. Regain general pascal knowledge from the links I provided above, use existing scripts to familiarize yourself with syntax and how to write code, then start small and work your way up.

 

From what you've been wanting it'd probably be better if you copied elements from overriding records. So like:

 

1. User selects records in a file, then applies the script.

2. User inputs the name of the file they want to copy overriding values from.

3. User inputs path/s they want to copy values from.

4. See code.

5. Done.

 

 

unit userscript;

var
  filename: string;

function Initialize: integer;
begin
  // initialize your stuff here
  // use InputBox to accept user input for filename, then use a loop to find that file and store it in a variable.  I do this in several of my scripts.
  // use a looping InputBox until the input is empty to add paths the user wants to copy things from to a stringlist: slPaths
end;

function Process(e: IInterface): integer; 
var
  i: integer;
begin
  for i := 0 to OverrideCount(e) - 1 do begin
    if GetFile(OverrideByIndex(e, i)) = filename then begin
      ovrec := OverrideByIndex(e, i);
      Break;
    end;
  end;

  for i := 0 to slPaths.Count - 1 do begin
    wbCopyElementToRecord(e, ElementByPath(ovrec, slPaths[i]), True, True);
  end;
end;

Something like that. That code should get you started. I've done most of the hard parts for you.

 

 

If you're wondering why I'm having you guys learn code, here's some food for thought:

"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." --Chinese Proverb

Edited by matortheeternal
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...