Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp edit help wanted

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
brendon_butler
322 Views, 2 Replies

Lisp edit help wanted

Hi all,

 

I have this Lisp routine that I took from this site previously, but would like a modification made. I'm hoping somebody could possibly help me out.

So, the below routine simply adds a comma as a suffix to text. However, I would like it to now be added as a prefix.

 

 

 

(defun c:addcomma (/ olderr e sm)
  (setq olderr *error*)
  (defun *error* (msg)
    (if (/= msg "Function cancelled")
      (prompt (strcat "\nError: " msg))
    )
    (setvar "SNAPMODE" sm)
    (setq *error* olderr)                           ;Restore old *error* handler
    (princ)
  )
  (setq sm (getvar "SNAPMODE"))
  (setvar "SNAPMODE" 0)
  (while (setq e (car (nentsel "\nLocate text to add comma: ")))
    (if (member (strcase (cdr (assoc 0 (entget e)))) '("TEXT" "ATTRIB" "MTEXT"))
      (entupd (cdr (assoc -1 (entmod (subst (cons 1 (strcat (cdr (assoc 1 (entget e))) ","))(assoc 1 (entget e))(entget e))))))
    )
  )
  (setvar "SNAPMODE" sm)
  (setq *error* olderr)
  (princ)
)

 

Thanks in advance for any help given!

Brendon

2 REPLIES 2
Message 2 of 3
BeKirra
in reply to: brendon_butler

Try the code modified from your post:


 

 


brendon.butler wrote:

 

 

 

Hi all,

 

 

I have this Lisp routine that I took from this site previously, but would like a modification made. I'm hoping somebody could possibly help me out.

So, the below routine simply adds a comma as a suffix to text. However, I would like it to now be added as a prefix.

 

 

 

(defun c:addcomma (/ olderr e sm)
  (setq olderr *error*)
  (defun *error* (msg)
    (if (/= msg "Function cancelled")
      (prompt (strcat "\nError: " msg))
    )
    (setvar "SNAPMODE" sm)
    (setq *error* olderr)                           ;Restore old *error* handler
    (princ)
  )
  (setq sm (getvar "SNAPMODE"))
  (setvar "SNAPMODE" 0)
  (while (setq e (car (nentsel "\nLocate text to add comma: ")))
    (if (member (strcase (cdr (assoc 0 (entget e)))) '("TEXT" "ATTRIB" "MTEXT"))
      (entupd (cdr (assoc -1 (entmod (subst (cons 1 (strcat (cdr "," (assoc 1 (entget e)))))(assoc 1 (entget e))(entget e))))))
    )
  )
  (setvar "SNAPMODE" sm)
  (setq *error* olderr)
  (princ)
)

 

Thanks in advance for any help given!

Brendon


 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 3 of 3
Anonymous
in reply to: brendon_butler

(defun c:addcomma (/ olderr e sm)
  (setq olderr *error*)
  (defun *error* (msg)
    (if (/= msg "Function cancelled")
      (prompt (strcat "\nError: " msg))
    )
    (setvar "SNAPMODE" sm)
    (setq *error* olderr)                           ;Restore old *error* handler
    (princ)
  )
  (setq sm (getvar "SNAPMODE"))
  (setvar "SNAPMODE" 0)
  (while (setq e (car (nentsel "\nLocate text to add comma: ")))
    (if (member (strcase (cdr (assoc 0 (entget e)))) '("TEXT" "ATTRIB" "MTEXT"))
      (entupd (cdr (assoc -1 (entmod (subst (cons 1 (strcat ","  (cdr (assoc 1 (entget e)))))(assoc 1 (entget e))(entget e))))))
    )
  )
  (setvar "SNAPMODE" sm)
  (setq *error* olderr)
  (princ)
)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report