- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, all.
I wrote a lisp (with the help of a few folks in this forum - thanks again) that selects entities of a user's choice. It works without any issues whatsoever (it does what it's supposed to). One little thing still remains, however. It's unrelated to the main task itself (selecting elements), but with the "princ" command at the end.
Here's the code:
(defun C:SelectTargetEntity (/ steSelection steString) ; Prep initget with all possibilities: (initget (strcat "Text MText MLeader Point")) ; Set *answerSTE* with user input: (setq *answerSTE* (cond ( (getkword ; offer user a list of options (strcat "\nChoose [Text/MText/MLeader/POint] <" (setq *answerSTE* ; define default or previous choice (cond (*answerSTE*) ("MLeader")) ) ">: " ) ) ) (*answerSTE*) ; option if user just presses enter ) ) ; Set steString entity type based on *answerSTE* variable: (cond ((eq *answerSTE* "Text") (setq steString "Text")) ((eq *answerSTE* "MText") (setq steString "MText")) ((eq *answerSTE* "MLeader") (setq steString "MultiLeader")) ((eq *answerSTE* "Point") (setq steString "Point")) ) ; Set filter based on requested entity type: (setq filter (list (cons 0 steString))) ; Prep filtered selection: (setq steSelection (ssget "_:L" filter)) ; Maintains selection: (sssetfirst nil steSelection) ; Print amount of items selected: (princ (strcat "\n" (itoa (sslength steSelection)) " " *answerSTE* " objects selected!")) ; gives an error when steSelection is empty... (princ) )
I suppose that not the entire lisp was needed, but put that in there just for context.
The problem is that the command line displays this error message when the selection is empty: "error: bad argument type: lselsetp nil"
Is there a way to fix this? Even though this routine would not likely be used if there were no elements to be selected, I'd still like to have a more robust code - and any possible fix might be used for other routines in the future.
Thanks in advance.
Edgar
Solved! Go to Solution.