# Read txt file coordinate

**URL:** <https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816>\
**Category:** RAPID Programming\
**Created:** [March 5, 2025, 9:04am UTC](https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816 "2025-03-05T09:04:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoanghuy07zz](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hoanghuy07zz](https://tech-community.robotics.abb.com/u/hoanghuy07zz)\
**Post date:** [March 5, 2025, 9:04am UTC](https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816/1 "2025-03-05T09:04:33Z")

</div>

Hello everyone  
I am just starting to work on a project using ABB Yumi robot to do soldering. Since this is an automated system, it is not possible to jog each point, I have created a .txt file on Home and used RAPID to read that file. However, I am having difficulty in reading that file and assigning values ​​from the file to the variables x, y, z. Here is my code:

PROC WeldingMotion(num x, num y, num z)  
MoveL offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;  
WaitTime 0.5;  
MoveL offs(Temp, x, y, z), v100, fine, Servo\WObj:=wobj0;  
WaitTime 0.5;  
PulseDO signal1;  
WaitTime 1.5;  
MoveL offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;  
ENDPROC

PROC ReadAndWeld()  
Open “HOME:” \File:= “han.txt”, infile\Read;  
WHILE i\<4 DO  
text := ReadStr(infile\Delim:=“,”\RemoveCR);  
IF text = “EOF” THEN  
EXIT;  
ENDIF  
x := ReadNum(infile);  
text := ReadStr(infile\Delim:=“,”\RemoveCR);  
IF text = “EOF” THEN  
EXIT;  
ENDIF  
y := ReadNum(infile);  
text := ReadStr(infile\Delim:=“\0d”\RemoveCR);  
IF text = “EOF” THEN  
EXIT;  
ENDIF  
z := ReadNum(infile);  
WeldingMotion x, y, z;  
text := ReadStr(infile);  
i := i + 1;  
ENDWHILE  
ENDPROC

Please let me know if you have a solution  
Best Regards

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [March 5, 2025, 1:06pm UTC](https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816/2 "2025-03-05T13:06:32Z")

</div>

On first glance I see that your handling of EOF is problematic. Using the EXIT instruction will cause the program pointer to be discarded. Please see my blog here:  
[https://www.robot-forum.com/blog/entry/4-another-program-that-writes-a-program/](https://www.robot-forum.com/blog/entry/4-another-program-that-writes-a-program/)  
for an example of file handing and examples of extracting data from them. I hope that you find it useful.

---

<div class="post-metadata">

**Author:** ![hoanghuy07zz](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hoanghuy07zz](https://tech-community.robotics.abb.com/u/hoanghuy07zz)\
**Post date:** [March 5, 2025, 3:43pm UTC](https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816/3 "2025-03-05T15:43:14Z")

</div>

Thanks for your help!  
But actually I read your Blog about this issue but really don’t understand much. Maybe because RAPID code is too new to me. If possible, please help me assign the x, y, z values ​​of the file. Thank you very much.Type your comment

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [March 5, 2025, 3:52pm UTC](https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816/4 "2025-03-05T15:52:40Z")

</div>

I have no idea what your file looks like. Also, have you considered using a .csv file?

---

<div class="post-metadata">

**Author:** ![hoanghuy07zz](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hoanghuy07zz](https://tech-community.robotics.abb.com/u/hoanghuy07zz)\
**Post date:** [March 5, 2025, 3:58pm UTC](https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816/5 "2025-03-05T15:58:45Z")

</div>

I tried with .txt file its content is simply:  
-47.45241327,-49.76916306,-106.452481  
-47.45216231,49.29770462,-106.4528332  
50.27137845,49.29752072,-106.4529469  
50.27139316,-48.08475086,-106.4531297  
Also, after consulting some commands, I changed my code as follows:  
MODULE WeldingModule  
VAR iodev infile;  
VAR string strRead;  
CONST string EOF := “EOF”;  
VAR num x;  
VAR num y;  
VAR num z;  
VAR bool bEmptyFile := FALSE;  
CONST robtarget Temp := [[398.325199305, 0.258359649, 229.351914078],  
[0.008778554, -0.708013571, 0.70614426, 0.000073994],  
[1, -2, 0, 4],  
[-125.311648719, 9E+09, 9E+09, 9E+09, 9E+09, 9E+09]];

PROC main()  
MoveL Temp, v100, fine, Servo\WObj:=wobj0;  
ReadAndWeld;  
ENDPROC

PROC WeldingMotion(num x, num y, num z)  
MoveL Offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;  
WaitTime 0.5;  
MoveL Offs(Temp, x, y, z), v100, fine, Servo\WObj:=wobj0;  
WaitTime 0.5;  
MoveL Offs(Temp, x, y, z+10), v100, fine, Servo\WObj:=wobj0;  
ENDPROC

PROC ReadAndWeld()  
! Open the file to read  
Open “HOME:” \File:= “han.txt”, infile \Read;

WHILE bEmptyFile = FALSE DO  
strRead := ReadStr(infile \RemoveCR);  
IF strRead \<\> EOF THEN  
x := StrToVal(StrPart(strRead, 1, StrFind(strRead, “,”) - 1));  
strRead := StrPart(strRead, StrFind(strRead, “,”) + 1);  
y := StrToVal(StrPart(strRead, 1, StrFind(strRead, “,”) - 1));  
strRead := StrPart(strRead, StrFind(strRead, “,”) + 1);  
z := StrToVal(strRead);  
WeldingMotion x, y, z;  
ELSE  
bEmptyFile := TRUE;  
ENDIF  
ENDWHILE  
Close infile;  
ENDPROC  
ENDMODULE

But it still doesn’t work, there’s only a little time left until my exam. I really hope you can help me solve it.  
Best regards

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [March 5, 2025, 4:34pm UTC](https://tech-community.robotics.abb.com/t/read-txt-file-coordinate/11816/6 "2025-03-05T16:34:37Z")

</div>

It looked like in your first trial you were tying to use a delimiter “,” for a comma. It should be ASCII Hex for the , character. Stick with the ReadNum. I suspect that you are running the program instead of stepping line by line. Step line by line, pausing to examine the values that are being evaluated and written. It is the best way to debug.
