> that sounds good. But I think you sent me the same file as before?
> They are exactly alike.

Just checked, and I did send a newer version, I even added a 0.2 version number in the header. Here it is version 0.3.

On 2016-03-25 01:53 AM, João Pais wrote:
Hi,

I tinkered around with tcl, until I think I found a version that suits
my needs exactly:

- I reversed the selection - if {[lsearch $lineList $lineCount] < 0} {
- I commented out line  puts "lines to patch: $lineList", so that the
list of patched lines doesn't get saved with the patch output.


It seems that the patch counts each line that begins with # as a real
line. But since the pd txt format splits lines, it turns out that there
are many lines that don't begin with #N. For example with the 2 objects

#N canvas 1066 230 670 662 gui 0;
#X obj 0 0 cnv 12 400 260 empty \$0-colorh-i empty 20 12 0 14 -220796
-1 0;

there are 3 lines in the text file, but the patch will only count 2.
Adding an incr lineCount after the last "puts $patchLine" does the job
of matching the number of lines in the text file with the line count.

Sorry, the script was counting Pd-lines, not lines in the patch. Not much use if you look at the lines in a code-editor. If a line increment is done always, you could move it outside the if ...

Counting Pd-lines is useful if you want to correlate objects to the '#X connect' lines. But this would break down in case of sub-patches. I made another script for this...

Thanks very much, I think this is quite good already. I'll tinker a bit
more to see if I find out how to also process subpatches and messages. I
imagine that adding other if lines it could work.

The newer versions should be better as they prevent #A and #N from being corrupted.

Best,

Joao


#!/usr/bin/env tclsh
#
# changeCoords.tcl v0.3
# fjkr...@xs4all.nl

if {$argc < 4} {
    error "Usage: tclsh changeCoords.tcl patchName xcoord ycoord line1 ?line2? ..."
}

set patchName [lindex $argv 0]
set xcoord    [lindex $argv 1]
set ycoord    [lindex $argv 2]
set lineArgCount $argc
set lineList {}

#puts "patchName $patchName; xcoord $xcoord; ycoord $ycoord lineArgCount; $lineArgCount"
# line arguments may be numeric or a numeric range "nn-mm" (inclusive)

for {set start 3} {$lineArgCount > $start} {incr start} {
        set arg [lindex $argv $start]
#        puts "$start: $arg"
        if [regexp {(\d+)-(\d+)} $arg lineRange startLine endLine] {
                if {$startLine < $endLine} {
#                        puts "startLine $startLine; endLine $endLine;;  $lineRange"
                        for {set line $startLine} {$line <= $endLine} {incr line} {
                                lappend lineList $line
                        }
                }
        } else {
#                puts "line $arg"
                lappend lineList $arg
        }
}

#puts "lines not to patch: $lineList"

set lineCount 1
set f [open $patchName]
while {[gets $f patchLine] >= 0} {
    if [regexp {\#[AN] } $patchLine] {
#        puts -nonewline "$lineCount: "
        puts $patchLine
        incr lineCount
        continue
    }
    if [regexp {\#[X] } $patchLine] {
        if {[lsearch $lineList $lineCount] == -1} { # >= 0 for matching lines, == -1 for non-matching lines
            if [regexp {\#X obj (\d+) (\d+) (.+)} $patchLine allOfLine orgX orgY restOfLine] {
#                puts -nonewline "$lineCount: "
                puts "#X obj $xcoord $ycoord $restOfLine"
            } else {
#                puts -nonewline "$lineCount: "
                puts $patchLine
            }
        } else {
#            puts -nonewline "$lineCount: "
            puts $patchLine
        }
    } else {
#         puts -nonewline "$lineCount: "
         puts $patchLine
    }
    incr lineCount

}
close $f
_______________________________________________
Pd-list@lists.iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to