Author Topic: Filtering out specific text  (Read 8285 times)

0 Members and 1 Guest are viewing this topic.

Dent Cermak

  • Guest
Filtering out specific text
« Reply #30 on: August 11, 2005, 08:23:16 AM »
grandma moses

johnson

  • Guest
Re: Filtering out specific text
« Reply #31 on: January 13, 2011, 09:52:16 AM »
I have this list which will remove an entire line with specific text.

I can't remember where I got this so if it's yours let me know and I'll credit you with it

Code: [Select]
(defun C:RMT(/ eset en enlist)

  ;;;--- Let the user select mtext entities
  (if (setq eset(ssget (list (cons 0 "MTEXT"))))
    (progn

      (setq rstr(getstring T "\n Remove lines containing: "))
                    
      ;;;--- Set up a counter
      (setq cntr 0)
                    
      ;;;--- Loop through each entity
      (while (< cntr (sslength eset))
                                
        ;;;--- Get the entity's name
        (setq en(ssname eset cntr))

        ;;;--- Get the DXF group codes of the entity
        (setq enlist(entget en))

        (if(assoc 3 enlist)
          (progn
            (setq mtxtVal "")
            (foreach a enlist (if(= (car a) 3)(setq mtxtVal(strcat mtxtVal (cdr a)))))
            (setq mtxtVal(strcat bigStr (cdr(assoc 1 enlist))))
          )
          (setq mtxtVal(cdr(assoc 1 enlist)))
        )
        (if(/= mtxtVal "")
          (progn
            (setq mtxtLines(list))
            (setq mstpt 1 mcnt 1)
            (setq msrf "\\P")
            (while (< mcnt (+(-(strlen mtxtVal) (strlen msrf))1))
              (setq mtstStr(substr mtxtVal mcnt (strlen msrf)))
              (if(= mtstStr msrf)
                (progn
                  (setq mtxtLines(append mtxtLines (list (substr mtxtVal mstpt (- mcnt mstpt)))))
                  (setq mstpt (+ mcnt 2))
                  (setq mcnt(+ mcnt 1))
                )
              )
              (setq mcnt(+ mcnt 1))
            )
            (if(< mstpt (strlen mtxtVal))
              (setq mtxtLines(append mtxtLines (list (substr mtxtVal mstpt))))
            )
            (setq Lcnt 0)
            (while(< Lcnt (length mtxtLines))
              (setq a(nth Lcnt mtxtLines))
              (setq cnt 1)
              (while (< cnt (strlen a))
                (setq chStr(substr a cnt (strlen rstr)))
                (if(= rstr chStr)
                  (progn
                    (setq newList(list))
                    (foreach b mtxtLines
                      (if(/= b a)(setq newList(append newList (list b))))
                    )
                    (setq mtxtLines newList)
                    (setq cnt 10000 Lcnt -1)
                  )
                  (setq cnt(+ cnt 1))
                )
              )
              (setq LCnt(+ LCnt 1))              
            )
            (if(> (length mtxtLines) 0)
              (progn
                (setq newLine "")
                (setq lcntr 0)
                (foreach a mtxtLines
                  (if(= lcntr 0)
                    (setq newLine(strcat newLine a))
                    (setq newLine(strcat newLine "\\P" a))
                  )
                  (setq lcntr (+ lcntr 1))
                )
                (setq enlist(subst (cons 1 newLine)(assoc 1 enlist)enlist))
                (entmod enlist)
                (entupd en)
              )
            )  
          )
        )
        (setq cntr (+ cntr 1))
      )
    )                    
  )
  (princ)
)



here how to filter some text using contents.i want count perticular contents from bulk text group.suppose 1000 number of text and mtext is showing,i want filter some contents "XYZ" text(or Mtext).