maahee Posted Wednesday at 10:35 AM Posted Wednesday at 10:35 AM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CASE 1 (setq ss (ssadd)) (if (not (ssmemb n ss)) (ssadd n ss) ;code );if ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CASE 2 (setq flag T) (while flag (setq obj (ssget "_:S")) (cond (obj ;CODE ) ;ar (t (princ "\nNo selection made.") (initget "X") (setq bm (strcase (getstring "\nEnter 'X' to exit or press Enter to continue [X]: " ) ) ) (if (= bm "X" ) (setq flag nil) ; Exit the loop if user types 'x' (princ "\nInvalid input. Please try again.") ) ;if ) ) );WHILE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CASE 1: If the dataset is large, it will slow down the process. alternatives or tricks. CASE 2: Press the Enter key once to continue the loop, and press it twice to exit. or Only the letter "x" and empty inputs are acceptable. Quote
mhupp Posted Wednesday at 11:51 AM Posted Wednesday at 11:51 AM I'm not quite sure what your asking to optimize. Quote
maahee Posted Wednesday at 11:58 AM Author Posted Wednesday at 11:58 AM (edited) @mhupp Case 1: I want to reduce the time. I use the "not (ssmemb n ss)" function, but it takes a long time when the selection set is large. case 2: Press the Enter key once to continue the loop, and press it twice to exit. ( empty selection set handle) The above two cases do not relate to each other. Please Edited Wednesday at 12:05 PM by maahee Quote
mhupp Posted Wednesday at 01:08 PM Posted Wednesday at 01:08 PM I understand what your asking for in case1 case2. I am asking is why your using them. might be a better optimization in how your selecting things. just asking for a higher level of what your trying to do. Quote
Steven P Posted Wednesday at 03:01 PM Posted Wednesday at 03:01 PM (edited) Case 1: ssadd does a check if the entity exists in the set, you can change CASE 1 (setq ss (ssadd)) (if (not (ssmemb n ss)) (ssadd n ss) ;code );if to CASE 1 (ssadd n ss) ;code Often in code optimisation is rarely a single line that makes a difference... unless you are doing thousands of calculations, so here taking out an if statement won't do a lot. Most likely you have a loop within a loop that slows things - might be more efficient to look back at how you are selecting the entities and processing them before adding to the selection set. However don't just accept that, if you code will work without the line take out your if statement, and ssadd and you shouldn't really notice a big difference in speed Edited Wednesday at 03:22 PM by Steven P 1 1 Quote
Steven P Posted Wednesday at 03:18 PM Posted Wednesday at 03:18 PM Case 2: This nicest user friendly way I found.. is not the nicest user friendly way in programming - involves grread which the help suggests is rarely needed and for advanced users.... grread if the input is keyboard or mouse input. If keyboard check if it is enter, X, space or escape (enter, space, escape got to use character codes) else ignore text inputs. If mouse input check if they have selected an object or just clicking empty space However the help suggests doing this in other ways. For both cases, and MHUPPs question what is the goal you are wanting to achieve. 1 Quote
mhupp Posted Wednesday at 04:58 PM Posted Wednesday at 04:58 PM (edited) 3 hours ago, Steven P said: Case 2: However the help suggests doing this in other ways. Have a progress output to the bottom left for long process is always a good idea because people will cancel commands that they think are hung. https://www.cadtutor.net/forum/topic/75702-all-objects-inside-this-selection-want-to-send-layer-0/#findComment-598604 in the update loop if user hits esc exit lisp Edited Wednesday at 07:16 PM by mhupp 1 Quote
BIGAL Posted Wednesday at 10:57 PM Posted Wednesday at 10:57 PM Like others I really don't understand what your trying to do. You talk about large data sets but what are they and what exactly are you trying to do ? I use a group lists function to look at groups of common item where say 1st item in a sub list is the same, speeds up searches. Quote
maahee Posted yesterday at 08:01 AM Author Posted yesterday at 08:01 AM (edited) (defun C:123 () (setq ss (ssadd)) (setq i 0) (while (setq m (ssget)) ; selected group of line one by one or in group large scale (repeat (sslength m) (setq n (ssname m i)) (if (not (ssmemb n ss)) (progn (ssadd n ss) ;;;;;code ) ;progn (progn (princ) (print "/nduplicate selected line:") ) ;progn ) ;if (setq i (1+ i)) ) ;Repeat (setq i 0) ) ;while loop ) ;defun ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;case 2 ;;;;;Press the Enter key once to continue the loop, and press it twice to exit. (defun C:bm () (setq flag T) (while flag (setq obj (ssget "_:S")) (cond (obj ;CODE ) ;ar (t (princ "\nNo selection made.") (initget "X") (setq bm (strcase (getstring "\nEnter 'X' to exit or press Enter to continue [X]: "))) (if (= bm "X") (setq flag nil) ; Exit the loop if user types 'x' (princ "\nInvalid input. Please try again.") ) ;if ); seo cond ) );WHILE ) @BIGAL Test Lisp for reference. The selection set gradually increases, which takes a long time when it is large. Edited yesterday at 08:20 AM by maahee Quote
mhupp Posted 16 hours ago Posted 16 hours ago (edited) You can limit what ssget selects by entity, layer, color, size, basically anything in dxf codes. please read up on ssget This means you could just make a window selection. And not have to zoom in and out to make selections. also @Steven P already said "ssadd does a check if the entity exists in the set" check the length of SS before and after to see if it was already in the list. also also looks like your not using localized variables could be why its taking so long. (defun C:123 ( / ss pick l) (setq ss (ssadd)) (princ "\nSelect Entity: ") (while (setq pick (ssget)) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex pick))) (setq l (sslength ss)) ; Length before adding (setq ss (ssadd ent ss)) ; Try adding entity (if (= l (sslength ss)) ; If length is the same, item was already in list (princ "\n\nDuplicate Selected Line") ) ) (princ (strcat "\n" (itoa (sslength ss)) " Entities now in Selection SS")) ) ; rest of code goes here (princ) ) (defun C:bm ( / ss ent) (while (setq SS (ssget (ssget "_+.:E:S"))) ;exits if selection isn't made (setq ent (ssname ss 0)) ;CODE ) ) Edited 11 hours ago by mhupp 1 1 Quote
Steven P Posted 1 hour ago Posted 1 hour ago Reading about selection sets yesterday, if you are deleting from a selection set within your code, be aware that the entire set is indexed again which can add in delays (set contains entities 1 2 3 4 5 6 78 9, delete entity 5 from the set, then 6 7 8 and 9 are all indexed again to be 5 6 7 8 - time which can add up with very large selection sets). For case 1 I would be considering what you are doing in ';;;;code' to see if there are efficiencies in there (try running it as you write above to get a benchmark for the speed over your large selection set without any other codes) Quote
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.