Jest Posted March 9, 2021 Posted March 9, 2021 I have some lisp commands that asked me for selection after starting them. I would like to modify them, so they can take into consideration selection I made before starting lisp. For example...down there is a lisp, to select all objects on single layer. I must select one object after starting command. It is more suitably for me, to select object before running lisp command. I have tried to modify icon macro command using previous (p) or last (l) but it dont work. How can I modify this lisp to satisfy my wishes? (defun c:layall ( / o ) (and (setq o (car (entsel "\nSelect object on layer :"))) (sssetfirst nil (ssget "_X" (list (assoc 8 (entget o)) (cons 410 (getvar 'CTAB))))) ) (princ) ) kind regards F. Quote
Jest Posted March 9, 2021 Author Posted March 9, 2021 It is already set to 1, but still not working. As I said, I have many lisp routines that requests selection after starting command. Sometimes inserting "p" or "l" in cui macro works, sometimes not. Quote
rkmcswain Posted March 9, 2021 Posted March 9, 2021 You could use (ssget "_I") - which will return a selection set of anything currently selected. But in the case of this routine, you only want a single object. Easy enough to do, just grab the only object in the selection set and work on it. But if multiple objects are selected when you invoke this command, it will only grab the first one and ignore the others. Something like this: (defun c:layall ( / sset o ) (and (setq sset (ssget "_I")) (setq o (ssname sset 0)) ;(and (setq o (car (entsel "\nSelect object on layer :"))) (sssetfirst nil (ssget "_X" (list (assoc 8 (entget o)) (cons 410 (getvar 'CTAB))))) ) (princ) ) But note this version does not ask you to pick if nothing was preselected. Quote
Jest Posted March 10, 2021 Author Posted March 10, 2021 Thank you, exactly what I needed for this lisp. I am not familiar with creating lisp commands...I have never made such a thing. I know how to load and use lisps and sometimes change defun command name. Can you give me simple advise how to put your command to other similar lisps... the rule where and how to insert (ssget "_I") into lisp text?... if it is so simple...? Quote
BIGAL Posted March 10, 2021 Posted March 10, 2021 Check out Lee-mac has a good explanation of ssget. ssget Function Reference | Lee Mac Programming (lee-mac.com) 2 Quote
rkmcswain Posted March 10, 2021 Posted March 10, 2021 9 hours ago, Jest said: Thank you, exactly what I needed for this lisp. Slightly different version where you can either preselect one or more objects, or not, in which case it will prompt you to select. (defun c:layall ( / sset o ) (if (not (setq sset (ssget "_I"))) (setq o (car (entsel "\nSelect object on layer :"))) (setq o (ssname sset 0)) ) (sssetfirst nil (ssget "_X" (list (assoc 8 (entget o)) (cons 410 (getvar 'CTAB))))) (princ) ) Quote
Jest Posted March 10, 2021 Author Posted March 10, 2021 1 hour ago, rkmcswain said: Slightly different version where you can either preselect one or more objects, or not, in which case it will prompt you to select. (defun c:layall ( / sset o ) (if (not (setq sset (ssget "_I"))) (setq o (car (entsel "\nSelect object on layer :"))) (setq o (ssname sset 0)) ) (sssetfirst nil (ssget "_X" (list (assoc 8 (entget o)) (cons 410 (getvar 'CTAB))))) (princ) ) Great, this is much more useful.. I discovered that this process s very applicable.. So, I played a bit with this version and extended process to send all selection to back.... and according to my knowledge, I completed macro command to ^C^C_layall;draworder:back I am wondering, how would you write this additional in this lisp instead? I hope I am not bothering you much regards! Quote
Jest Posted March 10, 2021 Author Posted March 10, 2021 So, we solved layall example, to select all objects in layer... I would like to go back at the root of my problem, to the beginning of this post. Actually I needed lisp section that I could put in any lisp routine, which asks me to select object, but I want that command takes into consideration selection, I made just before starting command. Is it possible to simply insert such a part of command into another Lisp? Quote
rkmcswain Posted March 10, 2021 Posted March 10, 2021 It depends, do you want any other restrictions on this? The routine you used as an example requires a single entity. If you are OK with allowing multiple object selections, then perhaps the (foo) function below? (defun c:test ( / arg ) (if (setq arg (foo)) (sssetfirst nil arg) ) (princ) ) (defun foo () (if (not (setq sset (ssget "_I"))) (progn (princ "\nSelect objects ") (setq sset (ssget)) ) ) ) Quote
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.