drawing number list

I have been trying, in vain, to write a lisp routine that would prompt the user for a drive letter then a directory and then would create or open a
drawing list.txt document, read the last number on the list, add one more to it on the next line and then place the next number in the bottom right hand corner of the drawing. This would allow you to pick a button, then the lisp file would get you a drawing number (the next numerically), record it and then apply it to your drawing. I am new to lisp programming and am sort of baffled by the way the logical operators work. If someone could give me an example of how you would tackle this, it would help a great deal. Thanks.
Chuck
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
chuck i fail to see your logic. why do you want to do this?

to
hand
lisp
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
So everyone on our LAN would simply be able to press a button and the new drawing they are working on would be assigned the next drawing number in the current contract without having to go to a drawing register and select a drawing number or , as is often the case, with people too lazy to get up and get a drawing number they will be working merrily away only to find out later that two people have used the same number.

the
more
and
of
an
Thanks.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Chuck wrote:

Great idea, Chuck.
For this kind of case, it's generally best to put some code in so we know exactly what you're doing. What EXACTLY are you trying to do with the logical operators that's giving you trouble?
If it's reading the file, I do something like this:
(setq ofil (open "filename" "r")) (while (setq nxtlin (read-line ofil)) ;process line here ) (close ofil)
When the end of the file is reached, nxtlin is set to nil, then returned by setq, which exits the while loop.
Now, is that what you're having trouble with, by chance?
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Here's what I've got. As you can see I'm a real amateur at this. I should probably take a course in this except the closest offering is an hour's drive each way for a night school class once a week.
(defun c:dstamp () (setq drvn (getstring "/nplease enter the drive name ")) (setq dirn (getstring "/nplease enter the directory name include subdirectories separated by a / like this...dir/subdir " ) ) (setq filen (strcat drvn ":/" dirn "drawing numbers.txt")) (setq dn (open filen "w")) ((while (setq nextline (read-line dn)) (setq dwgname (atof (read-line dn)) (setq dwgname (+ 1 dwgname)) (write-line (rtos dwgname) dn) (close dn) (setq a (getvar "textsize")) (setq x (/ a 2)) (setq a (- (car (getvar "limmax")) a)) (command "text" "j" "br" (list a x) "" "" dwgname) )

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
I've discovered that dwgname is a system variable and can't be used as an autolisp variable plus my brackets were incorrect. This is my latest attempt.
(defun c:dstamp () (setq drvn (getstring "/nplease enter the drive name ")) (setq dirn (getstring "/nplease enter the directory name include subdirectories separated by a / like this...dir/subdir " ) ) (setq filen (strcat drvn ":/" dirn "drawing numbers.txt")) (setq dn (open filen "w")) (setq cval (read-line dn)) (if (= cval " ") (write-line "1" dn)) (while (setq nextline (read-line dn)) (setq dname (atof (read-line dn))) ) (setq dname (+ 1 dname)) (write-line (rtos dname) dn) (close filen) (setq a (getvar "textsize")) (setq x (/ a 2)) (setq a (- (car (getvar "limmax")) a)) (command "text" "j" "br" (list a x) "" "" dname)

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Chuck wrote: <SNIPPED>

If I'm not mistaken, you're trying to determine if the file is empty, is that correct? If so, here is a 'logic error'. You're testing for a space character here. I think it would be better to test for nill. Something like this:
(if (not cval) (write-line "1" dn) (progn ;code here to get last line and increment number );progn );if
Again, I'm going on assumptions here, so adapt as necessary. Wouldn't you want to check to see if the txt file exists, then create with the "1" in it, if it does not?
Also, FWIW, there is a variable named DWGPREFIX that will give you the path of the current drawing. If this is appropriate for you, it's much cleaner than prompting the user for a path.
As always, re-post with any comments/questions.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
(defun c:dstamp () (setq dp (getvar "DWGPREFIX")) ;returns the current drive and directory of the drawing (setq filen (strcat dp "drawing numbers.txt")) ;creates the file in the "dp" directory (setq dn (open filen "w")) ;this is where I start to get lost...open filen for writing....I assume you can also read from this file at this point? (setq cval (read-line dn)) (if (not cval) (write-line "1" dn) (progn (while (setq dnumber (read-line dn)) (setq dname (atof dnumber)) ;returns the nextline as a real (setq dnxet (+ 1 dname)) ;increments the real by one for the next drawing number (write-line (rtos dnext) dn) :writes the next drawing number to the file ) (close dn) :close the file ) (setq a (getvar "TEXTSIZE")) (setq x (/ a 2)) ;sets the vertical offset to TEXTSIZE/2 (setq a (- (car (getvar "LIMMAX")) a)) ;sets the horizontal offset to LIMMAX-TEXTSIZE (bottom-right justified) (command "text" "j" "br" (list a x) "" "" dnumber) ;prints the dnumber at the pre-determined co-ordinates )

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Chuck wrote: <SNIPPED>

This is incorrect. You would have to open the file to read OR write. To test this, I did this at the command line:
(setq ofil (open "c:/notreallyafilename.txt" "r")) nil
Command: (setq ofil (open "c:/notreallyafilename.txt" "w")) #<file "c:/notreallyafilename.txt">
Command: (setq ofil (open "c:/notreallyafilename.txt" "w"))*Cancel*
Command: (write-line "first line") first line "first line"
Command: (close ofil) nil
Notice on the initial read attempt that nil is returned. This is how I would test for the existance of the file. Logic would look like this:
(if (setq ofil (open filename "r")) (progn (while (setq nxtlin (read-line ofil)) (setq lastnum nxtlin) ;might net adapted to your situation );while (setq increment (1+ lastnum)) (close ofil) ;always close files ASAP );progn, then (setq increment 1) );if (setq ofil (open filename "a")) ;if it doesn't exist, it will be created (write-line (itoa increment)) ;might need adapted to your situation (close ofil)
Open with the "a" will automatically add to the end of the file
WARNING: I wrote this rather quickly without testing, and I'm not positive of your file format. My intent is to show the basic logic, hopefully in a simple to understand format. ;)
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.