cancel
Showing results for 
Search instead for 
Did you mean: 

TCL : add information

Genius
Genius

hello ,

 

I want to add information in my clsfile on each load/tool :

I have two files

First file : info.txt

Second file : 1001.cls

Problem

my line is added and not replaced
and my second problem in my output file, the lines are not replaced according to the tool number

 

thanks for the support

 

info.txt :

#-----------------------------------------------------------------------------
OUTIL                     IE           IF       
#-----------------------------------------------------------------------------
LOAD/TOOL,1,ADJUST,1      2050         1500
LOAD/TOOL,2,ADJUST,2      3500         1200             
LOAD/TOOL,14,ADJUST,14    8850         1600

1001.cls :

 

TOOL PATH/TC-FR-DIA32-R0.8,TOOL,TC-FR-DIA32-R0.8
LOAD/TOOL,1,ADJUST,1
...
...
...
TOOL PATH/TC-FR-DIA40-R0.8,TOOL,TC-FR-DIA40-R0.8
LOAD/TOOL,2,ADJUST,2
...
...
...
TOOL PATH/TC-FR-DIA20-R0.8,TOOL,TC-FR-DIA20-R0.8
LOAD/TOOL,14,ADJUST,14
...
...
...
TOOL PATH/TC-FR-DIA32-R0.8,TOOL,TC-FR-DIA32-R0.8
LOAD/TOOL,1,ADJUST,1

Finally I would like my cls file looks like this:

TOOL PATH/TC-FR-DIA32-R0.8,TOOL,TC-FR-DIA32-R0.8
LOAD/TOOL,1,ADJUST,1,2050,1500
...
...
...
TOOL PATH/TC-FR-DIA40-R0.8,TOOL,TC-FR-DIA40-R0.8
LOAD/TOOL,2,ADJUST,2,3500,1200
...
...
...
TOOL PATH/TC-FR-DIA20-R0.8,TOOL,TC-FR-DIA20-R0.8
LOAD/TOOL,14,ADJUST,14,8850,1600
...
...
...
TOOL PATH/TC-FR-DIA32-R0.8,TOOL,TC-FR-DIA32-R0.8
LOAD/TOOL,1,ADJUST,1,2050,1500

 

my code :

 

set fin [open "info.txt" r]
set fout [open "1001.cls" r+]

while {![eof $fout]} {

set data [gets $fin]
set match [ string match {*LOAD/TOOL*} $data]

set ligne [gets $fout]
set record [ string match {*LOAD/TOOL,*} $line]

if {$match == 1} {
set info [join $data ,]
} 
if {$record == 1 } {
set lg [llength $line]
set ligne [string replace $line $lg end $info]
puts  $fout $ligne
}
}
}
close $fout
close $fin

 

@mkn
2 REPLIES

Re: TCL : add information

Valued Contributor
Valued Contributor

You have a } too many to start with.

You read one line at a time in both files. Why not read in the info file first into a list and try to match these with the cls?

You have not put anything into $line before you use it.

Search around on the tcl wiki  for help on tcl with examples.

W10 NX11.0.1

Re: TCL : add information

Genius
Genius

I have not checked my code before posting, actually too many}.
yes, I have realized a different code since Monday, first I read all my info.txt and not line by line, then I realized a temporary file 1001.cls.
Finally, my code looks like this:

not optimized, but it works

set fout [open "1001.cls" r]
set out [open "1001.tmp" w]

while {![eof $fout]} {

set ligne [gets $fout]
set record [ string match {*LOAD/TOOL*} $line]
	
if {$record == 1 } {

# my code 

set fin [open "info.txt r]
set fd [read $fin]
close $fin

 foreach line $fd {
# my code 

 }
 }
 }

 close $fout
 close $out

file rename -force "1001.tmp" "1001.cls"

 

@mkn

Learn online





Solution Information