deziree Posted October 9, 2008 Share Posted October 9, 2008 Hey all... I found the following lisp routing to insert a date stamp and update with a simple command. It's pretty close to what I want but not exact. The following is what I would like changed a) the stamp comes in "Thursday October 09 2008 - 3:16:18 pm" I would simply like it to read YY-MM-DD (as in 08-10-09). b) it does not automatically update when saved - I do not know if this is possible but it would be very helpful. If anyone can help me out I am trying to learn how to write these silly codes and I get lost very easily. Here is the code itself ; Function(s): makestamp: Allows user to place a date/time stamp. ; upstamp: Auto-updates an existing date/time stamp. ;type makestamp at the AutoCAD command prompt to run or upstamp to update (defun c:makestamp () ;creates new stamp in drawing (setq pt (getpoint "\nPick a point: ")) (setq curdate (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) (setq object (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 67 0) (cons 410 (getvar "ctab")) ;gets current layout. (cons 8 "TIMESTAMP") ;puts on this layer, used to identify in next lisp for updating. Do NOT CHANGE!!!! ;every time. Or on your print button, right before you put the little command for this lisp, you ;may want to issue a change clayer to the correct text layer for this. (cons 100 "AcDbText") (cons 10 (list (car pt)(cadr pt)(caddr pt) ) ) (cons 40 (getvar "textsize")) (cons 1 curdate) (cons 50 (* 00 (/ pi 180))) (cons 41 1.0) (cons 51 0) (cons 7 (getvar "cmlstyle"));gets current multi-line style (cons 71 0) (cons 72 0) (cons 100 "AcDbText") (cons 73 0) ) ) (entmake object) (princ) ) (defun c:upstamp () (setq curdate2 (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) (setq ssup (ssget "x" (list (cons 8 "TIMESTAMP")))) ;gets the only entity on the TIMESTAMP layer (setq count (sslength ssup)) ;test to see how many entities are on the TIMESTAMP layer. If count = 0, then lisp errors out. (if (= count 1) (progn (setq b1 (entget (ssname ssup 0))) ;if only one entity exist then the lisp updates the to the current time/date (setq c (assoc 1 b1)) (setq d (cons (car c) curdate2)) (setq b2 (subst d c b1)) (entmod b2) ) (progn ;if there is more than one entity on that layer, then lisp alerts user. (alert "ERROR: You have more than one entity on the TIMESTAMP layer.") (quit) ) ) (princ) ) Thanks Quote Link to comment Share on other sites More sharing options...
CALCAD Posted October 11, 2008 Share Posted October 11, 2008 Deziree, Try this modified code. ; Function(s): makestamp: Allows user to place a date/time stamp. ; upstamp: Auto-updates an existing date/time stamp. ; type makestamp at the AutoCAD command prompt to run or upstamp to update (defun c:makestamp () ;creates new stamp in drawing (setq pt (getpoint "\nPick a point: ")) ;(setq curdate (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) (setq curdate (getvar "CDATE")) (setq curdate (rtos curdate 2 4)) (setq year (substr curdate 3 2)) (setq month (substr curdate 5 2)) (setq day (substr curdate 7 2)) (setq curdate (strcat year "-" month "-" day)) (setq object (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 67 0) (cons 410 (getvar "ctab")) ;gets current layout. (cons 8 "TIMESTAMP") ;puts on this layer, used to identify in next lisp for updating. Do NOT CHANGE!!!! ;every time. Or on your print button, right before you put the little command for this lisp, you ;may want to issue a change clayer to the correct text layer for this. (cons 100 "AcDbText") (cons 10 (list (car pt)(cadr pt)(caddr pt) ) ) (cons 40 (getvar "textsize")) (cons 1 curdate) (cons 50 (* 00 (/ pi 180))) (cons 41 1.0) (cons 51 0) (cons 7 (getvar "cmlstyle"));gets current multi-line style (cons 71 0) (cons 72 0) (cons 100 "AcDbText") (cons 73 0) ) ) (entmake object) (princ) ) ; upstamp: Auto-updates an existing date/time stamp. (defun c:upstamp () ;(setq curdate2 (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) (setq curdate2 (getvar "CDATE")) (setq curdate2 (rtos curdate2 2 4)) (setq year (substr curdate2 3 2)) (setq month (substr curdate2 5 2)) (setq day (substr curdate2 7 2)) (setq curdate2 (strcat year "-" month "-" day)) (setq ssup (ssget "x" (list (cons 8 "TIMESTAMP")))) ;gets the only entity on the TIMESTAMP layer (setq count (sslength ssup)) ;test to see how many entities are on the TIMESTAMP layer. If count = 0, then lisp errors out. (if (= count 1) (progn (setq b1 (entget (ssname ssup 0))) ;if only one entity exist then the lisp updates the to the current time/date (setq c (assoc 1 b1)) (setq d (cons (car c) curdate2)) (setq b2 (subst d c b1)) (entmod b2) ) (progn ;if there is more than one entity on that layer, then lisp alerts user. (alert "ERROR: You have more than one entity on the TIMESTAMP layer.") (quit) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
CALCAD Posted October 11, 2008 Share Posted October 11, 2008 You could slightly modify the upstamp code by adding the line : (command ".CLOSE") to just before the (princ) at the end. Then I would suggest renaming the upstamp routine by changing the line : (defun c:upstamp () to something like : (defun c:uclose () or to anything you would like. So, to update the stamp and close you would type UCLOSE at the command line. Quote Link to comment Share on other sites More sharing options...
deziree Posted October 14, 2008 Author Share Posted October 14, 2008 Thank you that code worked... Quote Link to comment Share on other sites More sharing options...
CALCAD Posted October 14, 2008 Share Posted October 14, 2008 You're welcome. Glad it's working for you. Quote Link to comment Share on other sites More sharing options...
deziree Posted October 14, 2008 Author Share Posted October 14, 2008 Would you know how to change the code to make it change every time you save the drawing? Also could you explain what you change so I can try to figure it out.... I would really like to be able to write and edit these routines on my own some time I sort of understand the closing thing but need it for when i save since I would need it to show the new date from when it is saved. then i can print it with the new date. Quote Link to comment Share on other sites More sharing options...
CALCAD Posted October 15, 2008 Share Posted October 15, 2008 I'm sorry. After re-reading your first post I see that I assumed, wrongly, that you wanted to update the stamp and close. Updating and saving while staying in the drawing should not be a problem, but I have a shortage of time for a day or two. I will respond as soon as I can and I will give explanations. Actually, following the procedure I outlined using the CLOSE command except substituting QSAVE should work as in : (command ".QSAVE") just before the last (princ) in the update routine. In any case, I'll get back to you. Quote Link to comment Share on other sites More sharing options...
CALCAD Posted October 15, 2008 Share Posted October 15, 2008 OK, here's the code again with the save added to upstamp and some comments added to describe the changed / added code. Please feel free to ask questions. If you seriously want to learn Autolisp, the basic information about the functions and syntax are contained in the help files, but you will probably want to look on the web for tutorials and code examples. There's a lot of information out there. ; Function(s): makestamp: Allows user to place a date/time stamp. ; upstamp: Auto-updates an existing date/time stamp. ; type makestamp at the AutoCAD command prompt for new stamp or upstamp to update and save file. (defun c:makestamp () ;creates new stamp in drawing (setq pt (getpoint "\nPick a point: ")) ;(setq curdate (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) ; commented out ; Next section gets the current date from the system, converts it to a string ; and defines substrings for the year, month and day. (setq curdate (getvar "CDATE")) (setq curdate (rtos curdate 2 4)) (setq year (substr curdate 3 2)) (setq month (substr curdate 5 2)) (setq day (substr curdate 7 2)) ; Next line concatenates five substrings into the date format YY-MM-DD (setq curdate (strcat year "-" month "-" day)) (setq object (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 67 0) (cons 410 (getvar "ctab")) ; gets current layout. (cons 8 "TIMESTAMP") ; puts on this layer, used to identify in next lisp for updating. Do NOT CHANGE!!!! ; every time. Or on your print button, right before you put the little command for this lisp, you ; may want to issue a change clayer to the correct text layer for this. (cons 100 "AcDbText") (cons 10 (list (car pt)(cadr pt)(caddr pt) ) ) (cons 40 (getvar "textsize")) (cons 1 curdate) (cons 50 (* 00 (/ pi 180))) (cons 41 1.0) (cons 51 0) (cons 7 (getvar "cmlstyle")) ; gets current multi-line style (cons 71 0) (cons 72 0) (cons 100 "AcDbText") (cons 73 0) ) ) (entmake object) (princ) ) ; upstamp: Auto-updates an existing date/time stamp. (defun c:upstamp () ;(setq curdate2 (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) - commented out ; Next section gets the current date from the system, converts it to a string ; and defines substrings for the year, month and day. (setq curdate2 (getvar "CDATE")) (setq curdate2 (rtos curdate2 2 4)) (setq year (substr curdate2 3 2)) (setq month (substr curdate2 5 2)) (setq day (substr curdate2 7 2)) ; Next line concatenates five substrings into the date format YY-MM-DD (setq curdate2 (strcat year "-" month "-" day)) (setq ssup (ssget "x" (list (cons 8 "TIMESTAMP")))) ; gets the only entity on the TIMESTAMP layer (setq count (sslength ssup)) ; test to see how many entities are on the TIMESTAMP layer. If count = 0, then lisp errors out. (if (= count 1) (progn (setq b1 (entget (ssname ssup 0))) ; if only one entity exist then the lisp updates the to the current time/date (setq c (assoc 1 b1)) (setq d (cons (car c) curdate2)) (setq b2 (subst d c b1)) (entmod b2) ) (progn ; if there is more than one entity on that layer, then lisp alerts user. (alert "ERROR: You have more than one entity on the TIMESTAMP layer.") (quit) ) ) (command ".QSAVE") ; quick save the file - asks for filename only if first save (princ) ) Quote Link to comment Share on other sites More sharing options...
deziree Posted October 15, 2008 Author Share Posted October 15, 2008 Thanks I will look for some online tutorials... I will let you know tomorrow if the date changes but so far the code is working great. Thanks. Quote Link to comment Share on other sites More sharing options...
Foz Posted November 20, 2008 Share Posted November 20, 2008 We just use text attributes with fields embedded in our drawings. The possibilities are pretty much endless (see attached drawing). Click on one of the attributes in the lower left hand corner with the ddedit command and any attributes that show up with a grey hatch are ones with fields assigned to them. Double click on the hatched attribute and the Field dialog box will open. Play with the Field Category to see which options are available to you. Note that under Field Category:Date and Time, Field Names:SaveDate several reporting options are available in the examples box. Sample Date User Stamp.dwg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.