Jump to content

How to select all texts except which contains "X" text


Recommended Posts

Posted

Hi every one! Im new in the forum but I´ve beening using for lasts weeks to solve a lot of doubts.

 

Now i´m trying to create a lisp which select all text and mtext entities except those which contains some specific text, but I get the oposite result

(sssetfirst nil (Setq SS (ssget "_X" (list(cons 0 "Text,Mtext") (cons 1 (strcat "*" "NOTAS PARTICULARES" "*")) (cons 410 (getvar 'ctab))

       );list

      );ssget

     );setq

    );sssetfirst

(princ)

 

Can someone help me

Thanks in advance

Posted

Give this a shot. 

 

(sssetfirst nil (Setq SS (ssget "_X" (list(cons 0 "Text,Mtext") (cons -4 "<NOT")(cons 1 (strcat "*" "NOTAS PARTICULARES" "*"))(cons -4 "NOT>") (cons 410 (getvar 'ctab))

       );list

      );ssget

     );setq

    );sssetfirst

(princ)

 

  • Like 1
Posted (edited)

You can achieve this using the wildcard not operator ("~") :

(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(1 . "~*NOTAS PARTICULARES*") (cons 410 (getvar 'ctab)))))

However, if you wanted to exclude multiple patterns by separating the patterns using a comma (e.g. "PATTERN1,PATTERN2") you should note that the not operator will only apply to the first wildcard pattern in the delimited string (e.g. "~PATTERN1,PATTERN2" will still include "PATTERN2") :

_$ (wcmatch "PATTERN1" "~PATTERN1,PATTERN2")
nil
_$ (wcmatch "PATTERN2" "~PATTERN1,PATTERN2")
T

And so if you were looking to exclude multiple patterns, you could use either:

(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(-4 . "<NOT") '(1 . "PATTERN1,PATTERN2") '(-4 . "NOT>") (cons 410 (getvar 'ctab)))))

Or:

(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(1 . "~PATTERN1") '(1 . "~PATTERN2") (cons 410 (getvar 'ctab)))))

Since the filter list for an ssget expression implements an implicit AND logic.

Edited by Lee Mac
  • Like 3
Posted
10 minutes ago, Lee Mac said:

You can achieve this using the wildcard not operator ("~") :


(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(1 . "~*NOTAS PARTICULARES*") (cons 410 (getvar 'ctab)))))

However, if you wanted to exclude multiple patterns by separating the patterns using a comma (e.g. "PATTERN1,PATTERN2") you should note that the not operator will only apply to the first wildcard pattern in the delimited string (e.g. "~PATTERN1,PATTERN2" will still include "PATTERN2") :


_$ (wcmatch "PATTERN1" "~PATTERN1,PATTERN2")
nil
_$ (wcmatch "PATTERN2" "~PATTERN1,PATTERN2")
T

And so if you were looking to exclude multiple patterns, you could use either:


(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(-4 . "<NOT") '(1 . "PATTERN1,PATTERN2") '(-4 . "NOT>") (cons 410 (getvar 'ctab)))))

Or:


(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(1 . "~PATTERN1") '(1 . "~PATTERN2") (cons 410 (getvar 'ctab)))))

Since the filter list for an ssget expression implements an implicit AND logic.

I Really thank you Lee. It works perfectly and your explanation helped me a lot 

  • 2 weeks later...
Posted
On 1/15/2021 at 1:36 PM, Lee Mac said:

You can achieve this using the wildcard not operator ("~") :

Hello guys. I have been using this program without any problem at all, but today it doesn`t work well as shown in the image:

image.thumb.png.590716f20e4a96466ba9738faf954b68.png

It select all text including the Mtext with "~*NOTAS PARTICULARES*" condition.

 

 

I attach the showed file hoping you can see why is not working in this case.

I really thank you for your help

P-459_50_PR.dwg

Posted

@JovanG In long MTEXT strings like this, you also have to filter for the DXF code 3, not just DXF code 1. Note - This is what your entity codes look like for the MTEXT:

((-1 . <Entity name: 1cf6aa46180>) (0 . "MTEXT") (330 . <Entity name: 1cf57559700>) (5 . "3610") (100 . "AcDbEntity")
(67 . 0) (410 . "Model") (8 . "Textos") (62 . 7) (6 . "Continuous") (370 . 13) (100 . "AcDbMText") (10 835795.0 1.19418e+06 0.0)
(40 . 1.0) (41 . 114.291) (46 . 8.27327) (71 . 1) (72 . 5)
(3 . "{\\Fdgn000|c0;NOTAS PARTICULARES.\\P\\P1.\tSe ha considerado una sobreexcavación de 15 mc bajo la cama en el tramo C921-C922.
\\P2.\tLa cámara en diseño N2001 se construirá sobre la red existente convirtiendo ese tramo en arranque. La ubicación en planta se")
(1 . "rá la indicada en el cuadro de localización de cámaras y la profundidad, la indicada en el cuadro 1.}") (7 . "Style-Arial")
(210 0.0 0.0 1.0) (11 1.0 2.88641e-12 0.0) (42 . 109.571) (43 . 7.35743) (50 . 2.88641e-12) (73 . 2) (44 . 0.903614))

Notice the test string has a 3 in the dotted pair instead of a 1.

 

Try this now:

(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(1 . "~*NOTAS PARTICULARES*") '(3 . "~*NOTAS PARTICULARES*") (cons 410 (getvar 'ctab)))))

 

  • Like 1
Posted
49 minutes ago, pkenewell said:

Try this now:


(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(1 . "~*NOTAS PARTICULARES*") '(3 . "~*NOTAS PARTICULARES*") (cons 410 (getvar 'ctab)))))

Great! thank you @pkenewell, now I know why it doesn`t works in that particular string, that in my case was longer than normal, but for some reason now is not selecting anything when runing the program. do you have any idea?

 

Posted (edited)

@JovanG - Hmm I think you have to include the OR and NOT logical operators, but I am having trouble getting this to work. Perhaps someone else here can correct me?

 

I thought this would work:

(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(-4 . "<OR") '(1 . "~*NOTAS PARTICULARES*") '(3 . "~*NOTAS PARTICULARES*") '(-4 . "OR>") (cons 410 (getvar 'ctab)))))

or this?

(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(-4 . "<NOT") '(-4 . "<OR") '(1 . "*NOTAS PARTICULARES*") '(3 . "*NOTAS PARTICULARES*") '(-4 . "OR>") '(-4 . "NOT>") (cons 410 (getvar 'ctab)))))

