Jump to content

Optimizing Workflow with Loop Controls and Data Management


Recommended Posts

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

Posted (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 by maahee
Posted

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. 

Posted (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 by Steven P
  • Agree 1
  • Thanks 1
Posted

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. 

  • Thanks 1
Posted (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 by mhupp
  • Thanks 1
Posted

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.

Posted (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 by maahee
Posted (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 dragged selection negating having to check if its already selected.

 

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 increased, it was added
        (princ "\nAdded to selection set")
        (princ "\nAlready in selection set")
      )
    )
    (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 by mhupp

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