Mihail Posted October 13, 2022 Posted October 13, 2022 (edited) Hi All, Newbie into Lisp here. I am trying to find a way to search for a particular word within a long MTEXT and select all that text I compiled a short code from what I found here on this forum but I can't make it work: (defun C:seltxt (/ SS) (setq SS (ssget "_X" (list '(0 . "*TEXT") '(1 . "*DESIGNER*") '(3 . "*DESIGNER*") (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (princ) ) Any help with fixing this would be beneficial Please find attached an example DWG TEST1.dwg Edited October 13, 2022 by SLW210 Added Code Tags! Quote
Steven P Posted October 13, 2022 Posted October 13, 2022 For your search you will need to put an OR statement to get the 1 or 3 texts, at the moment it is searching 1 and 3 and if true for both (Lee Mac has a good explanation and examples on his website) I tried this and -quickly- just searching for '(3 . "*DESIGNER*") didn't work for me, but '(1 did... not sure why yet though. 1 1 Quote
mhupp Posted October 13, 2022 Posted October 13, 2022 (edited) like StevenP said This needs an or logic. what your ssget is looking for text that have both 1and 3 strings. were you need to be looking for one or the other. http://www.lee-mac.com/ssget.html#logical (defun C:seltxt (/ SS) (setq SS (ssget "_X" (list '(0 . "*TEXT") '(-4 . "<OR") '(1 . "*DESIGNER*") '(3 . "*DESIGNER*") '(-4 . "OR>") (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (princ) ) --edit '(3 . "*DESIGNER*") worked for me Steven. Looks like SLW210 updated the file maybe thats why? Edited October 13, 2022 by mhupp 2 1 Quote
Steven P Posted October 13, 2022 Posted October 13, 2022 41 minutes ago, mhupp said: '(3 . "*DESIGNER*") worked for me Steven. Looks like SLW210 updated the file maybe thats why? It looked all OK, so was confused when it should have worked, was busy earlier so didn't work out why or give a link in my answer (lunch now) Lee MAc SSGET reference page is: http://lee-mac.com/ssget.html and for very-very long text code 3 4 1 172 304 should get -all- the text considered (250 characters for each) Quote
Mihail Posted October 13, 2022 Author Posted October 13, 2022 1 hour ago, mhupp said: like StevenP said This needs an or logic. what your ssget is looking for text that have both 1and 3 strings. were you need to be looking for one or the other. http://www.lee-mac.com/ssget.html#logical (defun C:seltxt (/ SS) (setq SS (ssget "_X" (list '(0 . "*TEXT") '(-4 . "<OR") '(1 . "*DESIGNER*") '(3 . "*DESIGNER*") '(-4 . "OR>") (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (princ) ) --edit '(3 . "*DESIGNER*") worked for me Steven. Looks like SLW210 updated the file maybe thats why? Thank you for your help! What I noticed it is indeed working with simple text bot not at all with MTEXT. I even tested only with MTEXT and no luck. Any ideea why? Quote
ronjonp Posted October 13, 2022 Posted October 13, 2022 If you have super long text the 3 code could fail if the contents is not within the first entry: IMO it's much easier to select all text then remove items that don't match. (defun c:seltxt (/ ss) (if (setq ss (ssget "_X" (list '(0 . "*TEXT") (cons 410 (getvar 'ctab))))) (progn (foreach e (mapcar 'cadr (ssnamex ss)) (or (wcmatch (strcase (vla-get-textstring (vlax-ename->vla-object e))) "*DESIGNER*") (ssdel e ss) ) ) (sssetfirst nil ss) ) ) (princ) ) But you could also use the FIND command to do the same. 3 Quote
Mihail Posted October 13, 2022 Author Posted October 13, 2022 Thank you! Appreciate a lot the help. It is working. You guys are brilliant! 1 Quote
mhupp Posted October 13, 2022 Posted October 13, 2022 3 hours ago, Mihail said: Thank you for your help! What I noticed it is indeed working with simple text bot not at all with MTEXT. I even tested only with MTEXT and no luck. Any ideea why? Seems to work in BricsCAD. but @ronjonp to the rescue. 1 Quote
ronjonp Posted October 13, 2022 Posted October 13, 2022 1 hour ago, Mihail said: Thank you! Appreciate a lot the help. It is working. You guys are brilliant! Glad to help! 1 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.