TO AVOID CASE SENSITIVE IN TEXT SELECTION FROM LISP

TO AVOID CASE SENSITIVE IN TEXT SELECTION FROM LISP

Anonymous
Not applicable
1,951 Views
12 Replies
Message 1 of 13

TO AVOID CASE SENSITIVE IN TEXT SELECTION FROM LISP

Anonymous
Not applicable

Dear Helpers,

 

I got a lisp code that can select text elements in entire drawing by user input. But it's not working for case sensitive letters and also not asking for window selection. Please do needful.

 

(defun C:SWT (/ str ss) ; = Find String(s) by Content
(setq str (getstring "\nYour [full or partial] string content to search for: "))
(if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 (strcat "*" str "*")) (cons 410 (getvar 'ctab)))))
(sssetfirst nil ss); select/highlight/grip
); if
); defun

 

Regards,

T.Brahmanandam.

0 Likes
Accepted solutions (1)
1,952 Views
12 Replies
Replies (12)
Message 2 of 13

_gile
Consultant
Consultant

Hi,

 

Try this:

 

(defun C:SWT (/ str ss i txt)
  (if
    (and
      (setq str (getstring "\nYour [full or partial] string content to search for: "))
      (setq ss (ssget '((0 . "*TEXT"))))
    )
     (progn
       (setq str (strcat "*" (strcase str) "*"))
       (repeat (setq i (sslength ss))
         (setq txt (ssname ss (setq i (1- i))))
         (if (not (wcmatch (strcase (cdr (assoc 1 (entget txt)))) str))
           (ssdel txt ss)
         )
       )
       (sssetfirst nil ss)
     )
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 13

Anonymous
Not applicable

Excellent Sir,

 

Could you please update to block selections also, as like you ddi for text selection?

 

Regards,

T.Brahmanandam

0 Likes
Message 4 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

Could you please update to block selections also, as like you ddi for text selection?


 

If you are asking that for case-sensitivity, be aware that Block [and Layer] names in (ssget) filter lists are not  case-sensitive the way text-string content is.

 

(if

  (and

    (setq blkname (getstring "\nBlock name to find insertions of: "))

    (setq blks (ssget (list (cons 2 blkname))))

  )

  (sssetfirst nil blks)

)

 

It doesn't matter if you enter the Block name in a different CaSe CoMbInAtIoN from the way it is in the Block table -- it will find them.

Kent Cooper, AIA
0 Likes
Message 5 of 13

Anonymous
Not applicable

Thank you Sir,

 

I have updated the code with your hints, but not working to select the blocks with wildcart match.

 

(defun C:SBT (/ blkname blks i txt)
(if

(and

(setq blkname (getstring "\nBlock name to find insertions of: "))

(setq blks (ssget (list (cons 2 blkname))))

)
(progn
(setq blkname (strcat "*" (strcase blkname) "*"))
(repeat (setq i (sslength blks))
(setq txt (ssname blks (setq i (1- i))))
(if (not (wcmatch (strcase (cdr (assoc 1 (entget txt)))) blkname))
(ssdel txt blks)
)
)
(sssetfirst nil blks)
)
)
(princ)
)

0 Likes
Message 6 of 13

_gile
Consultant
Consultant

if you want to get help, you have to clearly explain what you mean with "select the blocks with wildcart match".



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 13

Anonymous
Not applicable

Sir,

If we have some blocks in drawing as below

 

"LED LAMP-A",

"LED LAMP-B"

 

"CFL LAMP-A"

"CFL LAMP-B"

 

"TUBE LIGHT-A"

"TUBE LIGHT-B"

 

1) If user give user input as TUBE, then all blocks which contains name as TUBE should select. In this case all TUBE LIGHT-A & TUBE LIGHT-B should be selected.

2) If user give user input as CFL, then all blocks which contains name as TUBE should select. In this case all CFL LAMP-A & CFL LAMP-B should be selected.

3) If user give user input as LED, then all blocks which contains name as TUBE should select. In this case all LED LAMP-A & LED LAMP-B should be selected.

Sir, I think this explanation gives better idea to you for my requirement. Advanced thank you sir.

0 Likes
Message 8 of 13

dbhunia
Advisor
Advisor

Try this

 

(setq blks (ssget "_A" (list (2 . "*blkname*"))))


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 9 of 13

dlanorh
Advisor
Advisor

This is correct if the supplied text is not at the start or the end of the name

It will not find blocks that start with blkname or end with blkname as it is used with wcmatch and there are no characters before in the start case or after in the end case

 

(setq blkname (strcat "*" (strcase blkname) "*"))

If blkname text is at the start of the blockname string then this has to be changed to

 

(setq blkname (strcat (strcase blkname) "*"))

If blkname text is at the end of the blockname string then this has to be changed to

 

(setq blkname (strcat "*" (strcase blkname))) 

 

I am not one of the robots you're looking for

0 Likes
Message 10 of 13

Kent1Cooper
Consultant
Consultant

@dlanorh wrote:

This is correct if the supplied text is not at the start or the end of the name

It will not find blocks that start with blkname or end with blkname as it is used with wcmatch and there are no characters before in the start case or after in the end case

....


 

Not true.  The  *  wildcard stands in for any character or combination of characters, including no  characters.  It is very  commonly used in a situation where it does  find things in which there are no characters in place of the  *  wildcard:

 

(ssget "_X" '((0 . "*POLYLINE")))

 

is used all the time to find Polylines of any variety, and it finds both LWPOLYLINE entities for which the LW are covered by the  * , and POLYLINE entities for which there are no characters in place of the  * .  Likewise, *TEXT is used to find both TEXT and MTEXT entities.

 

Easy proof:

Command: (wcmatch "TEST" "TEST*")
T
Command: (wcmatch "TEST" "*TEST")
T

Command: (wcmatch "TEST" "*TEST*")
T

Kent Cooper, AIA
0 Likes
Message 11 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... 

I have updated the code with your hints, but not working to select the blocks with wildcart match.

 

….

 

Try it this way [untested]:

 

(defun C:SBT (/ blkname blks i txt)
  (if

    (and

      (setq blkpart (getstring "\nPartial Block name for insertions of Blocks containing it: "))

      (setq blks (ssget (list (cons 2 (strcat "*" (strcase blkpart) "*")))))

    )
    (sssetfirst nil blks)
  )
  (princ)
)

Kent Cooper, AIA
0 Likes
Message 12 of 13

Anonymous
Not applicable

Thank you Sir. It's working fine.

0 Likes
Message 13 of 13

dlanorh
Advisor
Advisor

@Kent1Cooper wrote:


Easy proof:

Command: (wcmatch "TEST" "TEST*")
T
Command: (wcmatch "TEST" "*TEST")
T

Command: (wcmatch "TEST" "*TEST*")
T


 

You are correct Robot Happy I'm obviously having another senior moment and confusing this with something else. Robot Embarassed

I am not one of the robots you're looking for

0 Likes