Jump to content

alert given if the text is not found


pmxcad

Recommended Posts

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

Link to comment
Share on other sites

(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)
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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