<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Betreff: Add a line of content into .txt file. in PowerMill Forum</title>
    <link>https://forums.autodesk.com/t5/powermill-forum/add-a-line-of-content-into-txt-file/m-p/13370176#M316</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14304290"&gt;@icse&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are right, I use method cmd to create a new .txt file and then I append this to the main txt file. This really fast.&lt;/P&gt;&lt;P&gt;Thank you for a suggestion.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Mar 2025 01:16:12 GMT</pubDate>
    <dc:creator>nguyenthinhvt95</dc:creator>
    <dc:date>2025-03-14T01:16:12Z</dc:date>
    <item>
      <title>Add a line of content into .txt file.</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/add-a-line-of-content-into-txt-file/m-p/13361438#M314</link>
      <description>&lt;P&gt;I have a problem need your help:&lt;/P&gt;&lt;P&gt;I create a txt file to count how many file export per month to report to boss.&lt;/P&gt;&lt;P&gt;the structure of content line in .txt file (show in the picture):&lt;/P&gt;&lt;P&gt;"Number count" , "Path project" , "extra infomation".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the moment I use foreach funtions to reach all line of .txt file and then use token by "," to get the final number.&lt;/P&gt;&lt;P&gt;It working well but it take really a long time to reach all line of .txt.&lt;/P&gt;&lt;P&gt;Is there any function that allows adding a new line of content to a TXT file, with the requirement that the added line must be on a new line compared to the existing content in the TXT?"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// DIALOGS MESSAGE OFF&lt;BR /&gt;// DIALOGS ERROR OFF&lt;BR /&gt;INT old_time = time()&lt;/P&gt;&lt;P&gt;STRING Link_txt = "A:\CAM\Macro\6.CSharp\5_All_in_one\Control\OpenPowermillFileData.txt"&lt;/P&gt;&lt;P&gt;STRING LIST $TXT_Data = {}&lt;BR /&gt;STRING LIST $TK_temp = {}&lt;/P&gt;&lt;P&gt;FILE OPEN $Link_txt FOR READ AS input&lt;BR /&gt;FILE READ $TXT_Data FROM input&lt;BR /&gt;FILE CLOSE input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;int $OpenCode = 0&lt;BR /&gt;int Check_Variable =0&lt;/P&gt;&lt;P&gt;//Tao 1 noi dung moi tu file ban dau. Xoa khoang trang va nap vao bien text&lt;BR /&gt;string text = "Total line: " + $size(TXT_Data)&lt;BR /&gt;int dem = 1&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;CREATE PATTERN ;&lt;BR /&gt;ACTIVATE Pattern #&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Foreach item In TXT_Data {&lt;BR /&gt;//Xóa khoảng trắng&lt;BR /&gt;if item != "" and $dem &amp;gt;= 2 {&lt;BR /&gt;$TK_temp = Tokens (item , ',')&lt;BR /&gt;// lay gia tri lon nhat&lt;BR /&gt;$Check_Variable = INT($TK_temp[0])&lt;BR /&gt;if OpenCode &amp;lt;= $Check_Variable {&lt;BR /&gt;$OpenCode = $Check_Variable&lt;BR /&gt;}&lt;BR /&gt;$Text = $Text + crlf + $item&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$dem = $dem + 1&lt;BR /&gt;string PatternNameOLD= $entity('pattern', '').name&lt;BR /&gt;string PatternNameNEW= "Read line: " + $dem&lt;/P&gt;&lt;P&gt;RENAME Pattern $PatternNameOLD $PatternNameNEW&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;DELETE Pattern $entity('pattern', '').name&lt;BR /&gt;//===================Check the last number and + 1======================================&lt;BR /&gt;$OpenCode = $OpenCode + 1&lt;/P&gt;&lt;P&gt;//===================Gom chuoi cu va moi thanh 1 file vao dien vao file txt===================&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//====================Date time :HH/MM/SS dd/mm/yy====================================================&lt;BR /&gt;INT tm=time()&lt;BR /&gt;STRING ARRAY $timestamp[] = tokens(utc_time($tm).timestamp, "-")&lt;BR /&gt;string hour = local_time(tm).hour&lt;BR /&gt;string date_full = $local_time(tm).hour + ":" + $local_time(tm).minute + "," + $timestamp[2] + "/" + $timestamp[1] + "/" + $timestamp[0] + "," + USER_ID()&lt;BR /&gt;//====================Date time====================================================&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;String value = $OpenCode + "," + $project_pathname(0) + "," + date_full&lt;BR /&gt;$Text = $Text + crlf + $value&lt;BR /&gt;//=====Write file again with updated=======&lt;BR /&gt;FILE OPEN $Link_txt FOR WRITE AS out&lt;BR /&gt;FILE WRITE $text to out&lt;BR /&gt;FILE CLOSE out&lt;/P&gt;&lt;P&gt;EDIT PAR 'project.Notes.' ""&lt;BR /&gt;EDIT PAR 'project.Notes.' $OpenCode&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//=========================check total line and keep line the line ==============================&lt;/P&gt;&lt;P&gt;int SizeOfFile = size(TXT_Data)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//=========================input the number of line want to keep ==============================&lt;BR /&gt;int LineKeepNumber = 300&lt;BR /&gt;//=========================input the number of line want to keep ==============================&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;int Startline = SizeOfFile - LineKeepNumber&lt;BR /&gt;if SizeOfFile &amp;gt; LineKeepNumber {&lt;/P&gt;&lt;P&gt;FILE OPEN $Link_txt FOR READ AS input&lt;BR /&gt;FILE READ $TXT_Data FROM input&lt;BR /&gt;FILE CLOSE input&lt;/P&gt;&lt;P&gt;$text = "Total line: " + $size(TXT_Data)&lt;BR /&gt;int dem_line = 1&lt;/P&gt;&lt;P&gt;Foreach item In TXT_Data {&lt;BR /&gt;if $dem_line &amp;gt; Startline {&lt;BR /&gt;$Text = $Text + crlf + $item&lt;BR /&gt;}&lt;BR /&gt;$dem_line = $dem_line + 1&lt;BR /&gt;}&lt;BR /&gt;//=====Write file again with updated=======&lt;BR /&gt;FILE OPEN $Link_txt FOR WRITE AS out&lt;BR /&gt;FILE WRITE $text to out&lt;BR /&gt;FILE CLOSE out&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;INT cumulative_time = time() - old_time&lt;BR /&gt;STRING msg = "Open code process took " + (cumulative_time) + "secs"&lt;BR /&gt;print $msg&lt;/P&gt;&lt;P&gt;DIALOGS MESSAGE ON&lt;BR /&gt;DIALOGS ERROR ON&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 04:49:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/add-a-line-of-content-into-txt-file/m-p/13361438#M314</guid>
      <dc:creator>nguyenthinhvt95</dc:creator>
      <dc:date>2025-03-10T04:49:03Z</dc:date>
    </item>
    <item>
      <title>Betreff: Add a line of content into .txt file.</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/add-a-line-of-content-into-txt-file/m-p/13361888#M315</link>
      <description>&lt;P&gt;if oyu whant to append text to a file you use this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;string $filepath = "C:\test.txt"
string $txttoappend = "This should be added to the file as new line"

FILE OPEN $filepath FOR APPEND AS output
FILE WRITE $txttoappend TO output
FILE CLOSE output&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if reading and handle entries in that file is to slow in the powermill macro language consider using a simple C# application.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 10:46:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/add-a-line-of-content-into-txt-file/m-p/13361888#M315</guid>
      <dc:creator>icse</dc:creator>
      <dc:date>2025-03-10T10:46:54Z</dc:date>
    </item>
    <item>
      <title>Betreff: Add a line of content into .txt file.</title>
      <link>https://forums.autodesk.com/t5/powermill-forum/add-a-line-of-content-into-txt-file/m-p/13370176#M316</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14304290"&gt;@icse&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are right, I use method cmd to create a new .txt file and then I append this to the main txt file. This really fast.&lt;/P&gt;&lt;P&gt;Thank you for a suggestion.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2025 01:16:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/powermill-forum/add-a-line-of-content-into-txt-file/m-p/13370176#M316</guid>
      <dc:creator>nguyenthinhvt95</dc:creator>
      <dc:date>2025-03-14T01:16:12Z</dc:date>
    </item>
  </channel>
</rss>

