waders Posted August 6, 2012 Posted August 6, 2012 Help! I found this code that will change or update are date stamp text on are drawing but we have to select it manually. I would like to make it automatically update the text based on crossing window or coodinates. I know that fields would be the easy solution but based on are process it won't work. Thanks (defun C:TXD ( / dd yy mm da mlst ss lll zz) (setq dd (car (entsel "Select Text: \n"))) (setq lll (entget dd)) (if lll (progn (setq zz (assoc 1. lll)) (setq dd (getvar "cdate")) (setq yy (fix (/ dd 10000))) (setq ye (fix (- yy 2000))) ;"ye" will subtracts year to show last two digits of year (setq mm (- (fix (/ dd 100)) (* yy 100.0))) (setq da (- (fix dd) (+ (* mm 100.0) (fix (* yy 10000.0))))) (setq mm (fix (1- mm))) (setq mlst (list "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12")) (setq mm (nth mm mlst)) (setq dd (strcat mm "-" (itoa (fix ye)))) ;To add day replace line above with line below. ;(setq dd (strcat mm (itoa (fix da)) "-" (itoa (fix ye)))) (if (= (substr (cdr zz) 1 4) "ASB:") (setq dd (strcat "ASB: " dd))) (entmod (subst (cons 1 dd) zz lll)))) (princ)) Quote
MSasu Posted August 6, 2012 Posted August 6, 2012 You should check the SSGET function - need to define a filter to identify that item only. If the stamp location is constant: (if (setq dd (ssget "_X" '((0 . "TEXT") (10 [color=red]1.000[/color] [color=blue]2.000[/color] 0.000)))) (setq dd (ssname dd 0)) (exit) ) Where the red and blue labels should be replaced with X, respectively Y coordinates of the said stamp. Quote
waders Posted August 6, 2012 Author Posted August 6, 2012 Sorry they may not all be in the exact same x/y coordinate (but very close). So I was hoping to do some sort of crossing window (multiple x/y coordinates). But if they were all constant location how would I change the code? (defun C:TXD ( / dd yy mm da mlst ss lll zz) ; [color=red](setq dd (car (entsel "Select Text: \n"))) :<----- Change to[/color] [color=blue] (if (setq dd (ssget "_X" '((0 . "TEXT") (10 10.0482 0.286996 0.0)))) ;<--- This?[/color] [color=blue] (setq dd (ssname dd 0))[/color] [color=blue] (exit)[/color] [color=blue])[/color] (setq lll (entget dd)) (if lll (progn Quote
MSasu Posted August 7, 2012 Posted August 7, 2012 Your change is the right one; alternatively may try: (defun C:TXD ( / dd yy mm da mlst ss lll zz) [color=red] (if (setq dd (ssget "_X" '((0 . "TEXT") (10 10.0482 0.286996 0.0)))) (progn [/color][color=red] (setq dd (ssname dd 0)) [/color] (setq lll (entget dd)) (setq zz (assoc 1. lll)) (setq dd (getvar "cdate")) (setq yy (fix (/ dd 10000))) (setq ye (fix (- yy 2000))) ;"ye" will subtracts year to show last two digits of year (setq mm (- (fix (/ dd 100)) (* yy 100.0))) (setq da (- (fix dd) (+ (* mm 100.0) (fix (* yy 10000.0))))) (setq mm (fix (1- mm))) (setq mlst (list "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12")) (setq mm (nth mm mlst)) (setq dd (strcat mm "-" (itoa (fix ye)))) ;To add day replace line above with line below. ;(setq dd (strcat mm (itoa (fix da)) "-" (itoa (fix ye)))) (if (= (substr (cdr zz) 1 4) "ASB:") (setq dd (strcat "ASB: " dd))) (entmod (subst (cons 1 dd) zz lll)))) (princ)) For sure, SSGET allow you to use window/crossing selections - just check in help and on Forum for examples. Quote
MSasu Posted August 7, 2012 Posted August 7, 2012 Presuming that there are no other text entities in that area (4 x 4 units): (ssget "_C" '(8.0 -2.0) '(12.0 2.0) '((0 . "TEXT"))) Quote
BIGAL Posted August 7, 2012 Posted August 7, 2012 Do it simply make the date stamp a block with date as an attribute and you can update easily all sheets or just one etc our plot stamp is a field in tiny print but always updates every time we open dwg. If you want a sample lsp to do this just ask or search here for "TAG update" Quote
waders Posted August 7, 2012 Author Posted August 7, 2012 Okay I thought that made sence utill I got this error message: ; error: bad argument type: lentityp nil I must have not put in the code right. (defun C:TXD (/ dd yy mm da mlst ss lll zz) [color=red](setq dd (ssget "_C" '(10.0 0.25) '(10.25 0.125) '((0 . "TEXT")))) ; <----- where & how I added it? [/color] (setq lll (entget dd)) (if lll (progn (setq zz (assoc 1. lll)) (setq dd (getvar "cdate")) (setq yy (fix (/ dd 10000))) (setq ye (fix (- yy 2000))) ;"ye" will subtracts year to show last two digits of year (setq mm (- (fix (/ dd 100)) (* yy 100.0))) (setq da (- (fix dd) (+ (* mm 100.0) (fix (* yy 10000.0))))) (setq mm (fix (1- mm))) (setq mlst (list "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12") ) (setq mm (nth mm mlst)) (setq dd (strcat mm "-" (itoa (fix ye)))) (if (= (substr (cdr zz) 1 4) "ASB:") (setq dd (strcat "ASB: " dd)) ) (entmod (subst (cons 1 dd) zz lll)) ) ) (princ) ) Quote
MSasu Posted August 7, 2012 Posted August 7, 2012 It was better to start from my first example: (defun C:TXD (/ dd yy mm da mlst ss lll zz) [color=red](if [/color](setq dd (ssget "_C" '(10.0 0.25) '(10.25 0.125) '((0 . "TEXT")))) [color=red] (progn (if (> (sslength ss) 1) (alert "Found more than one label!") ) [/color] [color=red] (setq dd (ssname dd 0)[/color] lll (entget dd)) (setq zz (assoc 1. lll)) (setq dd (getvar "cdate")) (setq yy (fix (/ dd 10000))) (setq ye (fix (- yy 2000))) ;"ye" will subtracts year to show last two digits of year (setq mm (- (fix (/ dd 100)) (* yy 100.0))) (setq da (- (fix dd) (+ (* mm 100.0) (fix (* yy 10000.0))))) (setq mm (fix (1- mm))) (setq mlst (list "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12") ) (setq mm (nth mm mlst)) (setq dd (strcat mm "-" (itoa (fix ye)))) (if (= (substr (cdr zz) 1 4) "ASB:") (setq dd (strcat "ASB: " dd)) ) (entmod (subst (cons 1 dd) zz lll)) ) [color=red] (alert "No label found!")[/color] ) (princ) ) I have also added two warnings to the code - when found no label or more than one. Quote
waders Posted August 7, 2012 Author Posted August 7, 2012 Okay I see I had my coordinates off the second set should be '(10.25 0.375) not '(10.25 0.125). Now I get the error "; error: bad argument type: lselsetp nil". It's like it's not even finding the text or it is but it's not able to edit it is that possible? Thanks so much for your Help! Quote
MSasu Posted August 8, 2012 Posted August 8, 2012 Sorry, there was a typing mistake from my side: (if (> (sslength [s][color=red]ss[/color][/s]dd) 1) (alert "Found more than one label!") ) Quote
waders Posted August 8, 2012 Author Posted August 8, 2012 Thanks Mircea! That did it. Thanks again for your help I really appreciate it. Later Quote
MSasu Posted August 8, 2012 Posted August 8, 2012 You're welcome! One advice, if you don't mind. It is a good programming practice to avoid to re-use variable names, especially when their type is different, in order to avoid confusions. In your code, dd symbol store first a selection set, after a number and finally a string. [color=red](setq dd (car (entsel "Select Text: \n")))[/color] [color=darkgreen](setq dd (getvar "cdate"))[/color] [color=blue](setq dd (strcat mm "-" (itoa (fix ye))))[/color] Quote
waders Posted August 17, 2012 Author Posted August 17, 2012 Thanks again for all you help Mircea. Here is the final code for others to use or modify as they see fit. (defun c:upd (/ dd yy mm da mlst ss lll zz) (if (setq dd (ssget "_C" '(10.0 0.25) '(10.25 0.375) '((0 . "TEXT")))) ;Gets text based on crossing window coordinates (progn (if (> (sslength dd) 1) (alert "Found more than one label!") ) (setq dd (ssname dd 0) lll (entget dd) ) (setq zz (assoc 1. lll)) (setq cd (getvar "cdate")) ;Gets and stores system date (setq yy (fix (/ cd 10000))) ;Gets and stores year for stored system date (setq ye (fix (- yy 2000))) ;"ye" will subtracts year to show last two digits of year (setq mm (- (fix (/ cd 100)) (* yy 100.0))) ;Gets and stores month ; (setq da (- (fix cd) (+ (* mm 100.0) (fix (* yy 10000.0))))) ;Gets and stores date (setq mm (fix (1- mm))) (setq mlst (list "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12") ) (setq mm (nth mm mlst)) (setq tx (strcat mm "-" (itoa (fix ye)))) ;Puts month & year in text string ; (setq tx (strcat mm (itoa (fix da)) ", " (itoa (fix yy)))) ;Puts month, day & year in text string (if (= (substr (cdr zz) 1 4) "ASB:") (setq dd (strcat "ASB: " tx)) ) (entmod (subst (cons 1 tx) zz lll)) ) (alert "No label found!") ) (princ) ) Quote
MSasu Posted August 17, 2012 Posted August 17, 2012 You're entirely welcome! I hope that you will reconsider my above advice on variables naming... Quote
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.