Back

Topic

[KB1055]Using regular expressions with advanced text editor

Tags: ASCII, Regular

5 years ago
By LM
Options
Print
Applies to:

PcVue all versions supporting ascii format for mimics


Summary:

This article explains how to use regular expressions to modify a set of text files and thus save a lot of time when modifying a project.
A good place to learn more about regular expressions: https://www.regular-expressions.info/


Details:

Regular expressions can be used in modern text editors such as Ultra Edit, PSPad, Notepad++…
At the time of writing this article, PSPad does not allow to use them on several files at the same time, whereas it is possible with Notepad++, so we will discover how to do it with Notepad++ through a concrete case.

In a project, we have 4 windows that use the same window template, but not with the same properties inherited from the template. So the graphical rendering is different for the 4 windows, it is not homogeneous:
4 Different Mimics

If you want to apply the same properties inherited from the template for all 4 windows, you can do it easily with Notepad++ by doing a search / replace with regular expressions. This will be all the more convenient if you manipulate a lot of files. Imagine if we had to homogenize 100 windows…

Caution: before modifying your project with external tools, please take care of saving carefully last version of your project.

Then we have to make sure that the mimics are saved in ASCII format so that we can modify them with a text editor. The easiest way is to use the library converter from the Display menu. The library converter will close all open mimics before appearing. Then select the concerned library, check the option Mimics and convert to ASCII format:
Library Converter

In our example we want all 4 windows to use the same inherited properties as the first one:
View1 Properties

We open this mimic with Notepad++ to find the line that starts with TEMPLATE near the top of the file. This line defines not only the window template used by the View1 window, but also all the properties inherited from the template:
View1 ASCII file

Now you have to replace the TEMPLATE line of the other 3 files using this :
TEMPLATE, “SmallTemplate”,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
Note that the number of options on the line depends on the version of PcVue.

To do this, launch the file search tool by clicking on the menu Search –> Find in Files… Here we use the regular expression “.” (dot) which means any character in the Find what field. Here is the configuration that is appropriate in our case :
Replace In Files
TEMPLATE,”SmallTemplate”,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.

Another simpler regular expression could be used in that case:
TEMPLATE,”SmallTemplate”.*$ means an entire line starting with TEMPLATE,”SmallTemplate”

Press the Replace in Files button and confirm. Caution: files are automatically saved, so it is not possible to undo the modifications. The 4 files in the W directory are then modified and homogeneous. Here is the result after closing and opening the 4 new windows :
4 Similar Mimics


Another example. A search and replace in the COMM.dat file with the following regular expression allows to change IP address of all PLCs to redirect them on a local simulator:

Search: ,\d{1,3}#\d{1,3}#\d{1,3}#\d{1,3}#\d{1,3}#0#0#10#0#0#0#0#0
Replace: ,127#0#0#1#502#0#0#10#0#0#0#0#0

PSPad regular expressions


Another example. Since PcVue version 16, protoc.dat file in Bin directory has been replaced by CimWayProtocols.xml file. A search and replace in that xml file allows you to redirect all the protocols so that they use the simulation protocol:

Search: filename=”cwp.*.dll”
Replace: filename=”cwpSimNG.dll”


 

Created on: 03 Apr 2020 Last update: 04 Sep 2024