Author Topic: MTEXT to TEXT.  (Read 1501 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 242
MTEXT to TEXT.
« on: April 11, 2016, 05:23:12 PM »
How to get the text of a MTEXT with several lines?

OK.
OK.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: MTEXT to TEXT.
« Reply #1 on: April 11, 2016, 06:22:00 PM »
How to get the text of a MTEXT with several lines?

OK.

Have you tried EXPLODE command ?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

FELIX

  • Bull Frog
  • Posts: 242
Re: MTEXT to TEXT.
« Reply #2 on: April 11, 2016, 10:56:08 PM »
This serves me. If you have something better, please.
OK.

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun SPLIT-LINHA (str del / len lst pos SS II LL)
  (setq len (1+ (strlen del)))
  (while (setq pos (vl-string-search del str))
         (setq lst (cons (substr str 1 pos) lst))
         (setq str (substr str (+ pos len)))
  )
  (setq SS (reverse (cons str lst)))
  ;
  (SETQ LL '())
  (SETQ II 0)
  (REPEAT (LENGTH SS)
     (IF (/= "" (NTH II SS)) (SETQ LL (CONS (NTH II SS) LL)))
     (SETQ II (+ II 1))
  )
  (REVERSE LL)
)
;..............................................................................
(SETQ ENT (CAR (ENTSEL)))
(SETQ LIS (ENTGET ENT))
(SETQ TIP (CDR (ASSOC 0 LIS)))
(IF (= TIP "MTEXT")
  (PROGN
  (SETQ TXTSE (CDR (ASSOC  1 LIS)))
  (SETQ TXTPT (CDR (ASSOC 10 LIS)))
  (SETQ TXTHE (CDR (ASSOC 40 LIS)))
  (SETQ LTXT  (SPLIT-LINHA TXTSE "\\P"))
  )
)
(PRINT LTXT)
(PRINC)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
OK.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: MTEXT to TEXT.
« Reply #3 on: April 12, 2016, 08:07:58 AM »
Quote from: ribarm

Have you tried EXPLODE command ?


Maybe OP means when an MTEXT object contains more than 250 characters and is split up into multiple chunks?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: MTEXT to TEXT.
« Reply #4 on: April 12, 2016, 12:55:57 PM »
Something like this?
Code - Auto/Visual Lisp: [Select]
  1. (defun mtextlines ( ent / enx itm str )
  2.     (setq enx (reverse (entget ent))
  3.           str (list (cdr (assoc 1 enx)))
  4.     )
  5.     (while (setq itm (assoc 3 enx))
  6.         (setq str (cons (cdr itm) str)
  7.               enx (cdr (member itm enx))
  8.         )
  9.     )
  10.     (LM:str->lst (apply 'strcat str) "\\P")
  11. )
  12.  
  13. ;; String to List  -  Lee Mac
  14. ;; Separates a string using a given delimiter
  15. ;; str - [str] String to process
  16. ;; del - [str] Delimiter by which to separate the string
  17. ;; Returns: [lst] List of strings
  18.  
  19. (defun LM:str->lst ( str del / pos )
  20.     (if (setq pos (vl-string-search del str))
  21.         (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
  22.         (list str)
  23.     )
  24. )
Code - Auto/Visual Lisp: [Select]
  1. (mtextlines (car (entsel)))

FELIX

  • Bull Frog
  • Posts: 242
Re: MTEXT to TEXT.
« Reply #5 on: April 12, 2016, 10:31:10 PM »
Very good! Code more compact, as I like.

Okay and Close.
OK.