But both seem to select everything.

 

EDIT: I tried this combination too - still doesn't work. Don't know what I am doing wrong here:

(sssetfirst nil 
   (ssget "_X" 
      (list
         '(0 . "TEXT,MTEXT") 
         '(-4 . "<OR") 
            '(-4 . "<NOT") 
               '(1 . "*NOTAS PARTICULARES*") 
            '(-4 . "NOT>")
            '(-4 . "<NOT")
               '(3 . "*NOTAS PARTICULARES*")
            '(-4 . "NOT>")
         '(-4 . "OR>")
         (cons 410 (getvar 'ctab))
      )
   )
)

 

Edited by pkenewell
Posted (edited)
16 hours ago, pkenewell said:

you have to include the OR and NOT logical operators

That`s an excellent approach @pkenewell. That give me an idea of how can it works, but if somebody can help me with the piece of code that is lacking I would really appreciate your help, because probably it will take me some time to get it (if I do, because, like you said,  both codes you wrote seem to select everything and I´m getting same result with mine).

 

Thanks for all. Wish you a good day!

Edited by JovanG
Posted
17 hours ago, pkenewell said:

@JovanG - Hmm I think you have to include the OR and NOT logical operators, but I am having trouble getting this to work. Perhaps someone else here can correct me?

 

I thought this would work:


(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(-4 . "<OR") '(1 . "~*NOTAS PARTICULARES*") '(3 . "~*NOTAS PARTICULARES*") '(-4 . "OR>") (cons 410 (getvar 'ctab)))))

or this?


(sssetfirst nil (ssget "_X" (list '(0 . "TEXT,MTEXT") '(-4 . "<NOT") '(-4 . "<OR") '(1 . "*NOTAS PARTICULARES*") '(3 . "*NOTAS PARTICULARES*") '(-4 . "OR>") '(-4 . "NOT>") (cons 410 (getvar 'ctab)))))

But both seem to select everything.

 

EDIT: I tried this combination too - still doesn't work. Don't know what I am doing wrong here:


(sssetfirst nil 
   (ssget "_X" 
      (list
         '(0 . "TEXT,MTEXT") 
         '(-4 . "<OR") 
            '(-4 . "<NOT") 
               '(1 . "*NOTAS PARTICULARES*") 
            '(-4 . "NOT>")
            '(-4 . "<NOT")
               '(3 . "*NOTAS PARTICULARES*")
            '(-4 . "NOT>")
         '(-4 . "OR>")
         (cons 410 (getvar 'ctab))
      )
   )
)

 

 

@Lee Mac You are the resident expert on wildcard matching, regular expressions and Selection set filtering. Any ideas on this?

 

Posted

Filtering on DXF group 3 is problematic in general, given that there are potentially multiple occurrences of this group within the DXF data - even a simple ssget filter such as the following will be unsuccessful:

(ssget "_X" '((0 . "MTEXT") (3 . "*NOTAS PARTICULARES*")))

However, since each DXF group 3 entry will contain a 250 character portion of the MText content, there is a chance that the target pattern will be spread between the values held by two of such groups, and therefore could not be matched by any ssget filter list of the above form. There is also the possibility that the target text wil be interspersed with MText formatting codes, which will also cause this selection method to fail.

 

The most reliable solution would be to acquire a selection set of all MText objects within the current layout/viewport, iterate over the set and, for each entity, construct a string representing the entire MText content (from all DXF group 3 entries and the DXF group 1 entry), remove all MText formatting codes from the string, and then use the wcmatch function or vl-string-search function to test whether the target string is present, removing or retaining the entity from the selection set as required.

Posted (edited)

@Lee Mac thanks - I was afraid that was the case. I think the OP changed to iterating through the selection from his following post. Too bad ssget can't handle that type of situation.

Edited by pkenewell
Posted

Oh, now I can see why it doesn´t works by filtering on DXF group 3. I´ll try by using wcmatch function. Thank you @Lee Mac and thank you too @pkenewell for all your help.

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...