Simple fix (LISP noob) Syntax
Hi all, I'm a casual basic lisper. Where in the code is wrong. I'm getting the ss with ssget. I want some error trapping to tell the users that nothing is selected. LISP selects all text regardless of layer. But this error I can't fix. I've tried looking at some examples but I can't get any to work.This works when objects are selected:
(defun c:SEL_TEXT_ALL ()(setq ss nil) (setq ss (ssget '((0 . "MTEXT,TEXT")))) (if (> (sslength ss) 0) (progn (command "Pselect" ss "") (princ (strcat "\nNumber of found Text objects : < " (itoa (sslength ss)) " >")) (setq ss nil) (princ) ) (princ (strcat "\n***Nothing Selected***")) ))Error I get when nothing selected:
Select objects:; error: bad argument type: lselsetp nilEDIT: Is it good practice to clear the selection set before the progn is run? Maybe a simpler version :
(defun c:stext (/ ss) (if (setq ss (ssget '((0 . "TEXT,MTEXT")))) (princ (strcat "\n" (itoa (sslength ss)) " Text Entities Found")) (princ "\n*** Nothing Selected ***")) (prin1))
There is no real need to clear ss prior to the call.(ssget) returns either nil or a PICKSET
I don't quite understand the PSelect command?You have bound the variable ss to the PICKSET.
I declared ss local to this function, but you could just as easily make it part oflarger 1.
-David
That is because you are trying to get the number of the selection set variable while it is equal to nil , so to get sure that the selection set variable has a selection just add the function add with the variable , eg.
(if (and ss (> (sslength ss) 0))
Actually the way you did write the routine is not the recommended one and you did take the longest way to reach the destination , so have a look about the following modification of your codes .
(defun c:SEL_TEXT_ALL (/ ss) (if (setq ss (ssget '((0 . "MTEXT,TEXT")))) (princ (strcat "\nNumber of found Text objects : < " (itoa (sslength ss)) " >" )) (princ "\n***Nothing Selected***") ) (sssetfirst nil ss) (princ))
Just ask if you have any doubts Thanks guys for the quick responses. This forums great. Building up a LISP file with handy custom selection sets. Will post when I've completed it. Trying to incorporate a fn found here:http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570 for selection of blocks and not xrefs. Wrapping the if command like before doesn't work.
(defun c:SEL_BLOCKS (/ ss);; FN by lpseifert @ http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570 (if (setq ss (ssget (list (cons 0 "INSERT"))) idx -1) ( (repeat (sslength ss) (setq en (ssname ss (setq idx (1+ idx))) obj (vlax-ename->vla-object en) ) (if (vlax-property-available-p obj 'Path) (progn (ssdel en ss) (setq idx (1- idx)) ) ) ) (princ (strcat "\nNumber of found Blocks : < " (itoa (sslength ss)) " >")) ) (princ "\n***Nothing Selected***") ) (sssetfirst nil ss) (princ)) Don't forget your progn!
(defun c:SEL_BLOCKS (/ ss);; FN by lpseifert @ http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570 (if (setq ss (ssget (list (cons 0 "INSERT"))) idx -1) (progn (repeat (sslength ss) (setq en (ssname ss (setq idx (1+ idx))) obj (vlax-ename->vla-object en) ) (if (vlax-property-available-p obj 'Path) (progn (ssdel en ss) (setq idx (1- idx)) ) ) ) (princ (strcat "\nNumber of found Blocks : < " (itoa (sslength ss)) " >")) ) (princ "\n***Nothing Selected***") ) (sssetfirst nil ss) (princ)) No, but seriously, that was all that was missing. Thank you. When you're working and trying to learn LISP at the same time it's easy to miss out on the simplest thing.
EDIT, tried that but when nothings selected it's come with
; error: bad argument type: lselsetp nil
(defun c:SEL_BLOCKS (/ ss);; FN by lpseifert @ http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-filter-xrefs-out-from-ssget-list-cons-0-quot-insert-quot/m-p/2852572#M293570 (if (setq ss (ssget (list (cons 0 "INSERT"))) idx -1) ((progn (repeat (sslength ss) (setq en (ssname ss (setq idx (1+ idx))) obj (vlax-ename->vla-object en) ) (if (vlax-property-available-p obj 'Path) (progn (ssdel en ss) (setq idx (1- idx)) ) ) ) ) (princ (strcat "\nNumber of found Blocks : < " (itoa (sslength ss)) " >"))) (princ "\n***Nothing Selected***") ) (sssetfirst nil ss) (princ))Tried to wrap the progn up so that it was in the if and then (princ "\n***Nothing Selected***") outside that for the else with extra parentheses but didn't work. Hint: a setq expression will return the last value bound to the last symbol argument - in your case, the initial setq expression will return -1 Consider the following:
(defun c:sel_blocks ( / def lst sel ) ;; Iterate over the block table and compile a list of xref blocks to exclude (while (setq def (tblnext "block" (not def))) (if (= 4 (logand 4 (cdr (assoc 70 def)))) (setq lst (vl-list* "," (cdr (assoc 2 def)) lst)) ) ) ;; Attempt to retrieve a selection of blocks (but not xrefs) (if (setq sel (ssget (cons '(0 . "INSERT") (if lst (vl-list* '(-4 . ""))))))) (princ (strcat "\nNumber of blocks: " (itoa (sslength sel)))) (princ "\nNothing selected.") ) (princ))
页:
[1]
2