LISP FOR SELECTING TEXT HAVING SAME TEXT CONTENT & TRANSFERING THEM INTO A LAYER

LISP FOR SELECTING TEXT HAVING SAME TEXT CONTENT & TRANSFERING THEM INTO A LAYER

Anonymous
Not applicable
3,587 Views
8 Replies
Message 1 of 9

LISP FOR SELECTING TEXT HAVING SAME TEXT CONTENT & TRANSFERING THEM INTO A LAYER

Anonymous
Not applicable

Dear All,

 

i seek you help to provide me a lisp which could me following thing done

 

LISP FOR SELECTING ALL THE TEXT HAVING SAME TEXT CONTENT AND TRANSFERING THEM INTO A LAYER OF TEXT CONTENT NAME.

 

thanks in advance. plz reply soon. 

0 Likes
3,588 Views
8 Replies
Replies (8)
Message 2 of 9

RobDraw
Mentor
Mentor

@Anonymous wrote:

plz reply soon. 


If you're in a hurry, you might try posting in the right forum.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130


Rob

Drafting is a breeze and Revit doesn't always work the way you think it should.
Message 3 of 9

Anonymous
Not applicable

There are several ways to do this,
but try this:

(defun c:Trl (/ fromLay toLay ss objdata)
(setq fromLay (getstring t "\nName of the current layer:")
toLay (getstring t "\nNew layer: ")
ss (ssget "_X" (list (cons 8 fromLay)))
)
(repeat (sslength ss)
(setq
objdata (entget (ssname ss 0))
objdata (subst (cons 8 toLay) (cons 8 fromLay) objdata)
)
(entmod objdata)
(ssdel (ssname ss 0) ss)
)
(princ)
)
(prompt "\n Type >> TRL << ")

Júnior Nogueira.

Por favor,  Aceitar como Solução se meu post te ajudar.

Please Accept as Solution if my post helps you.

0 Likes
Message 4 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

....
(setq fromLay (getstring t "\nName of the current layer:")
toLay (getstring t "\nNew layer: ")
...

[That's not really what they're looking to do, but if it were, it could be done much more concisely with a CHPROP command, which would change the Layer of the entire selection all together.]

Kent Cooper, AIA
Message 5 of 9

Kent1Cooper
Consultant
Consultant

Yes, the Customization Forum would be a better place, but when you ask there, I have some questions.  If the text content is, for example, "REVISION 1" that you want to put all Text with that content on a Layer with that name, should it also put those whose content is "Revision 1" on that Layer [i.e. should it not be case-sensitive]?  Should it put only objects whose entire  content is the specified string, or all objects that contain  that string even if they might have more in them [such as "REVISION 1 13/06/18"]?  Does the Layer already exist?  I'd probably come up with some more if trying to work something out.

Kent Cooper, AIA
Message 6 of 9

imadHabash
Mentor
Mentor

Hi,

it can be done by FIND command ( without lisp ) . fill your content in Find What :  then press Find button then press Create Selection Set ( All ) button to find after that you have selected texts with grips . Now directly you can change the layer and as you wish . 

 

olp.png

Imad Habash

EESignature

Message 7 of 9

Anonymous
Not applicable

@Kent1CooperI think I was mistaken a little.
but I found this code in the forum searches I modified only one line and I believe it will meet the need to @Anonymous

 

(defun C:TFD (/ *error* doc mss n tc tclist duplist tcss); = Text [& Mtext] Find Duplicates
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (setvar cmdecho 1)
    (vla-endundomark doc)
    (princ)
  ); defun - *error*
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (if (setq mss (ssget "_X" (list '(0 . "*TEXT") (cons 410 (getvar 'ctab)))))
    (progn ; then
      (setvar 'cmdecho 0)
      (setq TFDss (ssadd)); initially empty duplicates selection set
      (repeat (setq n (sslength mss))
        (setq tc (cdr (assoc 1 (entget (ssname mss (setq n (1- n)))))))
          ; = text content of each
        (cond
          ((member tc duplist))
            ; = already in duplicates list [do nothing]
          ((member tc tclist) (setq duplist (cons tc duplist)))
            ; = already in content list [put in duplicates list]
          ((setq tclist (cons tc tclist)))
            ; = first instance of it [put in content list]
        ); cond
      ); repeat
      (setq col 0); base value for counting color numbers upward
      (foreach tc duplist ; assign colors to sets of duplicates
        (setq tcss (ssget "_X" (list '(0 . "*TEXT") (cons 1 tc))))
	(command "_.layer" "_make" "Text" "_color" 7 "" "")
;;;        (command "_.chprop" tcss "" "_color" (setq col (1+ col)) "")
	(command "_.chprop"  tcss "" "_layer" "Text" "")
        (repeat (setq n (sslength tcss)) (ssadd (ssname tcss (setq n (1- n))) TFDss))
          ; put in collective duplicates selection set
      ); foreach
      (setvar 'cmdecho 1)
      (if (> (sslength TFDss) 0)
        (sssetfirst nil TFDss); select/grip/highlight
        (prompt "\nNo Text/Mtext objects with duplicate text content found."); else
      ); if
    ); progn
  ); if
  (vla-endundomark doc)
  (princ)
); defun -- C:TFD

(prompt "\nType TFD for Text/Mtext - Find Duplicates.")
Message 8 of 9

nislam04
Participant
Participant

Next Level: 

Is it possible to assign this layer to the nearest line...?

 

I mean;

 

Is it possible to write a lisp routine where I will select a group of lines and texts then it will make a layer with a name of the text content and change the layer of the nearby line with newly created layer name?

 

Thank you

0 Likes
Message 9 of 9

dimber13
Community Visitor
Community Visitor

Is it possible to modify the TFD lisp to ask where to look for the duplicates in the first step? I don´t know too much about lisp programming and I´d really appreciate the help, thank you.

0 Likes