TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Dommy2Hotty 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:
<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?
-
Yep, but why use lisp?
-
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.
-
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 --
(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).
:)
-
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.
-
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:
<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>
-
Glad to hear D2H. Just let me know if / when you need another nudge.
-
Glad to hear D2H. Just let me know if / when you need another nudge.
I might will need some help...maybe
-
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 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:
<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>
-
(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)
)
-
: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!
(http://mccrory.fnal.gov/alex/photos/Austria/Drink,Felix,drink!.jpg)
-
My pleasure, hic.
-
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...
-
I'll rephrase --
"My pleasure, burp".
As in the picture, and I apologize to any underage folks that shouldn't be drinking.
:)
-
I believe that was 'hic' as in "hiccup"
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?"
-
"Rapid closure of the glottis", coming to a theatre near you.
:-o
-
"RUN BILLY! The Glottis is closing!"