Author Topic: Track recently created objects and put them into a selection set  (Read 2697 times)

0 Members and 1 Guest are viewing this topic.

Red Nova

  • Newt
  • Posts: 69
Hi.
I am looking for a way to track all recently created objects and put them into a selection set. I know how to do it one by one. But I would like to have a way to track new objects automatically. (I am lazy  :shifty:).
Say I have a lisp and at the start of it I put a "Start New Objects Tracking Mark" and somewhere near the end I put an "End New Objects Tracking Mark". The idea is to be able to track all items created between these 2 marks and have them in a selection set. (Preferably objects that have been deleted during lisp should be also removed from final selection set).
Not sure if this is even doable with lisp but would be grateful for comments :-).
« Last Edit: June 17, 2019, 08:48:51 AM by Red Nova »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Track recently created objects and put them into a selection set
« Reply #1 on: June 17, 2019, 08:50:59 AM »
One way woukd be to establish a bookmark based on an object’s handle. Easy to then iterate thru objects created after it via entnext, putting them in a selection set, although you may have problems proccesing the selection set (depending if you process them 1 by 1 or via a command) if the objects don’t reside in the same layout. On my phone and in transit so no code sample.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Track recently created objects and put them into a selection set
« Reply #2 on: June 17, 2019, 08:59:05 AM »
You could be able to do it very easy in following way :

(defun c:xxx ( / e entlst group ) ;;; start lisp - note that after routine is finished variable "ss" is global - sel.set with newly created entities - that's why is not localized and put among ( / e entlst group )

- start tracking
(setq e (entlast))

- create new entity - appending database
(entmake '((0 . "LINE") (10 0.0 0.0 0.0) (11 1.0 1.0 1.0)))

- collecting new objects and putting them in tracking entity list
(if (not (eq e (setq e (entlast))))
  (setq entlst (cons e entlst))
)

- end tracking
(setq group entlst)
(setq entlst nil)

- end of lisp and selecting grouped entities
(setq ss (ssadd))
(foreach e group
  (ssadd e ss)
)
(sssetfirst nil ss)
(prompt "\nObjects highlighted and stored in sel.set \"ss\"...")
(princ);silent_finish_of_(c:xxx)

); end_defun_(c:xxx)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Red Nova

  • Newt
  • Posts: 69
Re: Track recently created objects and put them into a selection set
« Reply #3 on: June 17, 2019, 09:28:34 AM »
MP, Thank you. Unfortunately I don't understand what this means, never used "object’s handle" and no clue what means "establish a bookmark". Maybe later you could drop a sample when you have a chance.

ribarm. Thank you, in this case I have to every time put the new object in the tracking entity list once it is created? I am trying to avoid this. The problem is I have many lisp codes and on the way I am creating multiple items. Now I need to modify all of these codes. And I need to receive a selection set of all objects created while code was running. I would prefer not check each code one by one to see where an item is created and add it to an entity list. If I could put only "Start Tracking" and "End Tracking" and receive a selection set in the end this would make the modification so much easier.

kpblc

  • Bull Frog
  • Posts: 396
Re: Track recently created objects and put them into a selection set
« Reply #4 on: June 17, 2019, 09:46:07 AM »
I think the better way is to modify your routines and make them return lisp of created objects. And at your 'main' lisp you can collect them and modify (or erase ;))
Sorry for my English.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Track recently created objects and put them into a selection set
« Reply #5 on: June 17, 2019, 10:23:02 AM »
I've only time for a a quick and dirty sample function to illustrate the gathering of entities in a selection set after a specfied entity handle:

Code: [Select]
(defun _Entities-After-Handle ( handle / ss ename data )
    ;;  Return the primary entities after the entity corresponding to arg handle.
    (if (eq 'ename (type (setq ss (ssadd) ename (vl-catch-all-apply 'handent (list handle)))))
        (while ename
            (and
                (setq data (entget ename))
                (null (member (cdr (assoc 0 data)) '("VERTEX" "ATTRIB" "SEQEND")))
                (setq ss (ssadd ename ss))
            )
            (setq ename (entnext ename))
        )
    )   
    (if (< 0 (sslength ss)) ss)
)

If you don't know what handles are you may be trying to run before having learned to walk. This may help you in your journey. Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Track recently created objects and put them into a selection set
« Reply #6 on: June 17, 2019, 10:26:12 AM »
a a

Didn't mean to sound like our pathetic crime minister.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

tombu

  • Bull Frog
  • Posts: 288
  • ByLayer=>Not0
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

Red Nova

  • Newt
  • Posts: 69
Re: Track recently created objects and put them into a selection set
« Reply #9 on: June 17, 2019, 03:50:32 PM »
Thank you all.

I ended up editing all 31 of my lisps, finding all new entities and adding them to selection sets individually.
Turned to be the easiest way of solving my problem noting my humble lisp knowledge.

Cheers.

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Track recently created objects and put them into a selection set
« Reply #10 on: June 22, 2019, 10:00:10 AM »
Use following code :-
Code: [Select]
(defun c:StartNewObjectsTracking ()
  ;;Start New Objects Tracking Mark
  (setq ssuniversal1 (ssget "_X"))
  (princ "\nNew Objects Tracking Started.")
  (princ)
)
(defun c:EndNewObjectsTracking ()
  ;;End New Objects Tracking Mark
  (setq ssuniversal2 (ssget "_X"))
  (setq ssnew (kdub:sssubtract ssuniversal2 ssuniversal1))
  (sssetfirst nil ssnew)
  (setq ssuniversal1 nil
        ssuniversal2 nil
  )
  (princ (strcat "\nNew Objects Tracking Ended. " (itoa (sslength ssnew)) " New Objects Created."))
  (princ)
)
(defun kdub:sssubtract (ss1 ss2 / ss)
  ;; Subtracts one selection set from another and returns their difference
  (cond ((and ss1 ss2) (vl-cmdf "._Select" ss1 "_Remove" ss2 "") (setq ss (ssget "_P")))
        (ss1 (setq ss ss1))
        (t (setq ss nil))
  )
  ss
)