TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Coder on February 09, 2011, 07:49:54 AM
-
Hello .
Why the following codes in RED are not working well ? and what is the best way to do it ?
(setq ss (ssget '((0 . "TEXT,Mtext"))))
((lambda ( n / *ss entities )
(while
(setq *ss (ssname ss (setq n (1+ n))))
(setq entities (entget *ss))
[color=red] (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Texts")(assoc 8 entities) entities )))))
(entupd (cdr (assoc -1 (entmod (subst (cons 71 1) (assoc 71 entities) entities )))))[/color]
)
)
-1
)
Thanks
-
After updating the Layer value [DXF 8] in the 'entities' DXF List, you are using the original list containing the old Layer value when updating the Text Generation Flag (in Text) or the Attachment Point (in MText) - Note that DXF 71 means different things for Text & MText!
Hence, since the original DXF Data is used, the Layer value is updated back to its original value.
-
Consider this code as an example:
(if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
(repeat (setq i (sslength ss))
(setq
elist (entget (ssname ss (setq i (1- i))))
elist (subst (cons 8 "Texts") (assoc 8 elist) elist)
elist (subst (cons 71 1) (assoc 71 elist) elist)
)
(entupd (cdr (assoc -1 (entmod elist))))
)
)
For clarity of my method, I have removed 'Text' from the ssget filter list. If you want to change the alignment of Text & MText you will need to include a conditional within the loop.
Lee
-
Little sub help...
(defun _Subst (dottedpair entitylist)
(subst dottedpair (assoc (car dottedpair) entitylist) entitylist)
)
(if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
(repeat (setq i (sslength ss))
(entupd (cdr (assoc -1
(entmod
(_Subst '(8 . "Texts")
(_Subst '(71 . 1)
(entget (ssname ss (setq i (1- i))))
)
)
)
)
)
)
)
)
-
To account for the Text/MText issue..
(defun c:test ( / _subst ss i elist )
(defun _subst ( code value elist )
(subst (cons code value) (assoc code elist) elist)
)
(if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
(repeat (setq i (sslength ss))
(setq elist (entget (ssname ss (setq i (1- i))))
elist (_subst 8 "Texts" elist)
)
(if (eq "TEXT" (cdr (assoc 0 elist)))
(setq elist (if (and (= 0 (cdr (assoc 72 elist)))
(= 0 (cdr (assoc 73 elist)))
)
(_subst 11 (cdr (assoc 10 elist)) elist)
elist
)
elist (_subst 72 0 elist)
elist (_subst 73 3 elist)
)
(setq elist (_subst 71 1 elist))
)
(entupd (cdr (assoc -1 (entmod elist))))
)
)
(princ)
)
-
Thank you Lee and Alanjt .
These examples are very helpful .
Appreciated.
-
You're welcome Coder, happy I could be of help :-)
-
You're welcome Coder, happy I could be of help :-)
x2