Macro not recording/performing Find and Replace task.
-
The subject was quite old in this thread, and upon prompt i chose to open a new Conversation referring to this old one:
Re: Creating and running macrosI want to modify a text/log file to make all the messages line up as columns example:
0Z","@mt":"Class: Program Msg:HMI star 0Z","@mt":"Class: Program Msg:Entering 0Z","@mt":"Class: Program Msg:No comma 5Z","@mt":"Class: Program Msg:Number o 3Z","@mt":"Class: PlcLogSettingsManagerMsg:PlcLo 8Z","@mt":"Class: ApplicationLifetimeManagerMsg: 8Z","@mt":"Class: ApplicationLifetimeManagerMsg: 8Z","@mt":"Class: ApplicationLifetimeManagerMsg: 2Z","@mt":"Class: ApplicationLifetimeManagerMsg: 2Z","@mt":"Class: Program Msg:Creating 0Z","@mt":"Class: MainForm Msg:MainForm 0Z","@mt":"Class: MainForm Msg:MainForm 0Z","@mt":"Class: MainForm Msg:MainForm 0Z","@mt":"Class: MainForm Msg:MainForm
I just used “Alt+Mouse Selection” to snip out a portion of the log file to show you what I’m trying to do.
As you can see the “Class: PlcLogSettingsManager” is pushing the “Msg:” column out of alignment. I thought to just record a macro to replace the “Class:” messages with a shorter text string and the right amount of spaces to make the columns line up. When I record a macro to “Find and Replace”, it doesn’t work. What am I doing wrong, or is there a better way to accomplish the task?
Any help is appreciated. Thanks!
-
BTW, here is the macro from the shortcuts.xml file:
<Macro name="Align columns" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="PlcLogSettingsManager" /> <Action type="3" message="1625" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="PlcLogSettingsMgr " /> <Action type="3" message="1702" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="ApplicationLifetimeManager" /> <Action type="3" message="1625" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="ApplctionLifeTmMgr" /> <Action type="3" message="1702" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro>
-
Not sure why you have two Copy commands (message=“2178”) in there…you didn’t mention…
Anyway, I had “luck” with your macro if I changed the message=“1702” lines to contain lParam=“770” instead of the “0” you had in there.
“0” is not ideal because it specifies a backward search without wrap. Thus, if your caret is at the first line of your data when you run the macro, nothing is going to happen.
“770” tells the macro system to do Match case and Wrap around in a top-to-bottom direction for the Replace All. Thus, it works…
I said “luck” earlier, because while a replacement was made with my changes, it didn’t have the right content to make the columns “line up”. I used your find/replace text just as you had it in the macro.
BTW if you want to “crack” your find/replace macros in the future, this SECTION of the user manual tells you how.
-
@Aaron-Bishdou Treat the tuning of a Find & Replace operation as a separate and preliminary task before thinking about macros. It is rare to have to examine npp’s representation of F&R ops in shortcuts.xml at all.
The transformation you are hoping for does not seem complex. If you want help, show explicitly the expressions you are trying in the Find and the Replace fields along perhaps with optional settings in the F&R dialog.
Also, think about whether your sample text captures all the anticipated variation (field names & lengths) in your log files.