Results 1 to 3 of 3

Thread: Don't want to have to restart when clicking a NON-polyline - CODE

  1. #1
    Member
    Join Date
    2018-02
    Posts
    2
    Login to Give a bone
    0

    Question Don't want to have to restart when clicking a NON-polyline - CODE

    Hey guys,
    I am very familiar with VBA, but not so much LISP. I have "inherited" a project where the user specifies arguments (Inverters, Strings, Panels; it is a solar energy project), then clicks on the line/polyline and it automatically creates multi-line text labeling each solar panel with the correct information. Currently, however, if you start this process, then "miss" clicking on a line/polylilne, the user has to restart the function. I have tried to convert this to VBA, but cant seem to find the correlating syntax for some (much) of the code. The code is listed below and ALSO ATTACHED - "INCS" (increment solar):

    Code:
    (defun C:INCS (/ Inum Snum Pnum entlst entmat entnew entlst entlst2 entlst3 lst y)
      (setq Inum (getint "Enter Inverter Starting Number:"))
        (if (>= Inum 1) (setq Inum Inum) (setq Inum 1))
      (setq Imax (getint "Enter Max Number of Inverters:"))
        (if (>= Imax 1) (setq Imax Imax) (setq Imax 1))
      
      (setq Snum (getint "Enter String Starting Number:"))
        (if (>= Snum 1) (setq Snum Snum) (setq Snum 1))
      (setq Smax (getint "Enter Max Number of Strings on Inverter:"))
        (if (>= Smax 1) (setq Smax Smax) (setq Smax 1))
        
      (setq Pnum (getint "Enter Panel Starting Number:"))
        (if (>= Pnum 1) (setq Pnum Pnum) (setq Pnum 1))
      (setq Pmax (getint "Enter Max Number of Panels on String:"))
        (if (>= Pmax 1) (setq Pmax Pmax) (setq Pmax 1))
    
    
      (while (<= Pnum Pmax)
          
        (setq entlst (nentsel "\nSelect Line/Polyline in Block :")
           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))))))
    
        (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" 
              (* 180 (/ (car (vl-sort (mapcar 'angle lst (cdr lst)) '<)) pi)) y Istring Sstring Pstring "")
    
        (setq Pnum (+ Pnum 1))
        (if (and (> Pnum Pmax) (< Snum Smax)) (and (setq Snum (+ Snum 1)) (setq Pnum 1)))                                   ;if the panel number is less than the max and the string number is less than the max, then increment the string number by 1 and set the panel number to 1
        (if (and (> Pnum Pmax) (= Snum Smax) (< Inum Imax)) (and (setq Inum (+ Inum 1)) (setq Snum 1) (setq Pnum 1)))
        
     
      )                                                                     ;ends the while statement
    )                                                                       ;ends the INCSOLAR command
    If anyone has any ideas so that this function continues, even when the user "misses" clicking a line/polyline, OR if anyone can tell me the best way to convert this to VBA (cannot find the equivalent of "NENTSEL", don't know what is happening at the "mapcar '(lambda (x)"/etc.), it would be much appreciated.

    thanks,
    Rob
    Attached Files Attached Files

  2. #2
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    555
    Login to Give a bone
    0

    Default Re: Don't want to have to restart when clicking a NON-polyline - CODE

    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")
    )
    )

  3. #3
    Member
    Join Date
    2018-02
    Posts
    2
    Login to Give a bone
    0

    Thumbs up Re: Don't want to have to restart when clicking a NON-polyline - CODE

    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



    Quote Originally Posted by BIG-AL View Post
    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")
    )
    )

Similar Threads

  1. Replies: 9
    Last Post: 2015-11-15, 08:35 AM
  2. Deployments need restart after c++?
    By Liamnacuac in forum CAD Management - General
    Replies: 1
    Last Post: 2014-06-06, 06:08 PM
  3. VB.NET polyline code help
    By mbdesigns2013467754 in forum Dot Net API
    Replies: 2
    Last Post: 2013-12-19, 09:40 AM
  4. Replies: 1
    Last Post: 2008-11-06, 01:39 PM
  5. Why you may want to restart Revit once in a while
    By Wes Macaulay in forum Revit Architecture - Tips & Tricks
    Replies: 1
    Last Post: 2003-06-20, 06:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •