Jump to content

removing deleted object from existing selection set


Trmsa

Recommended Posts

i have selection set and some of object inside of it are deleted. How to remove them from ss?

I tried to do it myself but my code dont work.

My code:

 

(setq n 0)
(setq ssx ss)
(setq x (sslength ssx))
(repeat x
   (if (entget(ssname ssx n))
			(princ n)
			(progn
			(setq en (ssname ssx n))
			(ssdel en ss)
			)
)
(setq n (1+ n)))

Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • Roy_043

    7

  • ronjonp

    5

  • Grrr

    5

  • Tharwat

    4

@Tharwat:

Using vlax-erased-p to check if an entity is erased is faster. The function also accepts enames.

 

BTW:

Passing a selection set with erased entities to a command does not cause any problems (in BricsCAD at least).

Link to comment
Share on other sites

@Tharwat:

Using vlax-erased-p to check if an entity is erased is faster. The function also accepts enames.

...

Not fast enough to introduce a vlax function IMO.

~5000 selset all erased

_$

 

nil

_ENTGET

_VLAX-ERASED-P Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

 

(_VLAX-ERASED-P).....1250 / 1.01

(_ENTGET)............1266 / 1.00

 

 

; 5 forms loaded from # loading...">

_$

Entget benches faster on a selset with ~22000 items:

_$

 

nil

_ENTGET

_VLAX-ERASED-P Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

 

(_ENTGET)............1047 / 1.03

(_VLAX-ERASED-P).....1079 / 1.00

 

 

; 6 forms loaded from # loading...">

_$

Edited by ronjonp
Link to comment
Share on other sites

@Tharwat:

Using vlax-erased-p to check if an entity is erased is faster. The function also accepts enames.

I think DXF is faster than converting objects to vla-objects although the vlax-erased-p function throws the following error than a nil on my end which seems odd.

; error: unable to get ObjectID: nil

 

Works great! Thanks! :D

 

You are welcome.

Link to comment
Share on other sites

@ronjonp:

You have tested a unique case. Try again with a selection set where 10% of the entities have been erased. You will find that building an entity list for a non-erased entity is relatively slow.

 

@Tharwat:

As mentioned: vlax-erased-p also accepts enames. So there is no need to convert to a vla-object.

Link to comment
Share on other sites

@Tharwat:

As mentioned: vlax-erased-p also accepts enames. So there is no need to convert to a vla-object.

 

Thanks Roy, honestly I did not know that vlax-erased-p function works with entity name so I have just tried it out and it works as well.

Link to comment
Share on other sites

If erasing an entity while iterating through the SS, doesn't this messes up the indexes of the enames that are inside of it?

 

That's if you are iterating one selection set right after selecting them but if the user has two or more selection sets then maybe a deletion involved in one of the SS that forced the user to deduct the erased objects from a specific SS. Just a guess.

Link to comment
Share on other sites

That's if you are iterating one selection set right after selecting them but if the user has two or more selection sets then maybe a deletion involved in one of the SS that forced the user to deduct the erased objects from a specific SS. Just a guess.

 

Just in case I'd initially construct a lists from those selection sets and process the entities from there. (might be uneffective approach but guarantees that is faultless).

Thanks Tharwat!

Link to comment
Share on other sites

@ronjonp:

You have tested a unique case. Try again with a selection set where 10% of the entities have been erased. You will find that building an entity list for a non-erased entity is relatively slow.

 

@Tharwat:

As mentioned: vlax-erased-p also accepts enames. So there is no need to convert to a vla-object.

 

You are correct ... 22000 items 15 deleted.

_$

 

_ENTGET

_VLAX-ERASED-P Benchmarking ....Elapsed milliseconds / relative speed for 2 iteration(s):

 

(_VLAX-ERASED-P).....2484 / 1.09

(_ENTGET)............2703 / 1.00

 

 

; 3 forms loaded from # loading...">

_$

I'd still stay vanilla though 8)

Link to comment
Share on other sites

If erasing an entity while iterating through the SS, doesn't this messes up the indexes of the enames that are inside of it?
The key here is that Tharwat's code starts with the *last* entity in the set. That is why it succeeds as opposed to the OP's code.

 

@ronjonp: I am surprised by your findings. Will test the same on BricsCAD.

Link to comment
Share on other sites

...

 

@ronjonp: I am surprised by your findings. Will test the same on BricsCAD.

That would be interesting to see. Did a couple more tests and _VLAX-ERASED-P is way faster on smaller selection sets for some reason?

 

And slows down considerably with large selection sets...

 

69

69

4

0

_ENTGET

_VLAX-ERASED-P Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):

 

(_VLAX-ERASED-P).....1703 / 2.61

(_ENTGET)............4453 / 1.00

 

 

; 9 forms loaded from # loading...">

 

And slows down considerably with large selection sets:

21438

21438

1339

0

_ENTGET

_VLAX-ERASED-P Benchmarking ....Elapsed milliseconds / relative speed for 2 iteration(s):

 

(_VLAX-ERASED-P).....2484 / 1.10

(_ENTGET)............2735 / 1.00

 

 

; 9 forms loaded from # loading...">

Link to comment
Share on other sites

In BricsCAD there definitely is a difference:

(setq lst (KGA_Conv_Pickset_To_EnameList (ssget "_A")))
(princ (length lst)) ; => 22000

(KGX_BenchMark '((mapcar 'entget lst) (mapcar 'vlax-erased-p lst)) 5)

; Benchmarking .......... elapsed milliseconds / relative timing <5 iterations>

;   (MAPCAR 'VLAX-ERASED-P LST) ...... 360 / 3.95 <fastest>
;   (MAPCAR 'ENTGET LST) ............ 1422 / 1.00 <slowest>

Note 1: I have used a list of enames where none of the entities has been erased.

Note 2: My test has 5 iterations instead of 2.

Link to comment
Share on other sites

Are you using MP's bench code?
No. The core of my code (see below) is based on a function by the late Axel Strube-Zettler. But I have obviously had a close look at the output of several benchmark utilities including Michael Puckett's.

;;; ======================================================================
;;; Function:     KGX_Elapsed (20120306)
;;; Purpose:      Check the time consumption of an expression.
;;; Arguments:    expr   - expression
;;;               nTimes - number of times the expression is executed
;;; Return value: Time in milliseconds.
;;; Remarks:      Based on code by: Axel Strube-Zettler (http://www.autolisp.mapcar.net/).
;;; ======================================================================
(defun KGX_Elapsed (expr nTimes / start)
 (setq start (getvar "tdusrtimer"))
 (setq expr
   (eval
     (list
       'lambda
       '(/ expr nTimes start)
       expr
     )
   )
 )
 (repeat nTimes (expr))
 (* (- (getvar "tdusrtimer") start) 8.64e7)
)

 

Note: http://www.mapcar.net/ is currently a 'parked' domain.

Link to comment
Share on other sites

If erasing an entity while iterating through the SS, doesn't this messes up the indexes of the enames that are inside of it?

 

It can if you are not careful. Proceeding through the selset going forward, you cannot simply increment the index number. In the repeat function, if you either increase the index number OR delete the entity from the selection set, it will work just fine, but will be less hassle to just proceed backward through the selset (like tharwat did).

 

If the entities that are erased are erased via lisp (theoretically it is (unless the selset is global?)), another approach would be to ssdel the entity from the selset as the entity is erased, skipping altogether the need to process once more through the selset.

Link to comment
Share on other sites

OK .. so we're comparing apples and oranges LOL

You are right. Testing with MP's code is quite an eye-opener. Food for thought...

 

(setq lst (KGA_Conv_Pickset_To_EnameList (ssget "_A")))
(princ (length lst)) => 22000 ; Note: no erased items.

(BenchMark_MP2005 '((mapcar 'entget lst) (mapcar 'vlax-erased-p lst)))

Elapsed milliseconds / relative speed for 10 iteration(s):

   (MAPCAR 'VLAX-ERASED-P LST).......31 / 124.48 <fastest>
   (MAPCAR 'ENTGET LST)............3859 / 1.00 <slowest>

Note:

MP's code compares both the min. and max. elapsed time against the same boundary. Which in itself is strange. But in the above case, where the min. time is much smaller than the max. time, this leads to an undesirably long waiting time. So I have changed that portion of the code to use a fixed number of iterations.

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