Topic: Simple Mail Merge Macro (1 of 8), Read 75 times
Conf: VEDIT User Applications
From: Timothy Lawler
Date: Thursday, May 20, 2004 04:50 PM

I am a novice as it relates to Vedit's Macro Capabilities. I am trying to create a script file for AutoCAD that would be generated by merging data in one file with another to create a script which in-turn creates a drawing. Has anyone written a macro with this type of capability? If so would you be interested in sharing it?

Open a new file file3

Foreach line in file1
Merge data from file1 with file2
append results to file3

Close file3


Thanks in advance,

Tim Lawler
thlawler@...

 


Topic: Re: Simple Mail Merge Macro (2 of 8), Read 60 times
Conf: VEDIT User Applications
From: Fritz Heberlein
Date: Friday, May 21, 2004 07:03 PM

> I am a novice as it relates to Vedit's Macro Capabilities.
[...]
> Foreach line in file1
> Merge data from file1 with file2
> append results to file3
>
> Close file3

Your subject Line reminds me that I had a *very* basic mail
merge macro for Latex some years ago. Unfortunately, i cannot find it
any more. But the basics would be something like the following (out
of memory, untested):

0. let's assume you have

a. an adress file "adr.txt" that contains entries of the Type

\adress{F. Heberlein
Universitätsallee 1
85071 Eichstätt}

b. a file "body.txt" containing the letter body

Then:

-------------------------------------------------------

// 1. Check if adress file is open; if not open it

#61=File_Check("adr.txt")
if(#61 > 0) { File_Open("adr.txt") }

// 2. (a) check for file containing letter body
(b) copy contents to a TReg, say, @9
(c) switch back to adr.txt

#62=File_Check("body.txt")
if(#62 > 0) {
File_Open("body.txt")
Reg_Copy_Block(9,0,File_Size)
Buf_Switch(#61) // switch back to adr.txt
}

// 3. open output file in a free buffer

Buf_Switch(BufFree)
#63=BufNum
file_save_as("output.txt",OK)
Buf_switch(#61) // switch back to adr.txt

// 4. merge adresses and body of text

repeat(ALL) {
Search("\adress{|m}",ADVANCE+ERRBREAK) //a. match entire adress
entry
Block_Begin(BOL_Pos) //b. mark it as block and
Match_Paren()
Reg_Copy_Block(10,Block_Begin,Cur_Pos+1) //c. copy it to TREG @10
buf_switch(#63) //d. switch to output.txt
insnewline(2)
Reg_Ins(10) //e. insert adress
insnewline()
Reg_Ins(9) //f. and text body
buf_switch(#61) //g. switch back to adr.txt
}

// 5. save result file

Buf_switch(#63)
file_save(BEGIN)

Fritz

 


Topic: Re: Simple Mail Merge Macro (3 of 8), Read 59 times
Conf: VEDIT User Applications
From: Timothy Lawler
Date: Friday, May 21, 2004 10:55 PM

Fritz,

Thanks for the help I will study this and try to make it work.

Best regards,

Tim Lawler
thlawler@...

 


Topic: Re: Simple Mail Merge Macro (4 of 8), Read 61 times
Conf: VEDIT User Applications
From: Christian Ziemski
Date: Saturday, May 22, 2004 02:52 AM

Hello Timothy!

Nice to see you as a new user here at WebBoard!


Hello Fritz!

Nice to see you back!

I don't want to interfere with your discussion but
please let me do some comments.

(Fritz, I know you wrote from memory!)



>// 1. Check if adress file is open; if not open it
>
>#61=File_Check("adr.txt")
>if(#61 > 0) { File_Open("adr.txt") }

File_Check() returns -1 if file isn't already open.
==> if(#61 < 0)

But perhaps you meant File_Exist() ?

if (File_Exist("adr.txt")) {
File_Open("adr.txt")
#61=Buf_Num
} else {
// do some error handling
}

The File_Open() handles it automatically if the file is already
loaded.



>// 2. (a) check for file containing letter body
> (b) copy contents to a TReg, say, @9
> (c) switch back to adr.txt
>
>#62=File_Check("body.txt")
>if(#62 > 0) {
> File_Open("body.txt")
> Reg_Copy_Block(9,0,File_Size)
> Buf_Switch(#61) // switch back to adr.txt
> }

Or something like this:

if (File_Exist("body.txt")) {
Reg_Load(9, "body.txt") // load file contents directly into text
register
} else {
// do some error handling
}



>// 4. merge adresses and body of text
>
>repeat(ALL) {
>Search("\adress{|m}",ADVANCE+ERRBREAK) //a. match entire adress entry
>Block_Begin(BOL_Pos) //b. mark it as block and

Doesn't that include "\adress" too?

>Match_Paren()
>Reg_Copy_Block(10,Block_Begin,Cur_Pos+1) //c. copy it to TREG @10


Perhaps this way:

Search("\adress|H7B",ADVANCE+ERRBREAK) // search address (incl.
open curly brace)
Block_Begin(Cur_Pos) // set block begin just
after open brace
Char(-1) // pos. on open brace
Match_Paren() // and search closing one
Block_End(Cur_Pos) // set block begin just
before closing brace
Reg_Copy_Block(10,Block_Begin,Block_End) // copy it to TREG @10
Block_Begin(CLEAR) // clear block markers


Happy programming!

Christian

 


Topic: Re: Simple Mail Merge Macro (5 of 8), Read 62 times
Conf: VEDIT User Applications
From: Fritz Heberlein
Date: Saturday, May 22, 2004 05:56 AM

Christian:

Thanks for your corrections!

> >// 4. merge adresses and body of text
> >
> >repeat(ALL) {
> >Search("\adress{|m}",ADVANCE+ERRBREAK) //a. match entire adress
> >entry Block_Begin(BOL_Pos) //b. mark it as block
> >and
>
> Doesn't that include "\adress" too?

Yes, it does - I needed to copy the entire expression (command +
adress).

Thanks and regards,

Fritz


--
Dr. Friedrich Heberlein, Akad. Direktor
Seminar für Klassische Philologie, KU Eichstaett-Ingolstadt
Universitaetsallee 1
D-85071 Eichstaett / Bayern

 


Topic: Re: Simple Mail Merge Macro (6 of 8), Read 68 times
Conf: VEDIT User Applications
From: Peter Rejto
Date: Monday, June 07, 2004 03:38 PM

Gentlemen,

If I understand your macro correctly, functionally, it is similar to the Latex letter environment? Since this environment works fine for me, I plan to continue using it.

Hence, my interest in your macro is strictly diagnostic. This is certainly the first Latex macro which I have seen transplanted into Vedit. So, a big welcome. I hope that many more will follow!

-peter.

 


Topic: Simple Mail Merge Macro (7 of 8), Read 62 times
Conf: VEDIT User Applications
From: Ian Binnie
Date: Monday, June 07, 2004 09:02 PM

On 5/20/2004 4:50:41 PM, Timothy Lawler wrote:
>I
>am trying to create a script
>file for AutoCAD that would be
>generated by merging data in
>one file with another to
>create a script which in-turn
>creates a drawing.

Your description of what you want to do is rather vague.

If all you are trying to do is append the contents of a number of files this can be done very easily with DOS COPY using the append option.

 


Topic: Simple Mail Merge Macro (8 of 8), Read 55 times
Conf: VEDIT User Applications
From: Peter Rejto
Date: Wednesday, June 09, 2004 06:40 PM

Hello Timothy:

How are you doing?

Please keep me posted.

-peter.