Jump to content

Use "currently selected" command into Lisp routine


Jest

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

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