Create a selection set from result of previous lisp command?

Create a selection set from result of previous lisp command?

PDACTL
Enthusiast Enthusiast
410 Views
5 Replies
Message 1 of 6

Create a selection set from result of previous lisp command?

PDACTL
Enthusiast
Enthusiast

If I create a selection set and then copy it, something like so:

(setq EN (ssget))
(command "_.COPY" EN "" pt1 pt2)

Is there a way to make a selection set of the NEW entities for use with subsequent operations?

0 Likes
Accepted solutions (1)
411 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Save the entlast prior to copy.

 

(defun c:Copynew ( / s e n)

  (if (and (setq s (ssget "_:L"))
	   (setq e (entlast))
	   (setq n (ssadd))
	   )
    (progn
      (command "_.copy" s "" pause pause)
      (while (setq e (entnext e))
	(ssadd e n))
      (sssetfirst nil n)))
  (princ)
  )

 

Or simple and dirty, don't like it. Copy them in place, then move.

(defun c:Copydirty ( / s)

  (if (setq s (ssget "_:L"))
    (progn
      (command "_.copy" s "" "_non" '(0 0) "_non" '(0 0))
      (command "_.move" s "" pause pause)
      (sssetfirst nil s)))
  (princ)
  )

 

Or..... use (vla-move) method.

0 Likes
Message 3 of 6

PDACTL
Enthusiast
Enthusiast

Copydirty works OK for me but I'm not sure I understand why!

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@PDACTL wrote:

Copydirty works OK for me but I'm not sure I understand why!


It Copies the original selection in place, and then Moves the original selection, not the copies.  That means it can just use the Previous selection to do it, so there isn't the complication of stepping along with (entnext) to find things.  But it also means that what you think of as the copies in the new location are not actually the copies -- those are back at the original location.  So if it matters to you that the things in the new location actually be newer objects than those in the original location, you shouldn't use that approach.  For the kinds of things I do, that is usually not a concern, so I do use that approach when appropriate.

Kent Cooper, AIA
0 Likes
Message 5 of 6

TomBeauford
Advisor
Advisor

If it's something you need on a regular basis take a look at this old irneb routine I used to use years ago: http://forums.augi.com/showthread.php?81175-select-result-lisp-modification#5

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 6 of 6

PDACTL
Enthusiast
Enthusiast

@Kent1Cooper wrote:

@PDACTL wrote:

Copydirty works OK for me but I'm not sure I understand why!


But it also means that what you think of as the copies in the new location are not actually the copies -- those are back at the original location.  


This is what got me!

Luckily it doesn't matter to me so this technique will work.

0 Likes