Thanks AL; Ended up using the "ERRNO" var; This is how it ended up...
Code:
;Rob Benz
;
; - Solar panel string increment number function
;
;02.15.2018
; - Added feature: hitting [SPACEBAR] will draw strings/wires in the same
; order that each panel was selected & labeled
;
;02.16.2018
;
; - Added "MakeCircles", "LabelCircles", and "TrimCircle" functions
;===============================================================================
; This function lets user click on each panel and then
; labels the panels correctly: Inverter#,String#,Panel#
;------------------------------------------------------
(defun C:INCS (/ Inum Snum Pnum entlst entmat entnew entlst entlst2 entlst3 lst y dist)
(vl-load-com) ; loads extended functions/utilities/etc. if not already loaded
(setq *ptList* nil) ; RESET all global vars used
(setq *fPanel* nil)
(setq *lPanel* nil)
(setq *tmp1* nil)
(setq *tmp2* nil)
(defun DrawLines (lt /) ; draw lines\strings between each panels
(prompt "\nDrawing Lines...")
(setq lt(reverse lt))
(setvar "clayer" "E-NEW-POWER-EQUIP")
(command "._LINE")
(apply 'command lt)
(command "")
(setvar "clayer" "M-GEN-NOTES")
(prompt "\nLines Drawn.")
(setq lt nil)
) ; END of defun DrawLines
(setvar "clayer" "M-GEN-NOTES") ;set layer to default PSI "M-GEN-NOTES" (color = yellow)
(setq Inum (getint "Enter Inverter Starting Number:")) ;get starting Inverter #
(if (>= Inum 1) (setq Inum Inum) (setq Inum 1)) ; these are incase user input 0 or negative int
(setq Imax (getint "Enter Max Number of Inverters:")) ;get MAX # Inverters
(if (>= Imax 1) (setq Imax Imax) (setq Imax 1))
(setq Snum (getint "Enter String Starting Number:")) ;get starting String #
(if (>= Snum 1) (setq Snum Snum) (setq Snum 1))
(setq Smax (getint "Enter Max Number of Strings on Inverter:")) ;get MAX # Strings
(if (>= Smax 1) (setq Smax Smax) (setq Smax 1))
(setq Pnum (getint "Enter Panel Starting Number:")) ;get starting Panel #
(if (>= Pnum 1) (setq Pnum Pnum) (setq Pnum 1))
(setq Pmax (getint "Enter Max Number of Panels on String:")) ;get MAX # Panels
(if (>= Pmax 1) (setq Pmax Pmax) (setq Pmax 1))
(setvar "ERRNO" 0) ; set system var to zero
(setvar "clayer" "M-GEN-NOTES") ;make sure that we start with the correct PSI "layer"
(while (<= Pnum Pmax) ;while panel # is <= to MAX panels, loop
(setq entlst (nentsel "\nSelect Line/Polyline in Block :")) ;select the panel/"block" to label
(setq errNo (getvar "ERRNO"))
(cond ((= errNo 0) ; no ERROR
(setq lst (apply 'append
(mapcar '(lambda (x)
(if (or (= 10 (car x)) (= 11 (car x)))
(list
(append
(list
(+ (* (car (nth 0 (setq entmat (caddr entlst)))) (cadr x))(* (car (nth 1 entmat)) (caddr x))(car (nth 3 entmat))))
(list
(+ (* (cadr (nth 0 entmat)) (cadr x)) (* (cadr (nth 1 entmat)) (caddr x)) (cadr (nth 3 entmat))))))))
(if (= "POLYLINE" (cdr (assoc 0 (entget (setq entlst2 (cdr (assoc 330 (entget (car entlst)))))))))
(progn (setq entnew entlst2)
(while (/= "SEQEND" (cdr (assoc 0 (entget entnew))))
(setq entnew (entnext entnew))
(setq entlst3 (cons (reverse (cdr (reverse (assoc 10 (entget entnew))))) entlst3))))(entget (car entlst)))
))) ;end setq
(setq Istring (strcat "I"(itoa Inum))) ;concants the letter I and the number
(setq Sstring (strcat "S"(itoa Snum))) ;concants the letter S and the number
(setq Pstring (strcat "P"(itoa Pnum))) ;concants the letter P and the number
(command "._mtext" (setq y (mapcar '/ (mapcar '+ (car lst) (caddr lst)) '(2 2)))
"_j" "_mc" "_r" 359.9 y Istring Sstring Pstring "") ;(* 180 (/ (car (vl-sort (mapcar 'angle lst (cdr lst)) '<)) pi))
(setq *ptList*(cons y *ptList*)) ; add to ptList (for drawing the lines)
(setq Pnum (+ Pnum 1))
;if panel# is < max, and the str# is < max, then inc str by 1 & set panel#=1
(if (and (> Pnum Pmax) (< Snum Smax))
(progn
(setq Pnum 1)
(setq lt *ptList*)
(prompt "\nDrawing Lines..\n")
(setq ptList(reverse *ptList*)) ;same way the points were added
(setvar "clayer" "E-NEW-POWER-EQUIP") ;change layer
(command "._LINE")
(apply 'command *ptList*)
(command "")
(prompt "\nLines Drawn.")
(setq *fPanel* (car *ptList*)) ;set FIRST panel in string
(setq *lPanel* (last *ptList*)) ;set LAST panel in string
(DrawCircles *fPanel* *lPanel*)
(MakeCircleLabels *fPanel* *lPanel* Inum Snum)
(TrimCircle *tmp1*)
(TrimCircle *tmp2*)
(setq *ptList* nil) ; clear list of panels to 'string' together
(setvar "clayer" "M-GEN-NOTES") ;reset layer
(setq Snum (+ Snum 1))
) ; end progn
)
(if (and (> Pnum Pmax) (= Snum Smax) (< Inum Imax)) (and (setq Inum (+ Inum 1)) (setq Snum 1) (setq Pnum 1)))
(setvar "ERRNO" 0) ;set system var to zero
) ;end cond errNo=0
((= errNo 7) ; clicked nothing ERROR
(prompt "\nSelection Missed. Try Again")
(setvar "ERRNO" 0) ;set system var to zero
) ;end cond errNo=7
((= errNo 52) ; hit [SPACEBAR]
(prompt "\nDrawing Lines..\n")
(setq *ptList*(reverse *ptList*)) ;same way the points were added
(setvar "clayer" "E-NEW-POWER-EQUIP") ;change layer to PSI "E-NEW-POWER-EUQIP"
(command "._LINE")
(apply 'command *ptList*)
(command "")
(prompt "\nLines Drawn.")
(setq *fPanel* (car *ptList*)) ;set FIRST panel in string
(setq *lPanel* (last *ptList*)) ;set LAST panel in string
(DrawCircles *fPanel* *lPanel*)
(MakeCircleLabels *fPanel* *lPanel* Inum Snum)
(TrimCircle *tmp1*)
(TrimCircle *tmp2*)
(setq *ptList* nil)
(setvar "clayer" "M-GEN-NOTES") ;reset layer
(setvar "ERRNO" 0) ;set system var to zero
) ;end cond errNo=52
(t
) ;end fallback condition (ELSE)
) ;end cond
) ;ends the while statement
(prompt "\nDrawing Lines..\n")
(setq *ptList*(reverse *ptList*)) ;same way the points were added
(setvar "clayer" "E-NEW-POWER-EQUIP") ;change layer
(command "._LINE")
(apply 'command *ptList*)
(command "")
(prompt "\nLines Drawn.")
(setq *fPanel* (car *ptList*)) ;set FIRST panel in string
(setq *lPanel* (last *ptList*)) ;set LAST panel in string
(DrawCircles *fPanel* *lPanel*)
(MakeCircleLabels *fPanel* *lPanel* Inum Snum)
(TrimCircle *tmp1*)
(TrimCircle *tmp2*)
(setq *ptList* nil)
(setvar "clayer" "M-GEN-NOTES") ;reset layer
(setvar "ERRNO" 0) ; resset system var to zero
(princ) ;clean exit
) ; END the INCS function
; This fxn takes first and last panels as args,
;then inserts circles with "inverter.string" text
;------------------------------------------------
(defun DrawCircles (strtC endC)
(entmake (list (cons 0 "CIRCLE")(cons 8 "E-NEW-POWER-EQUIP")(cons 10 strtC)'(40 . 12.0)))
(setq *tmp1* (entlast))
(entmake (list (cons 0 "CIRCLE")(cons 8 "E-NEW-POWER-EQUIP")(cons 10 endC)'(40 . 12.0)))
(setq *tmp2* (entlast))
) ; END defun DrawCircles
(defun MakeCircleLabels (strtP endP invNum strNum) ;(cons 72 10)
(entmake (list (cons 0 "TEXT")(cons 8 "GNO")(cons 10 strtP)(cons 1 (strcat (rtos invNum 2 0) "." (rtos strNum 2 0)))'(40 . 8.0))) ;(list (- (cadr strtP) 3)(- (last strtP) 3))
(entmake (list (cons 0 "TEXT")(cons 8 "GNO")(cons 10 endP)(cons 1 (strcat (rtos invNum 2 0) "." (rtos strNum 2 0)))'(40 . 8.0))) ;(list (- (cadr endP) 3)(- (last endP) 3))
) ; END defun MakeCircleLabels
; This fxn trims all things outside CIRCLES
;------------------------------------------------
(defun TrimCircle (entC)
(setq old-os (getvar "osmode"))
(setvar "osmode" 0)
(setq sset (entget entC)) ;(ssget (list (cons 0 "CIRCLE"))))
(setq n 0)
;(repeat (sslength sset)
(setq obj entC) ;(ssname sset 0.0))
(setq obj1 (vlax-ename->vla-object obj))
(setq cen (vlax-safearray->list (vlax-variant-value (vla-get-center obj1))))
(setq rad (vla-get-radius obj1))
(setq p 0)
(defun DTR (ang)
(* PI (/ ang 180.0))
);defun DTR
(setq ang 0)
(repeat 360
(setq p1 cen)
(setq p2 (polar p1 (DTR ang) rad))
(command "trim" obj "" "f" p1 p2 "" "")
(setq ang (1+ ang))
);repeat
;;; (repeat 360 ; this was getting rid of text (dont want to)
;;; (setq p1 cen)
;;; (setq p2 (polar p1 (DTR ang) (- rad (* 0.1 rad))))
;;; (command "erase" "f" p1 p2 "" "")
;;; (setq ang (1+ ang))
;;; );repeat
(setq n (1+ n))
;);repeat
(princ) ;clean exit
) ; END defun TrimCircle
Originally Posted by
BIG-AL
If you use a while you can do a couple of things a hard pick and repick till you actually pick or ask did you miss do again.
Code:
; hard version
(setq ans "Y")
(while (= ans "Y") (setq entlst (nentsel "\nSelect Line/Polyline in Block :")
(if (= entlst nil)(Alert "Missed pick a bit more carefull")
(setq ans "N")
)
)