Trmsa Posted October 19, 2017 Share Posted October 19, 2017 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))) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 19, 2017 Share Posted October 19, 2017 Like this: (repeat (setq i (sslength ssx)) (or (entget (setq ent (ssname ssx (setq i (1- i))))) (ssdel ent ssx) ) ) Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 19, 2017 Share Posted October 19, 2017 @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). Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 19, 2017 Share Posted October 19, 2017 (edited) @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 October 20, 2017 by ronjonp Quote Link to comment Share on other sites More sharing options...
Trmsa Posted October 20, 2017 Author Share Posted October 20, 2017 Like this: (repeat (setq i (sslength ssx)) (or (entget (setq ent (ssname ssx (setq i (1- i))))) (ssdel ent ssx) ) ) Works great! Thanks! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 20, 2017 Share Posted October 20, 2017 @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! You are welcome. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 20, 2017 Share Posted October 20, 2017 @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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 20, 2017 Share Posted October 20, 2017 @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. Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 20, 2017 Share Posted October 20, 2017 If erasing an entity while iterating through the SS, doesn't this messes up the indexes of the enames that are inside of it? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 20, 2017 Share Posted October 20, 2017 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! Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 20, 2017 Share Posted October 20, 2017 @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 Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 20, 2017 Share Posted October 20, 2017 ... @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..."> Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 20, 2017 Share Posted October 20, 2017 Are you using MP's bench code? ;; Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 20, 2017 Share Posted October 20, 2017 OK .. so we're comparing apples and oranges LOL Quote Link to comment Share on other sites More sharing options...
Jef! Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.