TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Amsterdammed on April 04, 2007, 08:18:01 PM

Title: Getting ss from last copy command
Post by: Amsterdammed on April 04, 2007, 08:18:01 PM
Hello everybody,

I wonder if there is a way to get all new entities made by a copy command, like i do with a single entity:

Code: [Select]
(command "copy" en "" pt ptn)
(setq en1 (entlast))

How can I get ss1 when i copy ss?

Thanks in Advance

Bernd
Title: Re: Getting ss from last copy command
Post by: Crank on April 04, 2007, 09:02:55 PM
If you look for the last entity in the database before the copy command, you can find all new created entities with entnext.

Code: [Select]
(setq last1 (entlast))
(command "._copy" en "" pt ptn)
(setq ss1 (collect last1))

(defun collect (el / ex ss)
(setq ex (entnext el)
        ss (ssadd ex (ssadd)))
(setq ex (entnext ex))
(while ex
(setq ss (ssadd ex ss) ex (entnext ex))
)
ss
)
Title: Re: Getting ss from last copy command
Post by: CAB on April 04, 2007, 09:12:21 PM
http://www.theswamp.org/index.php?topic=1989.msg25600#msg25600
Title: Re: Getting ss from last copy command
Post by: Kerry on April 04, 2007, 09:13:47 PM
or traditionally ..
Code: [Select]
;; // MarkCatch.LSP
;; based on New Rider Articles { I think }

;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
;;;  KB:mark
;;;* Mark data base to allow KB:catch.
;;;*
(DEFUN kb:mark (/ val)
   (SETQ val (GETVAR "cmdecho"))
   (SETVAR "cmdecho" 0)
   (IF (SETQ *KG:mark (ENTLAST))
      nil
      (PROGN (ENTMAKE '((0 . "POINT") (10 0.0 0.0 0.0)))
             (SETQ *KG:mark (ENTLAST))
             (ENTDEL *KG:mark)
      )
   )
   (SETVAR "cmdecho" val)
   (PRINC)
)
;;;-----------------------------------------------------------------------------------
;;;-----------------------------------------------------------------------------------
;;;  KB:catch
;;;* returns selection set of entities since last KB:mark.
;;;*
(DEFUN kb:catch (/ ss tmp)
   (IF *KG:mark
      (PROGN (SETQ ss (SSADD))
             (WHILE (SETQ *KG:mark (ENTNEXT *KG:mark)) (SSADD *KG:mark ss))
             (COMMAND "._select" ss "")
             (SETQ tmp ss)
      )
      (ALERT "*KG:mark not set. \n Run KB:mark before KB:catch.")
   )
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------

Code: [Select]
(DEFUN C:testit ()

   (kb:mark)
   (PROMPT "\n  Select stuff to Copy ")
   (SETQ ss (SSGET))
   (INITGET 32)

   (COMMAND "_copy" ss "" "\\" "\\")
   (SETQ ss1 (kb:catch))

)
Title: Re: Getting ss from last copy command
Post by: Kerry on April 04, 2007, 09:15:36 PM

The method outlined above will allow the collection across multiple commands including exploding blocks etc ...
Title: Re: Getting ss from last copy command
Post by: Amsterdammed on April 05, 2007, 07:54:47 AM

The method outlined above will allow the collection across multiple commands including exploding blocks etc ...


Thanks Kerry,

that is great. That exploding block thing is indeed something Very usefull and more than I asked for :lol:


Thanks again, everybody

Bernd
Title: Re: Getting ss from last copy command
Post by: Amsterdammed on April 05, 2007, 07:59:49 AM
Crank,

thanks, your solution is doing the same, but you with the last entry at the moment of the copy instead of a benchmark. works great, too, with less code. :-)

Thanks

Bernd
Title: Re: Getting ss from last copy command
Post by: Patrick_35 on April 05, 2007, 12:01:19 PM
Hi,
You can use a reactor

Code: [Select]
;;;=================================================================
;;;
;;; JSD.LSP V2.00
;;;
;;; Jeu de Sélection de ce qui a été créé
;;;
;;; Copyright (C) Patrick_35
;;;
;;;=================================================================

(defun commencer_jeu__selection(Rea Cde)
  (if (member (car Cde) '("COPY" "MIRROR" "GRIP_MIRROR" "ARRAY"))
    (setq $ (ssadd))
  )
)

(defun ajouter_jeu_de_selection (Rea Obj)
  (if (not (eq (cdr (assoc 0 (entget (cadr Obj)))) "ATTRIB"))
    (ssadd (cadr Obj) $)
  )
)

(defun enlever_jeu_de_selection (Rea Obj)
  (ssdel (cadr Obj) $)
)

(defun faire_jeu_de_selection()
  (setq mrea_jsd (vlr-command-reactor nil (list (cons :vlr-commandWillStart (function commencer_jeu__selection))
  )
)
mrea_fin (vlr-acdb-reactor    nil (list (cons :vlr-objectAppended   (function ajouter_jeu_de_selection))
(cons :vlr-objectUnErased   (function ajouter_jeu_de_selection))
(cons :vlr-objectErased     (function enlever_jeu_de_selection))
  )
)
  )
  (princ "\nSelection of what is created ready, use !$ at the command line.")
  (princ)
)

(vl-load-com)
(if (not mrea_jsd)
  (faire_jeu_de_selection)
)
(princ)

But I have a problem.  :-(
When I do for example a copy of objects of which there are blocks with attributes, a (sslength $) gives me well what was copied.
I make a undo and it's always good.
Now, if I do a MREDO, I have the surprise to discover that the result of (sslength $) corresponds to the number of objects which had been copied more the number of attributes.  :-o
I seek in vain from where the error can come and I do not find  :?

@+
Title: Re: Getting ss from last copy command
Post by: Kerry on April 05, 2007, 09:37:20 PM
Why would anyone want to add a command reactor for something like this .. just MORE bottleneck potential ..

Title: Re: Getting ss from last copy command
Post by: Patrick_35 on April 06, 2007, 02:08:30 AM
Because you can use it at the command line. for example, If you want to select a past from an another drawing, it's more easy whith this.
You have an additional option of selection at the command line.

@+
Title: Re: Getting ss from last copy command
Post by: CAB on April 06, 2007, 06:53:46 AM
I like the idea but I'm with Kerry on the potential time penalty you may have to pay.
My system is feeling too slow as it is.
Still wishing for a new computer, ah maybe my Birthday.  :oops: