View Full Version : Does anybody have a LISP that will increment a letter?
Robert.Hall
2006-03-17, 05:56 PM
Does anybody have a lisp that will increment a letter?
I use letters for revision levels (A, B, C, etc.).
I would like a lisp routine that I can use to quickly bump
the revision level on multiple drawings.
Something like:
Select the letter A, and it turns into B
T.Willey
2006-03-17, 06:42 PM
Try this. Skips letters "I, O and Q".
(defun UpRevisionString (String / tmpPos tmpStr tmpStr2 tmpStr3 EndStr tmpAddValue)
; Update to the new revision. A->B, Z->AA, AZ->BA, AZA->AZB
(setq tmpPos (strlen String))
(while (and (/= tmpPos 0) (= (setq tmpStr (substr String tmpPos 1)) "Z"))
(setq tmpPos (1- tmpPos))
(if tmpStr2
(setq tmpStr2 (strcat "A" tmpStr2))
(setq tmpStr2 "A")
)
)
(if (= tmpPos 0)
(repeat (1+ (strlen String))
(if EndStr
(setq EndStr (strcat EndStr "A"))
(setq EndStr "A")
)
)
(progn
(setq tmpStr3 (substr String 1 (1- tmpPOs)))
(if (or (= tmpStr "H") (= tmpStr "N") (= tmpStr "P"))
(setq tmpAddValue 2)
(setq tmpAddValue 1)
)
(setq tmpStr (chr (+ tmpAddValue (ascii tmpStr))))
)
)
(cond
(EndStr
EndStr
)
((and tmpStr tmpStr2 tmpStr3)
(strcat tmpStr3 tmpStr tmpStr2)
)
((and tmpStr tmpStr3)
(strcat tmpStr3 tmpStr)
)
)
)
Robert.Hall
2006-03-17, 07:20 PM
This isn't working?
It say too few arguments. I cannot figure
out what it is missing.
T.Willey
2006-03-17, 07:23 PM
Use like
(UpRevisionString "A")
Adesu
2006-03-20, 04:06 AM
Does anybody have a lisp that will increment a letter?
I use letters for revision levels (A, B, C, etc.).
I would like a lisp routine that I can use to quickly bump
the revision level on multiple drawings.
Something like:
Select the letter A, and it turns into B
Hi Robert,
Test my code,I hope this help you
; idt for increase or decrease text
(defun c:idt (/ ss opt sse str code_ascii nca nstr ed)
(setq ss (car (entsel "\nSelect a single text")))
(if
ss
(progn
(setq opt (strcase (getstring "\nSelect Increase or Decrease [I or D]<I>: ")))
(if (= opt "")(setq opt "I"))
(setq sse (entget ss))
(setq str (cdr (assoc 1 sse)))
(setq code_ascii (ascii str))
(if
(and (> code_ascii 64)(< code_ascii 98))
(progn
(if
(= opt "I")
(progn
(setq nca (1+ code_ascii))
(setq nstr (chr nca))
(setq ed (entmod (subst (cons 1 nstr)(assoc 1 sse) sse)))
(entupd ed)
) ; progn
) ; if
(if
(= opt "D")
(progn
(setq nca (1- code_ascii))
(setq nstr (chr nca))
(setq ed (entmod (subst (cons 1 nstr)(assoc 1 sse) sse)))
(entupd ed)
) ; progn
) ; if
) ; progn
) ; if
(if
(and (> code_ascii 96)(< code_ascii 123))
(progn
(if
(= opt "I")
(progn
(setq nca (1+ code_ascii))
(setq nstr (chr nca))
(setq ed (entmod (subst (cons 1 nstr)(assoc 1 sse) sse)))
(entupd ed)
) ; progn
) ; if
(if
(= opt "D")
(progn
(setq nca (1- code_ascii))
(setq nstr (chr nca))
(setq ed (entmod (subst (cons 1 nstr)(assoc 1 sse) sse)))
(entupd ed)
) ; progn
) ; if
) ; progn
) ; if
) ; progn
(alert "\nInvalid selected object,please try again")
) ; if
(princ)
) ; defun
Robert.Hall
2006-03-20, 04:03 PM
Thanks, both of these suggestions work great!
DarrenYoung
2006-03-21, 03:07 PM
Does anybody have a lisp that will increment a letter?
I use letters for revision levels (A, B, C, etc.).
I would like a lisp routine that I can use to quickly bump
the revision level on multiple drawings.
Something like:
Select the letter A, and it turns into B
Try this....
Written by Owen Wengerd (www.manusoft.com (http://www.manusoft.com) & www.cadlock.com (http://www.cadlock.com)) back in 2003 in the Autodesk customization discussion group.
http://discussion.autodesk.com/thread.jspa?messageID=1176527
Just pass it an alphabetic string and it'll spit back the next. "A" becomes "B", "B" becomes "C", "Z" becomes "AA". "AA becomes "AB", "AZ" becomes "BA", etc.
---snip---
(defun Str+ (source / prefix rchar)
(cond
((= source "") "A")
((= (setq prefix (substr source 1 (1- (strlen source)))
rchar (substr source (strlen source))
)
"Z"
)
(strcat (Str+ prefix) "A")
)
((strcat prefix (chr (1+ (ascii rchar)))))
)
)---snip---
hevgee
2006-03-22, 11:45 AM
Here is one that works, with numbers and letters, in any direction.
it take the font from your dimstyle, you may have to adjust this to suit your needs.
All the best
Hevgee
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.