Help with Fields.

Hi All. I'm trying to us a lisp to add a minus prefix to all text fields that I click. My code sort of works. Until I open it in the field editor and then things go crazy. And the field description at the bottom of the box seems to keep adding to itself.

Can anyone with field lisp experience tell me what I am doing wrong?

Here is the lisp:

(defun C:ADDMINUSPREFIX (/ ent_obj top_list second_list third_list fourth_list  field_string new_string)
(vl-load-com)
(setq field_string nil
new_string nil
fifth_list nil) (setq ent_obj (car (entsel "\nSelect a field text to add a '-' prefix: ")))
(setq prefix_code "%ps[-,]")
(if (and ent_obj (eq "TEXT" (cdr (assoc 0 (entget ent_obj)))))
(progn
;; Traverse the dictionary links to the field entity
(setq top_list (entget ent_obj))
(setq second_list (entget (cdr (assoc 360 top_list))))
(setq third_list (entget (cdr (assoc 360 second_list))))
(setq fourth_list (entget (cdr (assoc 360 third_list))))
(setq fifth_list (entget (cdr (assoc 360 fourth_list))))
(princ "fifth_list =") (princ fifth_list)
(setq field_string (cdr (assoc 2 fifth_list)))
(print "filed string = ") (princ field_string)
(setq lastQuotePosition (vl-string-position (ascii """) field_string nil t)) (setq new_string (strcat (substr field_string 1 lastQuotePosition) prefix_code "\"")) (print "new_string =") (princ new_string) (print "************************") (setq fifth_list (subst (cons 2 new_string) (assoc 2 fifth_list) fifth_list)) (print "fifth_list = ") (princ fifth_list) (print "######################################") ;(setq field_string (cdr (assoc 300 fifth_list))) (setq 300string (cdr (assoc 300 (reverse fifth_list)))) (print "300 string = ") (print 300string) (print "**************") (setq lastQuotePosition (vl-string-position (ascii "\"") 300string nil t)) (setq new_string (strcat (substr 300string 1 lastQuotePosition) prefix_code )) (print "new_string =") (princ new_string) (setq fifth_list (subst (cons 300 new_string) (assoc 300 (reverse fifth_list)) fifth_list)) (print "new fifth list = ") (princ fifth_list) (entmod fifth_list) (entupd (cdr (assoc 360 fourth_list))) (entupd ent_obj) (print "NOW TEST THE NEW FIELD FIFTH LIST") (setq top_list (entget ent_obj)) (setq second_list (entget (cdr (assoc 360 top_list)))) (setq third_list (entget (cdr (assoc 360 second_list)))) (setq fourth_list (entget (cdr (assoc 360 third_list)))) (setq fifth_list (entget (cdr (assoc 360 fourth_list)))) ;(princ "fifth_list =") (princ fifth_list) (print "Fifth List Item 2 = ") (princ (assoc 2 fifth_list)_) (princ) ) ) (princ) )

Thanks for any help. I suspect there is some obscure complex requirement that I don't know about. Oh. and all the print and princ everywhere in the code is just me tracking what is happening.

Comments

  • Couldn't solve it .For now I'm just copying separate minus ("-") text in front of the fields. That is much quicker than editing the fields.