Author Topic: Write to text file with incrementing text  (Read 5690 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Write to text file with incrementing text
« on: November 16, 2005, 05:53:22 PM »
I'm creating a photo gallery of a trip I just got back from on my website.  I've been learning HTML recently, and this is what I've come up with:

Code: [Select]
<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_002.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_002.jpg' width=100 height=75 border=0></a>
<br>002</td>

Now, all the pictures follow that naming format:  Louisville_XXX.jpg

Can LISP write that 51 times, incrementing any instance of the number?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #1 on: November 16, 2005, 05:57:16 PM »
Yep, but why use lisp?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Write to text file with incrementing text
« Reply #2 on: November 16, 2005, 06:03:11 PM »
Yep, but why use lisp?

To further my knowledge of LISP.  I don't want to copy, paste, find, replace, repeat...If you have any other suggestions, do share.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #3 on: November 16, 2005, 06:13:58 PM »
It's just that it's not a cadd app that's all. You could do it in vb, vba, vbscript, python yada ... I just wondered why you chose lisp.

Play with this --

Code: [Select]
(defun c:Test  ( / rset foo main )

    (defun rset ( text padding maxlen )
        (substr
            (   (lambda ( )
                    (while 
                        (<
                            (strlen (setq padding (strcat padding padding)))
                            maxlen
                        )
                    )
                    (setq text (strcat padding text))                               
                )
            )
            (- (strlen text) (1- maxlen))
        )
    )

    (defun foo ( integer / integerAsPaddedString )       
        (strcat
            "<td>"
            "<a href='http://home.comcast.net/~dominic.cesare"
            "/pictures/Louisville/Louisville_"
            (setq integerAsPaddedString (rset (itoa integer) "000" 3))
            ".jpg' title='Click to enlarge'>\n"
            "<img src='http://home.comcast.net/~dominic.cesare"
            "/pictures/Louisville/Louisville_"
            integerAsPaddedString
            ".jpg' width=100 height=75 border=0></a>\n"
            "<br>"
            integerAsPaddedString
            "</td>\n"
        )   
    )   

    (defun main ( / i )   
        (setq i 0)       
        (repeat 51
            (princ
                (foo
                    (setq i (1+ i))
                )
            )
        )       
        (princ)   
    )
   
    (main)
   
)

Obviously you could modify it so it writes to file etc. but I decided to keep it relatively simple.

(Warning, very Q&D).

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Write to text file with incrementing text
« Reply #4 on: November 17, 2005, 09:32:42 AM »
I appreciate it.  Like I said, I figured this is something that I could do with LISP, and in doing so, learn about expressions I haven't used before, and how I can apply them in the future.  As far as the other program languages:  I'm a newb.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Write to text file with incrementing text
« Reply #5 on: November 17, 2005, 09:38:31 AM »
Just tried it, works great!  I will add in the write to file portion later today.  I'll have to mess with the output a little bit to get blank lines between entries, like so:

Code: [Select]
<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_014.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_014.jpg' width=100 height=75 border=0></a>
<br>014</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_015.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_015.jpg' width=100 height=75 border=0></a>
<br>015</td>

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #6 on: November 17, 2005, 09:49:33 AM »
Glad to hear D2H. Just let me know if / when you need another nudge.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Write to text file with incrementing text
« Reply #7 on: November 17, 2005, 10:09:08 AM »
Glad to hear D2H. Just let me know if / when you need another nudge.

I might will need some help...maybe

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #8 on: November 17, 2005, 10:49:25 AM »
I might will need some help...maybe

Extra carriage returns, writing output to file ... ??

Let me know what and I'll try to help.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Write to text file with incrementing text
« Reply #9 on: November 17, 2005, 11:00:12 AM »
I might will need some help...maybe

Extra carriage returns, writing output to file ... ??

Let me know what and I'll try to help.

:)

I think I can figure the rest out, but I also like to reverse engineer code (saves time :wink:).  Basically, I'm grouping the pictures 6 to a row, and my html file looks like this:
Code: [Select]
<tr valign=top align=center>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_002.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_002.jpg' width=100 height=75 border=0></a>
<br>002</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_003.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_003.jpg' width=100 height=75 border=0></a>
<br>003</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_004.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_004.jpg' width=100 height=75 border=0></a>
<br>004</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_005.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_005.jpg' width=100 height=75 border=0></a>
<br>005</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_006.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_006.jpg' width=100 height=75 border=0></a>
<br>006</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_007.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_007.jpg' width=100 height=75 border=0></a>
<br>007</td>

</tr>

