dilan Posted February 14, 2019 Share Posted February 14, 2019 Hello to all. In the program through the function I choose the polyline: (defun Select1obj (objName msg) (while (not (and (setq ent (car (entsel msg))) (if ent (wcmatch (cdr (assoc 0 (entget ent))) objName) ) ) ) (princ "\nSelect Again: ") ) ent ) Like this: (setq pick (Select1obj "LWPOLYLINE" "\nSelect polyline number 1 ->>")) But in the program I have to choose another polyline (or there may not be one). Now it looks like this: (setq ssEle (ssget (list (cons 0 "LWPOLYLINE")))) Please tell me how to do the following: I select the first polyline through the function "Select1obj", then if i don't select another polyline through function "ssget", then the variable "ssEle" is assigned the polyline I selected through the function "Select1obj" (programmatically, without re-selection in the drawing). Thanks to everyone who will help me! Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 14, 2019 Share Posted February 14, 2019 When using ssget you make a selection set with at least 1 item, you use (sslength ss) to find out how many items, (ssname ss x) where x is the item number to be retrieved. Normally used with a repeat. You can also do a SSADD which adds items so you could keep doing entsel and add more items to a selection set. 1 Quote Link to comment Share on other sites More sharing options...
dilan Posted February 14, 2019 Author Share Posted February 14, 2019 (edited) 1 hour ago, BIGAL said: When using ssget you make a selection set with at least 1 item, you use (sslength ss) to find out how many items, (ssname ss x) where x is the item number to be retrieved. Normally used with a repeat. You can also do a SSADD which adds items so you could keep doing entsel and add more items to a selection set. Thank you very much, this is what I need! I did it like this: (setq pick (Select1obj "LWPOLYLINE" "\nSelect polyline number 1 ->>")) (setq ssEle (ssget (list (cons 0 "LWPOLYLINE")))) (if (not ssEle) (setq ssEle (ssadd pick)) ) Edited February 14, 2019 by dilan Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 14, 2019 Share Posted February 14, 2019 (edited) Since the and function uses short-circuit evaluation, your select1obj function may be reduced to: (defun select1obj ( typ msg / ent ) (while (and (setq ent (car (entsel msg))) (not (wcmatch (cdr (assoc 0 (entget ent))) typ)) ) (princ "\nInvalid object selected, please try again.") ) ent ) This also allows the user to dismiss the prompt in order to exit the function (with the function returning nil), without having to force an error by pressing Esc. You might also want to consider the following for a filtered single selection: (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))) Edited February 14, 2019 by Lee Mac 1 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.