[Zo...] Posted May 2, 2023 Share Posted May 2, 2023 I am trying to use a point list file that is created by our cad software for curve profile the file has some comments at the start in order to use this file, i need to delete the lines with "//" at the start i was thinking to read each line parse the first section if equal to "//" then skip else write to new file however, i fail to parse the lines with an error _see below_ I tried some other codes and none could execute properly, also x == "//" then is not a valid argument _sees // as start of comment the only thing that worked, was trimming a set number of lines but this will cause issues if files across different part families have different lines of comments it would only work if i could count the number of lines starting with "//" Link to comment Share on other sites More sharing options...
[He...] Posted May 2, 2023 Share Posted May 2, 2023 There can be a number of causes for this. I have really struggled with files with dual slashes because that is the same method for masking as PCM uses and that sometime causes problems. I know I solved a similar problem a few years ago but I don't remebmer how much workarounds was needed. It can also be that the file format is not what Calypso wants to read. Do you think you can post the file itself instead of just a screenshot so we might work with the actual file? Link to comment Share on other sites More sharing options...
[Fl...] Posted May 3, 2023 Share Posted May 3, 2023 Hi, i think it could work if you use the ASCII code (chr(47)) instead of / also it may be better to not create a parameter with // in its string. maybe something like this, only that you have to input the actual line of your file if (strElement(1," ",chr(47) + chr(47) + " ITEM 12162694 - REV 0")) == (chr(47) + chr(47)) then else endif regards Link to comment Share on other sites More sharing options...
[Je...] Posted May 3, 2023 Share Posted May 3, 2023 Execute the parsing routine in a standard CALYPSO *.bat file. This will allow you to ignore the "//" that is difficult to remove from PCM Link to comment Share on other sites More sharing options...
[Zo...] Posted May 4, 2023 Author Share Posted May 4, 2023 Please sign in to view this quote. file has .para extension, I added .tx to be able to attach it here12177740_1_fof_zeiss_15_ms_x_plus.para.txt Link to comment Share on other sites More sharing options...
[Zo...] Posted May 4, 2023 Author Share Posted May 4, 2023 Please sign in to view this quote. (strElement(1," ",chr(47) + chr(47)) Will always return "//" i am trying to test any string and see if it starts with "//" i tried code below but but i keep getting the same error A = readListFile(Curve_File_Plus) B = len(A) for i = 1 to B D = subStr(A,i,i) D= text(D) F = strElement(1," ",D) if F == (chr(47) + chr(47)) then ....... else endif next Link to comment Share on other sites More sharing options...
[Zo...] Posted May 4, 2023 Author Share Posted May 4, 2023 Please sign in to view this quote. can you elaborate a bit, please? i have never used *.bat file other than simple runend.bat xcopy c:\SPC Temp\*_chr.txt c:\CNCFeedbackData\ /c /a /r /y xcopy c:\SPC Temp\*_hdr.txt c:\CNCFeedbackData\ /c /a /r /y xcopy c:\SPC Temp\*.txt c:\spcdata\ /c /m /r /y do i use PCM commands or is this written in different code? if so, do you know where i can get few example of parsing so i can edit? Link to comment Share on other sites More sharing options...
[Je...] Posted May 4, 2023 Share Posted May 4, 2023 Batch file scripting is not PCM as it is a native function of Windows. It uses Windows CMD language syntax. It is a powerful tool to learn for many Windows functions for file manipulation. http://www.StackOverflow.com is a great place to start. https://stackoverflow.com/questions/852 ... place-text It should be something similar to the following where input_file and output_file are the files you are looking to edit. If these vary you will need adjust the parameters for setting that name as necessary. This requires that the batch file be in the same directory as the input_file directory as well. Deviation from that setup will require further edits. disclaimer - this code is absolutely untested and whatever text used from it is totally at your own risk; @echo off setlocal EnableDelayedExpansion set input_file=input.txt set output_file=output.txt if not exist "%input_file%" ( echo Input file not found: "%input_file%" goto :EOF ) set "exclude=^//" (for /F "usebackq delims=" %%a in ("%input_file%") do ( set "line=%%a" set "line=!line:%exclude%=!" if defined line echo !line! )) > "%output_file%" echo Done. Output written to: "%output_file%" You can review the PCM pdf manuals contained on your system for the proper naming of the .bat file and proper directory placement for automatic execution (should be around page 1-28 depending on your CALYPSO version) Link to comment Share on other sites More sharing options...
[Wa...] Posted May 4, 2023 Share Posted May 4, 2023 If all of the files resemble the one you posted, you can check the first character of every line in the file instead of checking for the "//"? I was able to use the following to create a new file that only contained the numerical data. itemNumber = 1234 CurveFileEdited = "C:\CurveParameter\" + itemNumber + "_x_plus_Edited.para" CurveFile = "C:\CurveParameter\" + itemNumber + "_x_plus.para" if fileExists(CurveFileEdited) then //do nothing else A = readListFile(CurveFile) B = len(A) for i = 1 to B if inStr(getParameterNamed(A,i),"/") == 1 then //do Nothing else //Add line to edited file addToFile(CurveFileEdited, getParameterNamed(A,i)) endif next i endif Link to comment Share on other sites More sharing options...
[Zo...] Posted May 4, 2023 Author Share Posted May 4, 2023 Please sign in to view this quote. you are a genius plugged it in, an works like a charm. removes the comment lines and delete duplicate points 🙂 clearParameter() Item_Number = "Curve_test" Curve_File_Plus_Edited = "K:\NGOM\Cavity\Cavity_Parameter\" + Item_Number + "\" + Item_Number + "_fof_zeiss_15_ms_x_plus_Edited.para" Curve_File_Plus_Temp = "K:\NGOM\Cavity\Cavity_Parameter\" + Item_Number + "\" + Item_Number + "_fof_zeiss_15_ms_x_plus_Temp.para" Curve_File_Plus = "K:\NGOM\Cavity\Cavity_Parameter\" + Item_Number + "\" + Item_Number + "_fof_zeiss_15_ms_x_plus.para" if fileExists(Curve_File_Plus_Edited) then //Do Nothing else A = readListFile(Curve_File_Plus) // read NX output B = len(A) // find file length for i=1 to B //Remove comment Lines if inStr(getParameterNamed(A,i),"/") == 1 then //Do Nothing else addToFile(Curve_File_Plus_Temp, getParameterNamed(A,i)) //write to Temp File endif next i A = readListFile(Curve_File_Plus_Temp) // read Temp file B = len(A) D = subStr(A,1,1) //extract first line E = text(D) // convert to text x = strElement(1," ",E) // extract first parse - "X" value y = strElement(2," ",E) // extract second parse - "Y" value z = strElement(3," ",E) // extract third parse - "Z" value I = strElement(4," ",E) // extract forth parse - "i" value J = strElement(5," ",E) // extract fifth parse - "j" value K = strElement(6," ",E) // extract sixth parse - "k" value K = mid(K,1,3) // trim line break addToFile(Curve_File_Plus_Edited ,x + " " + y + " " + z + " " + I + " " + J + " " + K) // write frist line into the file for i=1 to B-1 // compare for Duplicate Points D1 = subStr(A,i,i) E1 = text(D1) x1 = strElement(1," ",E1) y1= strElement(2," ",E1) z1 = strElement(3," ",E1) D2 = subStr(A,i + 1,i + 1) E2 = text(D2) x2 = strElement(1," ",E2) y2 = strElement(2," ",E2) z2 = strElement(3," ",E2) I2 = strElement(4," ",E2) J2 = strElement(5," ",E2) K2 = strElement(6," ",E2) K2 = mid(K2,1,3) if x2 == x1 and y2 == y1 and z2 == z1 then //Do Nothing else addToFile(Curve_File_Plus_Edited ,x2 + " " + y2 +" " + z2 + " " + I2 + " " + J2 + " " + K2) endif next i deleteFile(Curve_File_Plus_Temp) //Delete Temp File endif Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in