Comparing text in notepad and autocad drawing, if matched, change the text color in autocad drawing

Comparing text in notepad and autocad drawing, if matched, change the text color in autocad drawing

zenithlpl
Explorer Explorer
869 Views
6 Replies
Message 1 of 7

Comparing text in notepad and autocad drawing, if matched, change the text color in autocad drawing

zenithlpl
Explorer
Explorer

Hi,

 

I have set of text in notepad that I need to compare against text in autocad drawing.

If matched, the text in autocad will have to change into another colour.

 

Got a friend help for writing a lisp, but don't seem to work. 

 

Need help!

 

(defun C:read_file (/ TXT_FILE)
(setq TXT_FILE (getfiled "Select Text File" "" "txt" 1))
(if TXT_FILE
(progn
(setq INPUT (open TXT_FILE "r"))
(setq LINE (read-line INPUT))
(while LINE
(setq TEXT (car (read (" LINE "))))
(setq PT (cdr (read (" LINE "))))
(command "_.line" (car PT) (cadr PT) (car (cdr PT)) (cadr (cdr PT)))
(setq LINE (read-line INPUT))
)
(close INPUT)
(princ "\n Done!")
)
)
)

(defun C:color_text (/ SS INPUT VALUE)
(setq INPUT (open "C:\\Temp\\TextValues.txt" "r"))
(while (setq VALUE (read-line INPUT))
(setq SS (ssget "_X" '((0 . "TEXT")(1 . VALUE))))
(if (/= SS nil)
(foreach OBJ (mapcar 'cadr (ssnamex SS))
(setq OBJ (entmod (subst '(62 . 1) '(62 . 2) (entget OBJ))))
)
)
)
(close INPUT)
(princ "\n Done!")
)

 

 

Thank you

0 Likes
Accepted solutions (1)
870 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor

The problem may be in the entmod, do you need obj ? Ok the second 62 has to read the current color from the entity then it is substituted.

 

(entmod (subst '(62 . 1) '(62 . (entget OBJ)) (entget OBJ)))
0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant

You have "quoted" '() lists [which need to be fully literal, containing nothing that needs evaluation] that include things needing evaluation.  If there are things like that, such as variables to pull values out of, you must use the explicit (list) function.  And (entmod) doesn't need to be a part of setting a variable.  And (subst) won't work if the Text has ByLayer color -- there won't be an (assoc 62) entry in its entity data to replace.  So (append) it to the entity data, which will replace an earlier such entry if it's there.  Try something like this [untested]:

....

(while (setq VALUE (read-line INPUT))
  (if (setq SS (ssget "_X" (list '(0 . "TEXT") (cons 1 VALUE))))
    (foreach OBJ (mapcar 'cadr (ssnamex SS)); then
      (setq objdata (entget OBJ))

      (entmod (append objdata '((62 . 1))))

    ); foreach

  ); if

....

Kent Cooper, AIA
0 Likes
Message 4 of 7

komondormrex
Mentor
Mentor

hey,

 

(defun C:color_text (/ SS INPUT VALUE)
	(setq INPUT (open "C:\\Temp\\TextValues.txt" "r"))
	(while (setq VALUE (read-line INPUT))
		(setq SS (ssget "_X" '((0 . "TEXT")(cons 1 VALUE))))
		(if (/= SS nil)
			(foreach OBJ (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
				(setpropertyvalue OBJ "Color" 1) 
			)
		)
	)
	(close INPUT)
	(princ "\n Done!")
)

 

0 Likes
Message 5 of 7

zenithlpl
Explorer
Explorer

Seem like the below is not correct.

 

(setq TEXT (car (read ("LINE"))))
(setq PT (cdr (read ("LINE"))))

0 Likes
Message 6 of 7

komondormrex
Mentor
Mentor

sure. should be way of. and depends on what is in the string read.

(setq TEXT (car (read (strcat "(" LINE ")" ))))
(setq PT (cdr (read (strcat "(" LINE ")" ))))

 

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@zenithlpl wrote:

Seem like the below is not correct.

 

(setq TEXT (car (read ("LINE"))))
(setq PT (cdr (read ("LINE"))))


I agree.  The LINE variable will contain something like this, from your sample file:

"AB11-12345A"

That's a text string [the only thing you can get from (read-line)], but that code is built to pull elements from a list.  And it looks like that list should contain a text string and a point, in some format.  There's nothing in a line in that file that could be taken as a point.  Is the sample file not representative?  If each line should be longer, with point coordinates included, the way to extract those would be very different, but I don't want to work it out without seeing what you really have and understanding what you really want to do with it.

Kent Cooper, AIA
0 Likes