Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Name: Perpetually Modified Strings
- Author: eventHandler
- Version: beta1
- Written in DelphiScript, which is an OLE scripting language dervied from Standard Pascal.
- See https://support.smartbear.com/viewarticle/71968/ for more on this obscure language.
- The GUI is based on syntax learned by examining "Asset brower.pas" included with XEdit 3.1.3.
- Reference sources include:
- http://www.creationkit.com/index.php?title=TES5Edit_Scripting_Functions
- Mods be free!
- Hotkey: Ctrl+M
- }
- unit aaa_modifyBulkStrings;
- var
- elBase, elName: IInterface;
- frm: TForm;
- btnAppend, btnTrim, btnReplace, btnFront2Tail, btnTail2Front, btnClose: TButton;
- lblNote1, lblNote2: TLabel;
- strAdd, strCur, strDel, strEl: string;
- edClipboard: TEdit;
- mInfo: TMemo;
- cmbContainer: TComboBox;
- //=====
- function Process(e: IInterface): integer;
- begin
- elBase := e;
- ShowBrowser;
- Result := 0;
- Exit
- end;
- //===== Front2Tail, Tail2Front
- {
- }
- function Front2Tail: integer;
- begin
- Result := 0;
- if not InputQuery('Continue', 'Type here what to add to the tail:', strAdd) then begin
- Result := 1;
- Exit;
- end;
- if not InputQuery('Done', 'Type here what to remove from the front:', strDel) then begin
- Result := 2;
- Exit;
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- Delete(strCur, 1, Length(strDel));
- SetEditValue(elName, strCur + strAdd)
- end;
- end;
- //=
- function Tail2Front: integer;
- begin
- Result := 0;
- if not InputQuery('Continue', 'Type here what to add to the front:', strAdd) then begin
- Result := 1;
- Exit;
- end;
- if not InputQuery('Done', 'Type here what to remove from the tail: ', strDel) then begin
- Result := 2;
- Exit;
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- Delete(strCur, Length(strCur) - Length(strDel) + 1, Length(strCur));
- SetEditValue(elName, strAdd + strCur)
- end;
- end;
- //===== AppendFront, AppendTail
- {
- }
- function AppendFront: integer;
- begin
- Result := 0;
- if not InputQuery('Done', 'Type here what to add to the front:', strAdd) then begin
- Result := 1;
- Exit
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- SetEditValue(elName, strAdd + strCur)
- end;
- end;
- //=
- function AppendTail: integer;
- begin
- Result := 0;
- if not InputQuery('Done', 'Type here what to add to the tail:', strAdd) then begin
- Result := 2;
- Exit
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- SetEditValue(elName, strCur + strAdd)
- end;
- end;
- //===== TrimFront, TrimTail
- {
- }
- function TrimFront: integer;
- begin
- Result := 0;
- if not InputQuery('Continue', 'Type here what to remove from the front:', strDel) then begin
- Result := 1;
- Exit
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- Delete(strCur, 1, Length(strDel));
- SetEditValue(elName, strCur)
- end;
- end;
- //=
- function TrimTail: integer;
- begin
- Result := 0;
- if not InputQuery('Continue', 'Type here what to remove from the tail:', strDel) then begin
- Result := 1;
- Exit
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- Delete(strCur, Length(strCur) - Length(strDel) + 1, Length(strCur));
- SetEditValue(elName, strCur)
- end;
- end;
- //===== ReplaceAll, ReplaceFront, ReplaceTail
- {
- }
- function ReplaceAll: integer;
- begin
- Result := 0;
- if not InputQuery('Done', 'Type here what to set as the replacement text:', strAdd) then begin
- Result := 1;
- Exit
- end;
- if Assigned(elName) then begin
- SetEditValue(elName, strAdd)
- end;
- end;
- function ReplaceFront: integer;
- begin
- Result := 0;
- if not InputQuery('Continue', 'Type here what to remove from the front:', strDel) then begin
- Result := 1;
- Exit
- end;
- if not InputQuery('Done', 'Type here what to add to the front:', strAdd) then begin
- Result := 1;
- Exit
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- Delete(strCur, 1, Length(strDel));
- SetEditValue(elName, strAdd + strCur)
- end;
- end;
- //=
- function ReplaceTail: integer;
- begin
- Result := 0;
- if not InputQuery('Continue', 'Type here what to remove from the tail:', strDel) then begin
- Result := 1;
- Exit
- end;
- if not InputQuery('Done', 'Type here what to add to the tail:', strAdd) then begin
- Result := 2;
- Exit
- end;
- if Assigned(elName) then begin
- strCur := GetEditValue(elName);
- Delete(strCur, Length(strCur) - Length(strDel) + 1, Length(strCur));
- SetEditValue(elName, strCur + strAdd)
- end;
- end;
- //===========================================================================
- // on key down event handler for form
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin
- if Key = VK_ESCAPE then
- TForm(Sender).ModalResult := mrOk;
- end;
- //===========================================================================
- procedure evtClickBtnAppend(Sender: TObject);
- var
- strIn: string;
- begin
- if not InputQuery('Continue', 'Type the part to perform append on (front, tail, prefix, postfix):', strIn) then begin
- AddMessage('Invalid input while collecting append details.');
- Exit
- end;
- if (AnsiCompareText(strIn, 'front') = 0) or (AnsiCompareText(strIn, 'prefix') = 0) then begin
- AppendFront;
- Exit
- end;
- if (AnsiCompareText(strIn, 'tail') = 0) or (AnsiCompareText(strIn, 'postfix') = 0) then begin
- AppendTail;
- Exit
- end;
- AddMessage('evtClickBtnAppend error: invalid input.');
- end;
- //===
- procedure evtClickBtnTrim(Sender: TObject);
- var
- strIn: string;
- begin
- if not InputQuery('Continue', 'Type the part to perform trim on (front, tail, prefix, postfix):', strIn) then begin
- AddMessage('Invalid input while collecting trim details.');
- Exit
- end;
- if (AnsiCompareText(strIn, 'front') = 0) or (AnsiCompareText(strIn, 'prefix') = 0) then begin
- TrimFront;
- Exit
- end;
- if (AnsiCompareText(strIn, 'tail') = 0) or (AnsiCompareText(strIn, 'postfix') = 0) then begin
- TrimTail;
- Exit
- end;
- AddMessage('evtClickBtnTrim error: invalid input.');
- end;
- //===
- procedure evtClickBtnReplace(Sender: TObject);
- var
- strIn: string;
- begin
- if not InputQuery('Continue', 'Type the part to perform replacement on (all, front, tail, prefix, postfix):', strIn) then begin
- AddMessage('Invalid input while collecting replacement details.');
- Exit
- end;
- if (AnsiCompareText(strIn, 'all') = 0) then begin
- ReplaceAll;
- Exit
- end;
- if (AnsiCompareText(strIn, 'front') = 0) or (AnsiCompareText(strIn, 'prefix') = 0) then begin
- ReplaceFront;
- Exit
- end;
- if (AnsiCompareText(strIn, 'tail') = 0) or (AnsiCompareText(strIn, 'postfix') = 0) then begin
- ReplaceTail;
- Exit
- end;
- AddMessage('evtClickBtnReplace error: invalid input.');
- end;
- //===
- procedure evtClickBtnFront2Tail(Sender: TObject);
- begin
- Front2Tail;
- AddMessage('evtClickBtnFront2Tail running.');
- end;
- //===
- procedure evtClickBtnTail2Front(Sender: TObject);
- begin
- Tail2Front;
- AddMessage('evtClickBtnTail2Front running.');
- end;
- //===
- procedure cmbContainerOnChange(Sender: TObject);
- begin
- strEl := cmbContainer.Text;
- AddMessage('element string:' + strEl);
- elName := ElementByName(elBase, strEl);
- end;
- //===
- procedure ShowBrowser;
- var
- i, tOff, lOff, vPad, hPad, btnWidth: integer;
- begin
- tOff := 48;
- lOff := 24;
- vPad := 8;
- hPad := 8;
- btnWidth := 180;
- frm := TForm.Create(nil);
- try
- frm.Caption := 'Perpetually Modified Strings';
- frm.Width := 900;
- frm.Height := 480;
- frm.Position := poScreenCenter;
- frm.KeyPreview := True;
- frm.OnKeyDown := FormKeyDown;
- btnAppend := TButton.Create(frm);
- btnAppend.Parent := frm;
- btnAppend.Top := tOff;
- btnAppend.Left := lOff;
- btnAppend.Width := btnWidth;
- btnAppend.Caption := 'Append to existing entry.';
- btnAppend.Anchors := [akRight, akBottom];
- btnAppend.OnClick := evtClickBtnAppend;
- btnTrim := TButton.Create(frm);
- btnTrim.Parent := frm;
- btnTrim.Top := btnAppend.Top + btnAppend.Height + vPad;
- btnTrim.Left := lOff;
- btnTrim.Width := btnWidth;
- btnTrim.Caption := 'Trim from existing entry.';
- btnTrim.Anchors := [akRight, akBottom];
- btnTrim.OnClick := evtClickBtnTrim;
- btnReplace := TButton.Create(frm);
- btnReplace.Parent := frm;
- btnReplace.Top := btnTrim.Top + btnTrim.Height + vPad;
- btnReplace.Left := lOff;
- btnReplace.Width := btnWidth;
- btnReplace.Caption := 'Replace part/all of existing entry.';
- btnReplace.Anchors := [akRight, akBottom];
- btnReplace.OnClick := evtClickBtnReplace;
- btnFront2Tail := TButton.Create(frm);
- btnFront2Tail.Parent := frm;
- btnFront2Tail.Top := tOff;
- btnFront2Tail.Left := lOff + btnWidth + hPad;
- btnFront2Tail.Width := btnWidth;
- btnFront2Tail.Caption := 'Front2Tail';
- btnFront2Tail.Anchors := [akRight, akBottom];
- btnFront2Tail.OnClick := evtClickBtnFront2Tail;
- btnTail2Front := TButton.Create(frm);
- btnTail2Front.Parent := frm;
- btnTail2Front.Top := btnFront2Tail.Top + btnFront2Tail.Height + vPad;
- btnTail2Front.Left := lOff + btnWidth + hPad;
- btnTail2Front.Width := btnWidth;
- btnTail2Front.Caption := 'Tail2Front';
- btnTail2Front.Anchors := [akRight, akBottom];
- btnTail2Front.OnClick := evtClickBtnTail2Front;
- btnClose := TButton.Create(frm);
- btnClose.Parent := frm;
- btnClose.Top := btnReplace.Top + btnReplace.Height + vPad;
- btnClose.Left := lOff;
- btnClose.Width := btnWidth;
- btnClose.Caption := 'Close';
- btnClose.Anchors := [akRight, akBottom];
- btnClose.ModalResult := mrOk;
- // invisible edit field used to copy to clipboard
- edClipboard := TEdit.Create(frm);
- edClipboard.Parent := frm;
- edClipboard.Visible := False;
- mInfo := TMemo.Create(frm);
- mInfo.Parent := frm;
- mInfo.Top := btnClose.Top + btnClose.Height + vPad*8;
- mInfo.Left := lOff;
- mInfo.Width := frm.Width - lOff*2;
- mInfo.Height := 180;
- mInfo.Anchors := [akLeft, akRight, akBottom];
- mInfo.ScrollBars := ssVertical;
- mInfo.ReadOnly := True;
- lblNote1 := TLabel.Create(frm);
- lblNote1.Parent := frm;
- lblNote1.Top := mInfo.Top + mInfo.Height + vPad;
- lblNote1.Left := lOff + btnWidth/2;
- lblNote1.Anchors := [akRight, akBottom];
- lblNote1.Caption := 'Note: Replace front/tail only replaces the same # of characters used as input,'#13' it does NOT actually compare the front/tail to the input being replaced.';
- cmbContainer := TComboBox.Create(frm);
- cmbContainer.Parent := frm;
- cmbContainer.Top := tOff/6;
- cmbContainer.Left := frm.Width/2 + btnWidth;
- cmbContainer.Width := frm.Width - cmbContainer.Left - lOff;
- cmbContainer.Style := csDropDownList;
- cmbContainer.DropDownCount := 16;
- cmbContainer.Anchors := [akTop, akRight];
- cmbContainer.OnChange := cmbContainerOnChange;
- cmbContainer.Items.Add('EDID - Editor ID');
- cmbContainer.Items.Add('FULL - Name');
- cmbContainer.Items.Add('DESC - Description');
- cmbContainer.Items.Add('CNAM - Created Object');
- cmbContainer.Items.Add('BNAM - Workbench Keyword');
- cmbContainer.Items.Add('YNAM - Sound - Pick Up');
- cmbContainer.Items.Add('ZNAM - Sound - Drop');
- cmbContainer.Items.Add('CRIF - Crime faction');
- cmbContainer.Items.Add('DOFT - Default outfit');
- cmbContainer.Items.Add('RNAM - Race');
- cmbContainer.Items.Add('CNAM - Class');
- cmbContainer.Items.Add('ATKR - Attack Race');
- cmbContainer.Items.Add('ZNAM - Combat Style');
- cmbContainer.Items.Add('HCLF - Hair Color');
- cmbContainer.Items.Add('FTST - Head texture');
- cmbContainer.Items.Add('VTCK - Voice');
- //for i := 0 to Pred(slContainers.Count) do
- // cmbContainer.Items.Add(SimpleName(slContainers[i]));
- cmbContainer.ItemIndex := 0;
- lblNote2 := TLabel.Create(frm);
- lblNote2.Parent := frm;
- lblNote2.Top := cmbContainer.Top + cmbContainer.Height + vPad;
- lblNote2.Left := cmbContainer.Left;
- lblNote2.Anchors := [akRight, akBottom];
- lblNote2.Caption := 'WARNING: Currently no safeguards to ensure'#13'the records being modified have the selected field'#13'from this drop down list! It is YOUR responsibility'#13'to pick valid options for the records being modified.';
- strEl := cmbContainer.Text;
- AddMessage('element string:' + strEl);
- elName := ElementByName(elBase, strEl);
- frm.ShowModal;
- finally
- frm.Free;
- end;
- end;
- //===========================================================================
- {
- function Initialize: integer;
- begin
- Result := 1;
- end;
- }
- //===========================================================================
- {
- Always use tabs when indenting, and remember: Only YOU can prevent chaotic text alignment with untold bytes wasted on white space!
- Use Notepad++ and choose your own tab width for personal preference! Standard tab width is four fixed-width spaces. That is the only correct width, and what any civilized person will use.
- I take full (posthumous) responsibility if you blow up the planet using my scripts, but not for more mundane annoyances. I apologize in advance to everyone affected by the world blowing up.
- No lawsuits allowed against me. You've been warned!
- }
- end.
Advertisement
Add Comment
Please, Sign In to add comment