How to ASSOC a DXF Code, only
Hi guys,I'm just in the process of modifying a Text-to-MText routine (not my own, all credit to Peter Jamtgaard for the original, which I found here... https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/text-to-mtext-without-txt2mtxt/td-p/1491008).
;;;Here is a program to convert a group of text to mtext.;;;They must be lined up vertically.;;;Peter Jamtgaard(defun C:t2m (/ CNT ENAM ELST INSP STRLST TSTR)(setq SSET (ssget (list (cons 0 "TEXT")))CNT 0)(repeat (sslength SSET)(setq ENAM (ssname SSET CNT)CNT (1+ CNT)ELST (entget ENAM)INSP (assoc 10 ELST)TXTCLR (cdr (assoc 62 ELST))TXTHT (cdr (assoc 40 ELST))TSTR (cdr (assoc 1 ELST)))(setq STRLST (cons (cons TSTR (cdr INSP)) STRLST))(setq INSP (mapcar '(lambda (X Y) (+ X Y)) INSP (list 0 0.0 TXTHT0.0))))(print STRLST)(setq STRLST (sort_list STRLST 2 '>=)MTSTR "")(print STRLST)(foreach N (mapcar 'car STRLST)(if (= MTSTR "")(setq MTSTR N)(setq MTSTR (strcat MTSTR "\\P" N))))(entmake(setq MLST (list(cons 0 "MTEXT")(cons 100 "AcDbEntity")(cons 410 (getvar "ctab"))(assoc 8 ELST)(cons 100 "AcDbMText")INSP(assoc 40 ELST)(cons 71 1)(cons 72 5)(cons 44 0.96)(cons 62 TXTCLR)(cons 1 MTSTR)(assoc 7 ELST))))(command "erase" SSET ""))(defun SORT_LIST (SLIST ITEM SYM)(setqSLIST (vl-sort SLIST '(lambda (n1 n2) ((eval SYM) (nth ITEM n1) (nthITEM n2))))))I'm trying to get the newly created MTEXT to be the same colour of the source text.It doesn't matter to me which DTEXT element is read for the colour, as most of the time the text selected will match each other for colour.
Where I'm falling down is... TXTCLR (cdr (assoc 62 ELST)).It occurs to me that the DXF code for colour is only present if the element has a colour set other than 'ByLayer'.So if the selected text is coloured 'ByLayer', there is not DXF code 62 to read.
So my question is, is it at all possible to only read the DXF code 62, if it is present?And only assign this DXF code to the newly created MTEXT if it exists in the source text?
Hopefully that was a clear enough explanation.
Thanks a lot for any help. Quick mod
(cons 62 (if TXTCLR TXTCLR 256)) Hi pBe, thanks so much for the quick reply.
So the issue wasn't reading the colour, it was writing it?
Yes lamensterms, (62) is not valid Awesome, thanks for that pBe.
NP lamensterms
页:
[1]