Author Topic: TEXT LAYER LISP  (Read 1855 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
TEXT LAYER LISP
« on: February 01, 2021, 08:53:57 AM »
Hi.I  have 4 different words (multy times in the same drawing) in layer with name KYROSI. This words are (AA, DA, PA, AD). I am searching for a lisp to select all

1)  AA text and move them to layer TEXT-AA
2)  DA text and move them to layer TEXT-DA
3)  PA text and move them to layer TEXT-PA
4)  AD text and move them to layer TEXT-AD

use (command "_.-style" "_MYTEXTSTYLE" "arial.ttf" "_annotative" "_yes" "_no" 2.5 1.0 0.0 "_no" "_no" "_no")

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: TEXT LAYER LISP
« Reply #1 on: February 01, 2021, 05:33:00 PM »
Just use a ssget Text make a selection set of text, then use wcmatch to look for "AA" etc you will need to repeat searching the selection for each "Word"
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: TEXT LAYER LISP
« Reply #2 on: February 01, 2021, 05:44:35 PM »
Quick one -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt2lay ( / i l s x )
  2.     (setq l '("AA" "DA" "PA" "AD"))
  3.     (if (setq s (ssget "_X" (append '((0 . "TEXT") (-4 . "<OR")) (mapcar '(lambda ( x ) (cons 1 x)) l) '((-4 . "OR>")))))
  4.         (repeat (setq i (sslength s))
  5.             (setq i (1- i)
  6.                   x (entget (ssname s i))
  7.             )
  8.             (entmod (subst (cons 8 (strcat "TEXT-" (cdr (assoc 1 x)))) (assoc 8 x) x))
  9.         )
  10.     )
  11.     (princ)
  12. )

PM

  • Guest
Re: TEXT LAYER LISP
« Reply #3 on: February 01, 2021, 06:10:49 PM »
Thanks Lee Mac. Can you update the code to work from Mtext and change the selected text color to bylayer?

Thanks
« Last Edit: February 01, 2021, 06:22:57 PM by PM »

PM

  • Guest
Re: TEXT LAYER LISP
« Reply #4 on: February 02, 2021, 01:20:44 PM »
I try to change the code to this

Code - Auto/Visual Lisp: [Select]
  1.     (defun c:txt2lay ( / i l s x )
  2.         (setq l '("AA" "DA" "PA" "AD"))
  3.         (if (setq s (ssget "_X" (append '((0 . "MTEXT") (-4 . "<OR")) (mapcar '(lambda ( x ) (cons 1 x)) l) '((-4 . "OR>")))))
  4.             (repeat (setq i (sslength s))
  5.                 (setq i (1- i)
  6.                       x (entget (ssname s i))
  7.                 )
  8.                 (entmod (subst (cons 8 (strcat "TEXT-" (cdr (assoc 1 x)))) (assoc 8 x) x))
  9.             )
  10.         )
  11.         (princ)
  12.     )
  13.  


but is not working for mtext . Any options?

PM

  • Guest
Re: TEXT LAYER LISP
« Reply #5 on: February 13, 2021, 04:11:52 PM »
I try to change the code to this but is not working. Why?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt2lay ( / i l s x )
  2.    (setq l '("AA" "DA" "PA" "AD"))
  3.    (if (setq s (ssget "_X" (append '((0 . "TEXT,MTEXT") (-4 . "<OR")) (mapcar '(lambda ( x ) (cons 1 x)) l) '((-4 . "OR>")))))
  4.   (repeat (setq i (sslength s))
  5.  (setq i (1- i)
  6.   x (entget (ssname s i))
  7.  )
  8.  (entmod (subst (cons 8 (strcat "TEXT-" (cdr (assoc 1 x)))) (assoc 8 x) x))
  9.   )
  10.    )
  11.    (princ)
  12.     )
  13.  

Thanks

Lee Mac

  • Seagull
  • Posts: 12904
  • London, England
Re: TEXT LAYER LISP
« Reply #6 on: February 13, 2021, 04:21:01 PM »
Your MText may contain formatting codes embedded within the text content.

PM

  • Guest
Re: TEXT LAYER LISP
« Reply #7 on: February 14, 2021, 03:17:30 AM »
Hi lee . I upload a photo with the text properties. I attach and the dxf file. The mtext are in greek language. I export this dxf from QGIS (if it helps).

Thanks


BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: TEXT LAYER LISP
« Reply #8 on: February 14, 2021, 06:40:19 PM »
The simplest way is to pick the mtext, get the string then use lee's unformat this will return the greek text. So you could make a While that selects the mtext etc strips it and makes the List L to use in the code.

Code: [Select]
(setq l '())
(while (setq ent (entsel "\Pick a text Enter to exit"))
(setq str (cdr (assoc 1 (entget (car ent)))))
(setq nstr (LM:unformat str nil))
(setq L (cons nstr L))
)

Did notice because of the dxf the layers do not exist so code needs a make layer check also or just make it, if it exists it will continue ok.
« Last Edit: February 14, 2021, 06:45:23 PM by BIGAL »
A man who never made a mistake never made anything

PM

  • Guest
Re: TEXT LAYER LISP
« Reply #9 on: February 18, 2021, 03:47:31 PM »
Hi Bigal. Can you help with this change?

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: TEXT LAYER LISP
« Reply #10 on: February 18, 2021, 06:28:07 PM »
This needs to be changed (cdr (assoc 1 x)) returns the text including the mtext formatting so need to (setq nstr (LM:unformat (cdr (assoc 1 x)) nil)) then (strcat "TEXT - " nstr)
A man who never made a mistake never made anything