Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.
-
Hello Fellow Notepad++ Users,
Could you please help me with the following search-and-replace problem I am having?
I am a survey engineer and brand new to notepad++. Actually i started searching for notepad because last year i bought a new surveying equipment from a different company (LEICA) than my previous (TOPCON), and the format of my surveyings is different so everytime i have to manually copy-paste, delete and write everything, so to work with my current software…
I sincerely have tried to search for directions, but my problem is to complex for a beginner and i am loosing so much time figuring out and i am really pressed for delivering. So any help would be deeply appreciated and thank you in advance.My debug info:
Notepad++ v8.7.5 (64-bit)
Build time : Dec 21 2024 - 05:13:03
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : “D:\Τοπογραφικά\2024\Μαλλής Ιωάννης\Πρωτόλεια\MALLIS_TS.XML”
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
Periodic Backup : ON
Placeholders : OFF
DirectWrite : ON
Multi-instance Mode : monoInst
File Status Auto-Detection : cdEnabledNew (for current file/tab only)
Dark Mode : OFF
OS Name : Windows 10 Pro (64-bit)
OS Version : 22H2
OS Build : 19045.5247
Current ANSI codepage : 1253
Plugins :
mimeTools (3.1)
NppConverter (4.6)
NppExport (0.4)My Goals are :
Goal 1. A fully automated macro that turns Before to After or
Goal 2. If it can’t be fully automated (which i suspect), then help me up to a point and then i’ll take care of the rest manually.It is difficult to explain all the changes in plain text, but let me try with some steps. I will describe first the steps and at the bottom i paste those lines of before and after. In BOLD i present the parameters i need from the BEFORE and in ITALIC the structure of the AFTER.
i) In the Before file, i want everything from line 274 and above to be deleted. (the line 274 is not fixed in every different file).
ii) The Line 275
<InstrumentSetup id=“TPSSetupID_S1_7” instrumentDetailsID=“TPS_3338144” stationName=“S1” instrumentHeight=“1.490000” orientationAzimuth=“0.000000”>
i want to transform to (italic) Line 1 of After:
STN S1,1.490, (Between STN and S1, there are 5 spaces)iii) The Line 279 and 280:
<Backsight azimuth=“315.975684” targetHeight=“0.000000” circle=“315.975684” setupID=“TPSSetupID_S1_7”>
<BacksightPoint name=“S2” pntRef=“S2@8”>1004.603425 982.042372 103.549492</BacksightPoint>
I want to transform to (italic) Line 2 of After:
BKB S2,315.975684,315.975684 (Between BKB and S2, there are 5 spaces. BacksightPoint,Azimuth,Circle)iv) The Line 283 and 284:
<RawObservation setupID=“TPSSetupID_S1_7” purpose=“backsight” targetHeight=“1.765000” horizAngle=“315.975684” zenithAngle=“87.048171” horizDistance=“18.538283” slopeDistance=“18.928679” directFace=“true” timeStamp=“2024-10-17T12:15:54”>
<TargetPoint name=“S2” pntRef=“S2@9”>1004.603425 982.042372 103.549492</TargetPoint>
I want to transform to Lines 3 and 4 of After:
BS S2,1.765,
SD 315.975684,87.048171,18.928679
(Between BS and S2 and between SD and the next number, there are 6 spaces. After BS there is Targetpoint,TargetHeight. After SD there is horizAngle,zenithAngle,slopeDistance)vi) Then go to line 292 and 293:
<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“0.000000” horizAngle=“84.758594” zenithAngle=“82.872144” horizDistance=“19.028390” slopeDistance=“19.738486” directFace=“true” timeStamp=“2024-10-17T12:16:52”>
<TargetPoint name=“1” pntRef=“1@10”>1004.512219 1018.485657 106.736705</TargetPoint>
Which i want to transform to lines 5 and 6:
SS 1,0.000,
SD 84.758594,82.872144,19.738486
It’s the same as before (step iv), except from now on it starts with SSvii) After that it just repeats the step “vi” up to line 733-734 of Before.
viii) Then we go to Line 743 of Before where we repeat step ii (line105 of After), Line 748 and 749 where we repeat step iii (line106 of After), then we go to Line 751 and 752 of Before where we repeat step iv (line 107 and 108 of Before)
If you noticed i skipped step v. I did it on purpose because when you are in case of step 6 and the TargetPoint name starts with an S (ex. S1,S2…) then the SS turns to FS. Usually this happens right after the BS and before the SS of the second period of measurements.
v) line 760 and 761 of Before
<RawObservation setupID=“TPSSetupID_S2_67” purpose=“normal” targetHeight=“1.765000” horizAngle=“221.871847” zenithAngle=“96.423587” horizDistance=“26.940505” slopeDistance=“26.983079” directFace=“true” timeStamp=“2024-10-17T13:23:18”>
<TargetPoint name=“S3” pntRef=“S3@70”>979.237302 972.967645 104.881723</TargetPoint>
Which i want to transform to lines 109 and 110:
FS S3,1.765,
SD 221.871847,96.423587,26.983079ix) Then it repeats the step vi up to the next station where we begin again with step i to vi.
x) After it ends, i need the last lines of before to be deleted.
A couple of notices:
- When a line in After starts with a 2digit word, it follows 6 spaces and when it starts with a 3 line word it follows 5 spaces.
- When a line in After has 2 values after the spaces (like line 1,3,5 etc) it ends with comma. When it has 3 values it doesn’t end with comma.
Now i paste some characteristic lines from the Before. The number at the start is the number of the line. Each line starts with <
BEGINNING OF BEFORE
1<?xml version=“1.0” encoding=“utf-8”?>
2<LandXML xmlns=“http://www.landxml.org/schema/LandXML-1.2” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.landxml.org/schema/LandXML-1.2 http://www.landxml.org/schema/LandXML-1.2/LandXML-1.2.xsd” version=“1.2” date=“2024-10-18” time=“14:15:24” readOnly=“false” language=“English”>
3<Units>
4<Metric linearUnit=“meter” areaUnit=“squareMeter” volumeUnit=“cubicMeter” angularUnit=“grads” temperatureUnit=“celsius” pressureUnit=“HPA”/>
5</Units>
6<Application name=“LandXML Export” manufacturer=“Leica Geosystems AG” version=“2.50” manufacturerURL=“www.leica-geosystems.com”>
7<Author createdBy=“Leica-FlexLine” company=“Leica Geosystems AG” companyURL=“www.leica-geosystems.com” timeStamp=“2024-10-18T14:15:24”/>
8</Application>
9<CgPoints>
10<CgPoint name=“S1@4” oID=“S1” role=“control point” timeStamp=“2024-10-17T12:13:15”>1000.000000 1000.000000 100.000000</CgPoint>
11<CgPoint name=“S2@65” oID=“S2” role=“control point” timeStamp=“2024-10-17T13:20:20”>1004.603425 982.042372 103.546612</CgPoint>
12<CgPoint name=“S3@129” oID=“S3” role=“control point” timeStamp=“2024-10-17T13:50:50”>979.237302 972.967645 104.878486</CgPoint>
…
208<CgPoint name=“178@232” oID=“178” role=“measured” timeStamp=“2024-10-17T14:36:45”>990.281588 1031.312747 100.879458</CgPoint>
209<CgPoint name=“179@233” oID=“179” role=“measured” timeStamp=“2024-10-17T14:37:17”>960.688280 1029.106191 101.014885</CgPoint>
210</CgPoints>
211<Survey>
212<SurveyHeader name=“”/>
213<Equipment>
214<InstrumentDetails id=“TPS_3338144” manufacturer=“Leica Geosystems AG” model=“TS03 3” R500" serialNumber=“3338144” horizCollimation=“0.000470” vertCollimation=“0.000000”>
215<Corrections>
216<Feature code=“TPSCorrection”>
217<Property label=“oID” value=“3”/>
218<Property label=“referenceRadius” value=“6378000.000000”/>
219<Property label=“offsetCentralMeridian” value=“0.000000”/>
…
269<Property label=“heightReductionPPM” value=“0.000000”/>
270<Property label=“individualPPM” value=“0.000000”/>
271</Feature>
272</Corrections>
272</InstrumentDetails>
274</Equipment>***Up to this line i want to be deleted (or i am doing it myself). I just paste it to get an idea of the structure of the file.
275<InstrumentSetup id=“TPSSetupID_S1_7” instrumentDetailsID=“TPS_3338144” stationName=“S1” instrumentHeight=“1.490000” orientationAzimuth=“0.000000”>
276<Feature code=“TPSSetup”>
277<Property label=“type” value=“knownAzimuth”/>
278</Feature>
279<InstrumentPoint pntRef=“S1@4” name=“S1” timeStamp=“2024-10-17T12:13:15”>1000.000000 1000.000000 100.000000</InstrumentPoint>
280<Backsight azimuth=“315.975684” targetHeight=“0.000000” circle=“315.975684” setupID=“TPSSetupID_S1_7”>
281<BacksightPoint name=“S2” pntRef=“S2@8”>1004.603425 982.042372 103.549492</BacksightPoint>
282</Backsight>
283<RawObservation setupID=“TPSSetupID_S1_7” purpose=“backsight” targetHeight=“1.765000” horizAngle=“315.975684” zenithAngle=“87.048171” horizDistance=“18.538283” slopeDistance=“18.928679” directFace=“true” timeStamp=“2024-10-17T12:15:54”>
284<TargetPoint name=“S2” pntRef=“S2@9”>1004.603425 982.042372 103.549492</TargetPoint>
285<Feature code=“observationInfo”>
286<Property label=“TPSCorrectionRef” value=“3”/>
287<Property label=“EDMType” value=“reflectorless”/>
288<Property label=“reflectorName” value=“Reflectorless”/>
289<Property label=“reflectorConstant” value=“0.034400”/>
290</Feature>
291</RawObservation>
292<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“0.000000” horizAngle=“84.758594” zenithAngle=“82.872144” horizDistance=“19.028390” slopeDistance=“19.738486” directFace=“true” timeStamp=“2024-10-17T12:16:52”>
293<TargetPoint name=“1” pntRef=“1@10”>1004.512219 1018.485657 106.736705</TargetPoint>
294<Feature code=“observationInfo”>
295<Property label=“TPSCorrectionRef” value=“3”/>
296<Property label=“EDMType” value=“reflectorless”/>
297<Property label=“reflectorName” value=“Reflectorless”/>
298<Property label=“reflectorConstant” value=“0.034400”/>
299</Feature>
300</RawObservation>
301<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“0.000000” horizAngle=“94.912866” zenithAngle=“81.131542” horizDistance=“17.044892” slopeDistance=“17.821968” directFace=“true” timeStamp=“2024-10-17T12:17:29”>
302<TargetPoint name=“2” pntRef=“2@11”>1001.360583 1016.990502 106.695188</TargetPoint>
303<Feature code=“observationInfo”>
304<Property label=“TPSCorrectionRef” value=“3”/>
305<Property label=“EDMType” value=“reflectorless”/>
306<Property label=“reflectorName” value=“Reflectorless”/>
307<Property label=“reflectorConstant” value=“0.034400”/>
308</Feature>
309</RawObservation>
310<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“0.000000” horizAngle=“109.427064” zenithAngle=“86.721322” horizDistance=“15.405344” slopeDistance=“15.746649” directFace=“true” timeStamp=“2024-10-17T12:17:46”>
311<TargetPoint name=“3” pntRef=“3@12”>997.727105 1015.236751 104.750703</TargetPoint>
312<Feature code=“observationInfo”>
313<Property label=“TPSCorrectionRef” value=“3”/>
314<Property label=“EDMType” value=“reflectorless”/>
315<Property label=“reflectorName” value=“Reflectorless”/>
316<Property label=“reflectorConstant” value=“0.034400”/>
317</Feature>
318</RawObservation>
…
723</RawObservation>
724<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“0.000000” horizAngle=“145.541148” zenithAngle=“109.313317” horizDistance=“11.561889” slopeDistance=“11.686721” directFace=“true” timeStamp=“2024-10-17T13:10:00”>
725<TargetPoint name=“49” pntRef=“49@60”>992.416693 1008.727585 99.786412</TargetPoint>
726<Feature code=“observationInfo”>
727<Property label=“TPSCorrectionRef” value=“39”/>
728<Property label=“EDMType” value=“reflectorless”/>
729<Property label=“reflectorName” value=“Reflectorless”/>
730<Property label=“reflectorConstant” value=“0.034400”/>
731</Feature>
732</RawObservation>
733<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“1.765000” horizAngle=“203.482131” zenithAngle=“92.956647” horizDistance=“8.948246” slopeDistance=“9.003293” directFace=“true” timeStamp=“2024-10-17T13:12:39”>
734<TargetPoint name=“50” pntRef=“50@61”>991.065137 999.510800 100.719069</TargetPoint>
735<Feature code=“observationInfo”>
736<Property label=“TPSCorrectionRef” value=“39”/>
737<Property label=“EDMType” value=“reflector”/>
738<Property label=“reflectorName” value=“User 1”/>
739<Property label=“reflectorConstant” value=“0.030000”/>
740</Feature>
741</RawObservation>
742</InstrumentSetup>
743<InstrumentSetup id=“TPSSetupID_S2_67” instrumentDetailsID=“TPS_3338144” stationName=“S2” instrumentHeight=“1.585000” orientationAzimuth=“0.000000”>
744<Feature code=“TPSSetup”>
745<Property label=“type” value=“knownBacksight”/>
746</Feature>
747<InstrumentPoint pntRef=“S2@65” name=“S2” timeStamp=“2024-10-17T13:20:20”>1004.603425 982.042372 103.546612</InstrumentPoint>
748<Backsight azimuth=“115.975684” targetHeight=“0.000000” circle=“115.975684” setupID=“TPSSetupID_S2_67”>
749<BacksightPoint name=“S1” pntRef=“S1@68”>1000.000000 1000.000000 100.000000</BacksightPoint>
750</Backsight>
751<RawObservation setupID=“TPSSetupID_S2_67” purpose=“backsight” targetHeight=“1.765000” horizAngle=“115.975684” zenithAngle=“111.430698” horizDistance=“18.532304” slopeDistance=“18.835095” directFace=“true” timeStamp=“2024-10-17T13:20:08”>
752<TargetPoint name=“S1” pntRef=“S1@69”>1000.001485 999.994208 100.002880</TargetPoint>
753<Feature code=“observationInfo”>
754<Property label=“TPSCorrectionRef” value=“39”/>
755<Property label=“EDMType” value=“reflector”/>
756<Property label=“reflectorName” value=“User 1”/>
757<Property label=“reflectorConstant” value=“0.030000”/>
758</Feature>
759</RawObservation>
760<RawObservation setupID=“TPSSetupID_S2_67” purpose=“normal” targetHeight=“1.765000” horizAngle=“221.871847” zenithAngle=“96.423587” horizDistance=“26.940505” slopeDistance=“26.983079” directFace=“true” timeStamp=“2024-10-17T13:23:18”>
761<TargetPoint name=“S3” pntRef=“S3@70”>979.237302 972.967645 104.881723</TargetPoint>
762<Feature code=“observationInfo”>
763<Property label=“TPSCorrectionRef” value=“39”/>
764<Property label=“EDMType” value=“reflector”/>
765<Property label=“reflectorName” value=“User 1”/>
766<Property label=“reflectorConstant” value=“0.030000”/>
767</Feature>
768</RawObservation>
769<RawObservation setupID=“TPSSetupID_S2_67” purpose=“normal” targetHeight=“0.000000” horizAngle=“83.254523” zenithAngle=“91.449796” horizDistance=“22.857811” slopeDistance=“23.065539” directFace=“true” timeStamp=“2024-10-17T13:23:59”>
770<TargetPoint name=“51” pntRef=“51@71”>1010.546790 1004.113981 108.220189</TargetPoint>
771<Feature code=“observationInfo”>
772<Property label=“TPSCorrectionRef” value=“39”/>
773<Property label=“EDMType” value=“reflectorless”/>
774<Property label=“reflectorName” value=“Reflectorless”/>
775<Property label=“reflectorConstant” value=“0.034400”/>
776</Feature>
777</RawObservation>
…
2011<RawObservation setupID=“TPSSetupID_S5_200” purpose=“normal” targetHeight=“0.000000” horizAngle=“224.305789” zenithAngle=“97.416611” horizDistance=“17.421457” slopeDistance=“17.435813” directFace=“true” timeStamp=“2024-10-17T14:37:17”>
2012<TargetPoint name=“179” pntRef=“179@233”>960.688280 1029.106191 101.014885</TargetPoint>
2013<Feature code=“observationInfo”>
2014<Property label=“TPSCorrectionRef” value=“107”/>
2015<Property label=“EDMType” value=“reflectorless”/>
2016<Property label=“reflectorName” value=“Reflectorless”/>
2017<Property label=“reflectorConstant” value=“0.034400”/>
2018</Feature>
2019</RawObservation>
2020</InstrumentSetup>
2021</Survey>
2022</LandXML>END OF BEFORE
BEGINNING OF AFTER. Again, the number at the start with the dot is the number of the line. The actual line starts AFTER the dot.
1.STN S1,1.49,
2.BKB S2,315.975684,315.975684
3.BS S2,1.765,
4.SD 315.975684,87.048171,18.928679
5.SS 1,0,
6.SD 84.758594,82.872144,19.738486
7.SS 2,0,
8.SD 94.912866,81.131542,17.821968
…
103.SS 50,1.765,
104.SD 203.482131,92.956647,9.003293
105.STN S2,1.585,
106.BKB S1,115.975684,115.975684
107.BS S1,1.765,
108.SD 115.975684,111.430698,18.835095
109.FS S3,1.765,
110.SD 221.871847,96.423587,26.983079
111.SS 51,0,
112.SD 83.254523,91.449796,23.065539
113.SS 52,0,
114.SD 79.537496,91.449069,21.421922etc…
The AFTER is rather simple as you see. I hope you got the point…
Again, Thank you all very much.
-
@Black-Fox said in Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.:
The AFTER is rather simple as you see. I hope you got the point…
Regular expressions are going to most likely transform most of the lines you seek to change. However I’m a bit unsure of the very first requirement. You say “everything from line 274 and above to be deleted” yet you also appear to say line 274 is not fixed.
Now the 2nd requirement is working on successive lines (275, 276, 277 etc). That appears to be contrary to the 1st requirement. So I expect that your 1st requirement was actually to say you need lines 1-274 to be deleted (for me 274 and above means 274, 275 etc to the end of the file). You also say that the #274 may be different depending on the file. If it can be different you would need to provide the method by which you determine the line to stop deleting. I expect that may well be something along the lines of your 2nd requirement, thus the line would contain “<InstrumentSetup id=”.
So I would suggest you read the FAQ post called Template for Search/Replace Questions here. You need to insert examples of the before and after within code blocks as otherwise some characters may well be interpreted/altered by the posting engine, quotes
"
being one of them.Terry
-
@Black-Fox said in Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.:
i) In the Before file, i want everything from line 274 and above to be deleted. (the line 274 is not fixed in every different file).
That part is an easy low hanging fruit:
Search:
(?s-i)\A.*</Equipment>$
Replace:(nothing or blank)
Breaking that down:
(?s-i)
Thes
switches on the dot matches newline flag so that the.*
later in the expression will scan past the end of lines on to the next line. The-i
part turns off the ignore-case flag so that we end up scanning forEquipment
with the upper caseE
and lower casequipment
.\A
Says to start at the beginning or line 1 of the file..*
Matches any and all characters until …- The match stops at
</Equipment>$
. If you also want to remove all of the line with the</Equipment>
on it then use</Equipment>\R
instead of</Equipment>$
as\R
matches the end of line mark while$
matches up to but not including the end of line mark.
-
@Black-Fox said in Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.:
Could you please help me with the following search-and-replace problem I am having?
I’ve taken a different approach to @mkupper in that I target the lines you do want to keep as I was unsure of whether other tags such as “Equipment” might be embedded within the area you did want to keep.
So, using the Mark function I would use:
Find What:(?s)<InstrumentSetup id=.+
Have “Bookmark line” ticked(search mode must be Regular Expression)
and then click on the “Mark All” button. Now that the lines to keep are marked you can remove the “unmarked lines” by using the menu option Search, Bookmark, Remove Non-Bookmarked Lines". As long as you had the cursor at the start of the open file when running this Mark function, this will find the first occurrence of “<InstrumentSetup id=” and mark all lines from here to the end of the file.As I said before I believe all your requirements can be met by a number of regular expressions. Then these can all be stored together in a macro. This would mean all you need to do is open a file, then run the macro and if everything you tell us is accurate enough you should have the result you need.
As for all the other line changes, you do need to provide them in the code boxes. Currently you have so many requests presented it’s hard to understand everything as you currently have them presented. Some of your requests include statements like “Then we go to Line 743 of Before where we repeat step ii (line105 of After), Line 748 and 749 where we repeat step iii (line106 of After), then we go to Line 751 and 752 of Before where we repeat step iv (line 107 and 108 of Before)”. So the question is: Are there occurrences of the lines which you don’t want altered. From what I can see in your “after” example it does not appear to be so.
So if EVERY line that has a particular string in it that will need altering, telling us where that line might be; “line 743 of Before”; is redundant. All you need to say is “after the initial deletion of lines 1 to approximately 274” where ever “this string” occurs, it needs to change to “this format”.
Terry
-
Thank you all in advance.
Indeed i want to delete everything from 1 to 274. But that is the least of my problems, as it takes less than a sec to do it by myself.
Everything else is my difficulty. And unfortunately i don’t know the expressions to filter what i need and replace for an easy outcome.
The steps i to vi is a repeating process of the data inside the before file. What i mean is : Lines 275 to 742 is one period. Lines 743 to 1254 another period, etc. Each period has the same structure, Just the names change. The gap between lines 318 and 723 contains the same “paragraphs or sections” as the lines 309-317 so i didn’t repeat them more.As a conclusion, what i need is :
Example: The lines 283 and 284
283<RawObservation setupID=“TPSSetupID_S1_7” purpose=“backsight” targetHeight=“1.765000” horizAngle=“315.975684” zenithAngle=“87.048171” horizDistance=“18.538283” slopeDistance=“18.928679” directFace=“true” timeStamp=“2024-10-17T12:15:54”>
284<TargetPoint name=“S2” pntRef=“S2@9”>1004.603425 982.042372 103.549492</TargetPoint>to be altered to this:
BS S2,1.765,
SD 315.975684,87.048171,18.928679Can you help me with the expressions?
-
@Black-Fox said in Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.:
Can you help me with the expressions?
Now you still haven’t been able to show us exactly how you know to replace “<RawObservation”… with "BS. I think I see “S2” later in the 2nd (#284) original line, but you also have a “SD” which like “BS” seems to appear from nowhere.
And still you persist in showing examples without the code boxes. Are the numbers 283 and 284 actually part of the file? So as I see it the example should have actually been presented like this:
<RawObservation setupID=“TPSSetupID_S1_7” purpose=“backsight” targetHeight=“1.765000” horizAngle=“315.975684” zenithAngle=“87.048171” horizDistance=“18.538283” slopeDistance=“18.928679” directFace=“true” timeStamp=“2024-10-17T12:15:54”> <TargetPoint name=“S2” pntRef=“S2@9”>1004.603425 982.042372 103.549492</TargetPoint>
and
BS S2,1.765, SD 315.975684,87.048171,18.928679
assuming the 2 old lines changes to 2 new lines (transposing data). All I can understand so far is it seems you must use both old lines (283 & 284) to produce the new lines, moving strings between them.
These code boxes are explained in the link I gave you previously. In short, you insert the original data (without anything added or subtracted, so no line numbers if they weren’t in the original file), then select that data and click on the
</>
button above the post as you are creating it.Terry
-
@Black-Fox said in Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.:
As a conclusion, what i need is :
Example: The lines 283 and 284
From that example I would consider this may be the change you want to make:
- For every line starting with “<RawObservation”, use this and the next line to make 2 new lines.
- The first new line will start with "BS " followed by the code that appears in the quotes in “
name=""
” in the following line, then a comma followed by the “targetHeight” number in the first line, again followed by a comma. - As shown in the example, any number such as shown (1.765000) should be shown without any following zeros), so shown as “1.765”.
- The 2nd new line will start with "SD ", followed by the number for horizAngle, a comma, then the number for zenithAngle, a comma and finally the number for horizDistance.
Now, from your first post it would seem that there are lots of different transformations you need to make. If they can all be represented as I’ve shown then it certainly is possible to provide you with regular expressions to make the changes.
It now lies with you to present the examples in code boxes, before and after in seperate boxes and to also present the transformations in a similar fashion to how I explained it. Unless you can be clear in your own mind and present the requests clearly you are going to be waiting a long time, and many back and forward posts such as this before you get a solution. It does seem that you need to solve this quicker rather than slower.
Terry
-
Your problem is kind of on the upper limit of reasonable things to automate in a macro; you could do that, but you almost certainly would be happier with a script written in a scripting language (and by this I mean a script outside of NPP, not something like a PythonScript script).
-
@Mark-Olson said in Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.:
and by this I mean a script outside of NPP, not something like a PythonScript script
Very good point. Actually every time I re-read the OP I get more info, but it’s so cluttered that I am getting to the point where I wonder if a regex solution would be robust enough.
Question to @Black-Fox:
This is very likely something that may have been achieved before. In all likelihood, the manufacturer of either your old equipment or new equipment may have produced a translation program to do exactly this. And if available, as a commercial product (yes you may have to pay for it) it will “guarantee” a correctly transformed file.Regular Expressions will not guarantee that. Every effort is made by us (the solution providers) but we give no guarantee!
Terry
-
I figured so that it would be to complicated to do this alone.
I actually have asked the software manager to help me, but he hasn’t done it yet (and i am waiting months) and everytime i am doing this all by myself manually…
As for the numbers, yes they are not part of the code, but i put them so to explain which line of Before corresponds to which line of After.Can i ask you one last thing? Can you write me 2 “expressions”?
- I want this:
<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“0.000000” horizAngle=“94.912866” zenithAngle=“81.131542” horizDistance=“17.044892” slopeDistance=“17.821968” directFace=“true” timeStamp=“2024-10-17T12:17:29”>
To be replaced with this :
94.912866,81.131542,17.821968
- and i want to select each of this so to be erased (the numbers are variables) :
” pntRef=“2@11”>1001.360583 1016.990502 106.695188</TargetPoint>
<Feature code=“observationInfo”>
<Property label=“TPSCorrectionRef” value=“3”/>
<Property label=“EDMType” value=“reflectorless”/>
<Property label=“reflectorName” value=“Reflectorless”/>
<Property label=“reflectorConstant” value=“0.034400”/>
</Feature>
</RawObservation>Again, thank you all. I’m so pressed by the time for this work and is a huge waste of my time doing it for each line…
-
@Black-Fox said in Search and replace Question - From LEICA.xml format to TOPCON.txt format for surveying.:
<RawObservation setupID=“TPSSetupID_S1_7” purpose=“normal” targetHeight=“0.000000” horizAngle=“94.912866” zenithAngle=“81.131542” horizDistance=“17.044892” slopeDistance=“17.821968” directFace=“true” timeStamp=“2024-10-17T12:17:29”>
To be replaced with this :
94.912866,81.131542,17.821968
First off, it would help greatly if you use the button that’s in the toolbar for foryum messages when posting the text of your data or proposed regular expressions. The forum software tends to mangle text to make it “prettier” for humans meaning what others can copy/paste from the forum for testing is not exactly what’s in your data. Just select some text and click the button. It will wrap the text in triple single back tick things. These are a clue to the forum software that it must not “prettify” or otherwise mangle the text.
As you did not use the magic button I’ll need to guess that you intended to post that
<RawObservation setupID="TPSSetupID_S1_7" purpose="normal" targetHeight="0.000000" horizAngle="94.912866" zenithAngle="81.131542" horizDistance="17.044892" slopeDistance="17.821968" directFace="true" timeStamp="2024-10-17T12:17:29">
should be transformed into
94.912866,81.131542,17.821968
I would do this one of two ways:
Search:(?-i)<RawObservation setupID="[^"]*" purpose="normal" targetHeight="[0-9]+\.[0-9]+" horizAngle="([0-9]+\.[0-9]+)" zenithAngle="([0-9]+\.[0-9]+)" horizDistance="[0-9]+\.[0-9]+" slopeDistance="([0-9]+\.[0-9]+)" directFace="true" timeStamp="20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]">
Replace:$1,$2,$3
or
Search:(?-i)<RawObservation setupID="[^"]*" purpose="normal" targetHeight="[0-9]+\.[0-9]+" horizAngle="(?'horizAngle'[0-9]+\.[0-9]+)" zenithAngle="(?'zenithAngle'[0-9]+\.[0-9]+)" horizDistance="[0-9]+\.[0-9]+" slopeDistance="(?'slopeDistance'[0-9]+\.[0-9]+)" directFace="true" timeStamp="20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]">
Replace:$+{horizAngle},$+{zenithAngle},$+{slopeDistance}
They are exactly the same expression but for the second version I used group names rather than group numbers. It makes the expressions easier for humans to read and follow.
As there is so much clutter in the previous messages I did not look to see if there are possible exceptions that I should account for in the search/replace I just posted. If the search part does not match 100% of the
RawObservation
things you have then post the exceptions, using the magic button, and we can help with dealing with those expression.I usually to a first test where I search for just
<RawObservation
and hit the count button. I make note of the count. I then write the long regular expression and check that it also matches exactly the same count as the original<RawObservation
. If not, I know there are exceptions I need to figure out and deal with. -
@mkupper Thank you! Thank you sooo much!
You saved me at least one hour of manually selecting and deleting!!!
Thank you all very much!