Jump to content

Wildcard selection sets


ollie

Recommended Posts

Hi All

 

One of the staff from my work asked me for a method of counting the number of instances of a string begining with a character on a specific layer

 

That gave me the following idea which i felt the community may find useful

 

(setq sset (ssget "X" (list(cons 1 "A*")(cons 8 "Exlayer"))))

 

The asterix (*) allows for wildcard filtering of entities.

 

This also works with *char* for searching mid string

 

Ollie

Link to comment
Share on other sites

Thanks for sharing that Ollie,

 

another method:

 

(defun c:tcnt  (/ ss tStr)
 (vl-load-com)
 (if (and (setq ss (ssget "_X" (list (cons 0 "*TEXT"))))
          (setq tStr (getstring t "\nText to Search For: ")))
   (progn
     (setq ss (vl-remove-if-not
                (function
                  (lambda (x)
                    (wcmatch
                      (cdr (assoc 1 (entget x))) tStr)))
              (mapcar 'cadr (ssnamex ss))))
     (if (not (zerop (length ss)))
       (princ (strcat (rtos (length ss) 2 0) " Item(s) Found."))
       (princ "\nNo Matching Text Strings. ")))
   (princ "\n<!> No Text Found in Drawing <!>"))
 (princ))

Link to comment
Share on other sites

Thanks for sharing that Ollie,

 

 

No Probs its good to give back to the community for a change :)

 

Worth noting. Where I place "A*" as a literal string a variable can be used

 

Ollie

Link to comment
Share on other sites

That is awsome. Does it work in a similar method to Regex for PERL?

 

I can't be certain about that, but wildcard characters are pretty standard. :)

Link to comment
Share on other sites

Ollie,

Note that your example is Case sensitive. To make it non-case sensitive use this:

(setq sset (ssget "X" (list(cons 1 "[aA]*")(cons 8 "Exlayer"))))

Link to comment
Share on other sites

For another example of wcmatch within ssget see this example by Evgeniy

Here I explained how it works:

http://www.theswamp.org/index.php?topic=21058.msg255696#msg255696

 

He is a master of wildcard characters & there usage.

 

Thanks CAB

 

I have had a chance to play about with the wildcard system and it is more or less Regex for perl.

 

[a-f]* will find asdf but not Asdf (match chars from class [] 0 or more times

 

the only main difference I have noticed so far is that '\' chars such as \w, \d don't work

 

Ollie

Link to comment
Share on other sites

Thanks for sharing that Ollie,

 

another method:

 

(defun c:tcnt  (/ ss tStr)
 (vl-load-com)
 (if (and (setq ss (ssget "_X" (list (cons 0 "*TEXT"))))
          (setq tStr (getstring t "\nText to Search For: ")))
   (progn
     (setq ss (vl-remove-if-not
                (function
                  (lambda (x)
                    (wcmatch
                      (cdr (assoc 1 (entget x))) tStr)))
              (mapcar 'cadr (ssnamex ss))))
     (if (not (zerop (length ss)))
       (princ (strcat (rtos (length ss) 2 0) " Item(s) Found."))
       (princ "\nNo Matching Text Strings. ")))
   (princ "\n<!> No Text Found in Drawing <!>"))
 (princ))

 

 

why not ask for the filter, then select the text. you are forcing the routine to iterate through every piece of text in the drawing.

Link to comment
Share on other sites

why not ask for the filter, then select the text. you are forcing the routine to iterate through every piece of text in the drawing.

 

Good point Alan - not sure what I was thinking when I wrote that :unsure:

Link to comment
Share on other sites

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