Jump to content

How to ASSOC a DXF Code, only IF it's present...


Recommended Posts

Posted

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 TXTHT
0.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)
(setq
SLIST (vl-sort SLIST '(lambda (n1 n2) ((eval SYM) (nth ITEM n1) (nth
ITEM 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.

Posted

Hi pBe, thanks so much for the quick reply.

 

So the issue wasn't reading the colour, it was writing it?

Posted
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

Posted

Awesome, thanks for that pBe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...