<tr valign=top align=center>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_008.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_008.jpg' width=100 height=75 border=0></a>
<br>008</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_009.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_009.jpg' width=100 height=75 border=0></a>
<br>009</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_010.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_010.jpg' width=100 height=75 border=0></a>
<br>010</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_011.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_011.jpg' width=100 height=75 border=0></a>
<br>011</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_012.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_012.jpg' width=100 height=75 border=0></a>
<br>012</td>

<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_013.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_013.jpg' width=100 height=75 border=0></a>
<br>013</td>

</tr>

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #10 on: November 17, 2005, 12:42:03 PM »
Code: [Select]
(defun C:TryThis ( / replace lset main )

    (defun replace ( oldText newText text / i )
        (if (/= oldText newText)
            (while (setq i (vl-string-search oldText text))
                (setq text
                    (vl-string-subst
                        newText
                        oldText
                        text
                        i
                    )
                )
            )
        )
        text
    )

    (defun rset ( text padding maxlen )
        (substr
            (   (lambda ( )
                    (while
                        (<
                            (strlen (setq padding (strcat padding padding)))
                            maxlen
                        )
                    )
                    (setq text (strcat padding text))
                )
            )
            (- (strlen text) (1- maxlen))
        )
    )

    (defun main

        (   /
            header
            placeholder
            body
            footer
            imagecount
            groupcount
            result
            i
        )

        (setq header '("<tr valign=top align=center>\n\n"))

        (setq placeholder "[PLACEHOLDER]")

        (setq body
            (list
                "<td>"
                "<a href='"
                "http://home.comcast.net/~dominic.cesare"
                "/pictures/Louisville/Louisville_"
                placeholder
                ".jpg'"
                " title='Click to enlarge'>\n"
                "<img src="
                "'http://home.comcast.net/~dominic.cesare"
                "/pictures/Louisville/Louisville_"
                placeholder
                ".jpg'"
                " width=100 height=75 border=0></a>\n"
                "<br>"
                placeholder
                "</td>\n\n"
            )
        )

        (setq footer '("</tr>\n\n"))

        (setq
            i          0
            imagecount 10
            groupcount 6
            result     (list header)
        )

        (repeat imagecount
            (   (lambda (body)
                    (setq result
                        (cons
                            body
                            result
                        )
                    )
                    (if (zerop (rem i groupcount))
                        (setq result
                            (cons
                                header
                                (cons
                                    footer
                                    result
                                )
                            )
                        )
                    )
                )
                (   (lambda ( / paddedindex )
                        (setq paddedindex
                            (rset
                                (itoa (setq i (1+ i)))
                                "00"
                                3
                            )
                        )
                        (mapcar
                           '(lambda (item)
                                (replace
                                    placeholder
                                    paddedindex
                                    item
                                )
                            )
                            body
                        )
                    )
                )
            )
        )

        (setq result
            (apply 'append
                (reverse
                    (if (eq footer (car result))
                        result
                        (cons footer result)
                    )
                )
            )
        )

        ;;  I'm just going to print the data to the
        ;;  screen, if you want you could take the
        ;;  result and write it to a file

        (mapcar 'princ result)

        (princ)

    )

    (main)

)
« Last Edit: November 17, 2005, 12:46:37 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Write to text file with incrementing text
« Reply #11 on: November 17, 2005, 12:51:26 PM »
 :lol:  :-o

Yeah...uh...dang

Thanks MP!  That's a lot more than I had in mind!  Glad I posted here before lunch, because that's a lot of stuff I don't know about yet.  That's basically why I wanted to do this thru LISP.  I basically have to add the write to file (which I've done before) and change the image count.  Cheers!


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #12 on: November 17, 2005, 12:55:10 PM »
My pleasure, hic.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Write to text file with incrementing text
« Reply #13 on: November 17, 2005, 01:19:31 PM »
My pleasure, hic.

hic?

as in hick?

because of the picture?

if so...it's not me...

if I'm off base here...

then sorry to all the hick's I've offended...


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #14 on: November 17, 2005, 01:21:33 PM »
I'll rephrase --

"My pleasure, burp".

As in the picture, and I apologize to any underage folks that shouldn't be drinking.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

deegeecees

  • Guest
Re: Write to text file with incrementing text
« Reply #15 on: November 17, 2005, 01:22:06 PM »
I believe that was 'hic' as in "hiccup"

Quote
Hiccup - (usually plural) the state of having reflex spasms of the diaphragm accompanied by a rapid closure of the glottis producing an audible sound; sometimes a symptom of indigestion; "how do you cure the hiccups?"

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Write to text file with incrementing text
« Reply #16 on: November 17, 2005, 01:24:06 PM »
"Rapid closure of the glottis", coming to a theatre near you.

 :-o
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

deegeecees

  • Guest
Re: Write to text file with incrementing text
« Reply #17 on: November 17, 2005, 01:50:09 PM »
"RUN BILLY! The Glottis is closing!"