pmxcad Posted June 20, 2018 Share Posted June 20, 2018 Hello, I found a lisp on Lee`s website to search for and select text. A nice short routine and works perfectly. Now my question is: can an alert be given "not found" if the text is not found in the drawing and how?. (defun c:findtext ( / str ) (if (/= "" (setq str (getstring t "\nSpecify string to find: "))) (sssetfirst nil (ssget "_X" (list '(0 . "TEXT") (cons 1 str) ) ) ) ) (princ) ) something like, (alert str " not found") thank you in advance PmxCAD Quote Link to comment Share on other sites More sharing options...
1958 Posted June 20, 2018 Share Posted June 20, 2018 (defun c:findtext (/ str sstxt) (setq str (getstring t "\nSpecify string to find: ") sstxt (ssget "_X" (list '(0 . "TEXT") (cons 1 str))) ) (if (/= sstxt nil) (sssetfirst nil sstxt) (alert (strcat str " not found")) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 20, 2018 Share Posted June 20, 2018 Here's another: (defun c:findtext (/ s str) (cond ((= "" (setq str (getstring t "\nSpecify string to find: "))) (print "Later yo...")) ((null (setq s (ssget "_X" (list '(0 . "TEXT") (cons 1 str))))) (alert (strcat "'" str "' not found!")) ) (t (alert (strcat (itoa (sslength s)) " '" str "' item" (cond ((= 1 (sslength s)) "") ("s") ) " found!" ) ) (sssetfirst nil s) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
pmxcad Posted June 20, 2018 Author Share Posted June 20, 2018 Thanks 1958 & ronjonp, i think i wil go for the 1958 one. i`ve not tried yet, no Autocad at the moment. But is it also possible to at (progn to the alert part to close refedit (command "refclose" "s") after the alert. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 21, 2018 Share Posted June 21, 2018 An IF has two parts a true and a false, simplest is one line for T, 2 lines T or F, by adding (progn you can have multiple lines of code ) ; end progn ); end if If you want to get real carried away you can make a IF and use a defun that has 100 lines of code. Quote Link to comment Share on other sites More sharing options...
pmxcad Posted June 21, 2018 Author Share Posted June 21, 2018 BIGAL, I got it together and it works too. (defun c:findtext (/ str sstxt) (setq str (getstring t "\nSpecify string to find: ") sstxt (ssget "_X" (list '(0 . "TEXT") (cons 1 str))) );setq (if (/= sstxt nil) (sssetfirst nil sstxt) (progn (alert (strcat str " not found")) (command "refclose" "D" "") );progn );if (princ) );defun Thanks Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 21, 2018 Share Posted June 21, 2018 FWIW.. This: (if (/= sstxt nil) can just be this (if sstxt and reverse the return Quote Link to comment Share on other sites More sharing options...
pmxcad Posted June 21, 2018 Author Share Posted June 21, 2018 i will give it a try Quote Link to comment Share on other sites More sharing options...
1958 Posted June 21, 2018 Share Posted June 21, 2018 !!! Quite right! Quote Link to comment Share on other sites More sharing options...
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.