Jump to content

Getting the selection set that was just pasted


Recommended Posts

I m trying to get the selection set I just pasted with 'pasteclip' command from an other drawing but with no luck.

 

Is it possible? I though the 'vl-bb-set' & 'vl-bb-ref' would work but they do not seem to be working for sel. sets.

 

Any ideas appreciated. Thanks

Link to post
Share on other sites
mhupp
(setq SS (ssget "_L"))

 

from Lee Mac's website

Selects the last visible object added to the drawing database.

 

Caution: when using the "L" selection method in an MDI environment, you cannot always count on the last object drawn to remain visible. For example, if your application draws a line, and the user subsequently minimizes or cascades the AutoCAD drawing window, the line may no longer be visible. If this occurs, ssget with the "L" option will return nil.

Edited by mhupp
Link to post
Share on other sites

Thanks but that only works for one entity. I am talking about a selection set of entities.

Link to post
Share on other sites
mhupp
6 minutes ago, MJLM said:

Thanks but that only works for one entity. I am talking about a selection set of entities.

 

oops my bad. This is what I use when i explode stuff in a selection set and want to keep it in the same SS.

 

(setq LastEnt (entlast))
 *Paste items into drawing
(setq SS (ssadd))
(if (setq en (entnext LastEnt))
  (while en
    (ssadd en SS)
    (setq en (entnext en))
  )
)

 

 

Edited by mhupp
Link to post
Share on other sites
dan20047

I use reactors to save the last entity to a variable when a command such as paste or copy will start, then collect the new entities created when a command ends. I access those entities with a command that uses the variable for selection, example c:SEPP selects previous created, c:MPP moves previous created. (I use c:MP to move previous selection). 

 

(defun c:ML  () (command "MOVE" "L" "") (princ))
(defun c:MP  () (command "MOVE" "P" "") (princ))
(defun c:MPP  () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "MOVE" SAA_Previous "") (princ))	;; move previous from saved variable
(defun c:SEPP  () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "SELECT" SAA_Previous "")(sssetfirst SAA_Previous SAA_Previous) (princ))
(defun c:CP  () (command "COPY" "P" "") (princ))
(defun c:CPP  () (if (not SAA_Previous) (setq SAA_Previous "P"))(command "COPY" SAA_Previous "") (princ))	;; move previous from saved variable

 

I don't have time to extract just the reactor code for above as an example, but attached is my full reactor file. It won't run by itself as it depends on lots of subroutines from another file, but it contains the full structure of setting up reactors based on Eric Schneider's Autolay and vlr-manager. Search for SAA_Previous_Last for where it is called by the reactors.

 

This code does the same as mhupp above, except deals with last subentities. 

;;;==============================================================================
;;; Returns selection set of all entities after passed in entity name
;;; taken from CAD Cookbook utilities
;;;==============================================================================
(defun SAA_AFTER (ename / ss)
  (setq ss (ssadd))					;create selection set
  (if ename
    (while (setq ename (entnext ename))
       (ssadd ename ss)					;add entities to set
    )
;;;    (setq ss (ssget "X"))				;if no last entity, get all
  ) ;end if
  (if (> (sslength ss) 0) ss)			;return nil if no entities
)

;;;==============================================================================
;;; Returns last entity, even subentities on polylines
;;; used to ensure SAA_AFTER skips to the next full entity, not just a subentity
;;;
;;; by roy_043 from http://www.theswamp.org/index.php?topic=35626.msg408522#msg408522
;;;==============================================================================
(defun SAA_GetLast ( / ent newEnt)
  (setq ent (entlast))
  (while (and
           ent
           (setq newEnt (entnext ent))
         )
    (setq ent newEnt)
  )
  ent
)

 

saa_reactors.lsp

  • Like 1
Link to post
Share on other sites
tombu

Rather than using paste why not use Paste as Block Ctrl+Shift+V?

I'd use my Paste as Group macro:

^C^C_pasteblock;\(setq LstBlk(vla-get-Name (vlax-ename->vla-object (entlast))));_explode;_last;_-group;_create;*;;_previous;;(command "-purge" "B" LstBlk "N")
(setq LstBlk nil)

 

  • Agree 1
Link to post
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
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...