ollie Posted June 29, 2009 Posted June 29, 2009 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 Quote
Lee Mac Posted June 29, 2009 Posted June 29, 2009 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)) Quote
ollie Posted June 29, 2009 Author Posted June 29, 2009 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 Quote
Lee Mac Posted June 29, 2009 Posted June 29, 2009 Bear in mind that all wildcard characters will work for this, hence for a textstring that contains numbers: "*#*" can be used. A good example: http://www.cadtutor.net/forum/showpost.php?p=72097&postcount=8 Quote
ollie Posted June 29, 2009 Author Posted June 29, 2009 Bear in mind that all wildcard characters will work for this, hence for a textstring that contains numbers: "*#*" can be used. A good example: http://www.cadtutor.net/forum/showpost.php?p=72097&postcount=8 That is awsome. Does it work in a similar method to Regex for PERL? Quote
Lee Mac Posted June 29, 2009 Posted June 29, 2009 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. Quote
CAB Posted June 30, 2009 Posted June 30, 2009 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")))) Quote
CAB Posted June 30, 2009 Posted June 30, 2009 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. Quote
ollie Posted June 30, 2009 Author Posted June 30, 2009 For another example of wcmatch within ssget see this example by EvgeniyHere 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 Quote
Lee Mac Posted June 30, 2009 Posted June 30, 2009 For another example of wcmatch within ssget see this example by EvgeniyHere I explained how it works: http://www.theswamp.org/index.php?topic=21058.msg255696#msg255696 He is a master of wildcard characters & there usage. Nice example Alan Quote
alanjt Posted June 30, 2009 Posted June 30, 2009 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. Quote
Lee Mac Posted July 1, 2009 Posted July 1, 2009 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 Quote
Recommended Posts
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.