Jump to content

Having trouble adding "IF" to lisp routine to cycle through subs for area totals


Croftyno1

Recommended Posts

Hi,

 

I am struggling with my adapted lisp routine with snippets of code from LEE MACK and TRAVIS KNAPP.

 

The problem is if you tried to run this routine it works fine if all layers included in the lisp have been selected on the drawing but, if layer1 for instance wasnt on a particular selection ive picked from the drawing the routine does not carry on and cycle through the rest.

 

Please note: if you are trying to help, please assign a thickness to the lines or it wont work. (for quantities the thickness value is my depth).

 

(defun c:ad ()

 
(test)

 ; RE560
				
 	(setq total 0)
 	(setq count (sslength ss1))
	(while (/= count 0)
		(setq N1 (ssname ss1 0))
		(setq N2 (entget N1))
		(setq pnt10 (cdr (assoc 10 N2)))
		(setq pnt11 (cdr (assoc 11 N2)))        
		(setq dist1 (distance pnt10 pnt11))
		(setq thick (cdr (assoc 39 N2)))
		(setq dist (* thick dist1))
		(setq total (+ dist total))
		(ssdel n1 ss1)
		(setq count (1- count))
	);end while
 			(setq total1 (/ total 1000))

 (command "-STYLE" "simplex.txt" "simplex" "250" "1" "0" "n" "n" "n")  (command "color" "byl") ; changes text color to new layer
 (command "LAYER" "M" "area" "") ; Created a new layer
 (setq p (getpoint "Pick text location: ")) ; picking where you want the text
 (command "TEXT" "BC" p "" (strcat (rtos total1 2 3) " layer1m\U+00B2")) ; creates text and converts real number to string

 ; RE570
   (setq total2 0)
 (setq count1 (sslength ss2))
(while (/= count1 0)
(setq N3 (ssname ss2 0))
(setq N4 (entget N3))
(setq pnt12 (cdr (assoc 10 N4)))
(setq pnt13 (cdr (assoc 11 N4)))        
(setq dist2 (distance pnt12 pnt13))
(setq thick1 (cdr (assoc 39 N4)))
(setq dist0 (* thick1 dist2))
(setq total2 (+ dist0 total2))
(ssdel n3 ss2)
(setq count1 (1- count1))
);end while
 (setq total3 (/ total2 1000))

  (command "-STYLE" "simplex.txt" "simplex" "250" "1" "0" "n" "n" "n")  (command "color" "byl") ; changes text color to new layer
 (command "LAYER" "M" "area" "") ; Created a new layer
 (setq p1 (getpoint "Pick text location: ")) ; picking where you want the text
 (command "TEXT" "BC" p1 "" (strcat (rtos total3 2 3) " layer2m\U+00B2")) ; creates text and converts real number to string

 ; RE510
  (setq total4 0)
 (setq count2 (sslength ss3))
(while (/= count2 0)
(setq N5 (ssname ss3 0))
(setq N6 (entget N5))
(setq pnt14 (cdr (assoc 10 N6)))
(setq pnt15 (cdr (assoc 11 N6)))        
(setq dist3 (distance pnt14 pnt15))
(setq thick2 (cdr (assoc 39 N6)))
(setq dist4 (* thick2 dist3))
(setq total4 (+ dist4 total4))
(ssdel n5 ss3)
(setq count2 (1- count2))
);end while
 (setq total5 (/ total4 1000))
  (command "-STYLE" "simplex.txt" "simplex" "250" "1" "0" "n" "n" "n")  (command "color" "byl") ; changes text color to new layer
 (command "LAYER" "M" "area" "") ; Created a new layer
 (setq p2 (getpoint "Pick text location: ")) ; picking where you want the text
 (command "TEXT" "BC" p2 "" (strcat (rtos total5 2 3) " layer3m\U+00B2")) ; creates text and converts real number to string


 ; RE520
 
  (setq total6 0)
 (setq total99 0)
 (setq count3 (sslength ss4))
(while (/= count3 0)
(setq N7 (ssname ss4 0))
(setq N8 (entget N7))
(setq pnt16 (cdr (assoc 10 N8)))
(setq pnt17 (cdr (assoc 11 N8)))        
(setq dist5 (distance pnt16 pnt17))
(setq thick3 (cdr (assoc 39 N8)))
(setq dist6 (* thick3 dist5))
(setq total99 (+ dist5 total99))
(setq total6 (+ dist6 total6))
(ssdel n7 ss4)
(setq count3 (1- count3))
);end while
 (setq total7 (/ total6 1000))
 (setq total100 (/ total99 1000))
  (command "-STYLE" "simplex.txt" "simplex" "250" "1" "0" "n" "n" "n")  (command "color" "byl") ; changes text color to new layer
 (command "LAYER" "M" "area" "") ; Created a new layer
 (setq p3 (getpoint "Pick text location: ")) ; picking where you want the text
 (command "TEXT" "BC" p3 "" (strcat (rtos total7 2 3) " layer4m\U+00B2")) ; creates text and converts real number to string
 
(command "-STYLE" "simplex.txt" "simplex" "250" "1" "0" "n" "n" "n")  (command "color" "byl") ; changes text color to new layer
 (command "LAYER" "M" "area" "") ; Created a new layer
 (setq p99 (getpoint "Pick text location: ")) ; picking where you want the text
 (command "TEXT" "BC" p99 "" (strcat (rtos total100 2 3) " layer4 lin/m")) ; creates text and converts real number to string
 (princ)


 
  ; RE540
 
  (setq total8 0)
 (setq count4 (sslength ss5))
(while (/= count4 0)
(setq N9 (ssname ss5 0))
(setq N10 (entget N9))
(setq pnt18 (cdr (assoc 10 N10)))
(setq pnt19 (cdr (assoc 11 N10)))        
(setq dist7 (distance pnt18 pnt19))
(setq thick4 (cdr (assoc 39 N10)))
(setq dist8 (* thick4 dist7))
(setq total8 (+ dist8 total8))
(ssdel n9 ss5)
(setq count4 (1- count4))
);end while
 (setq total9 (/ total8 1000))
  (command "-STYLE" "simplex.txt" "simplex" "250" "1" "0" "n" "n" "n")  (command "color" "byl") ; changes text color to new layer
 (command "LAYER" "M" "area" "") ; Created a new layer
 (setq p4 (getpoint "Pick text location: ")) ; picking where you want the text
 (command "TEXT" "BC" p4 "" (strcat (rtos total9 2 3) " layer5m\U+00B2")) ; creates text and converts real number to string 


  ; RE580
 
  (setq total10 0)
 (setq count5 (sslength ss6))
(while (/= count5 0)
(setq N11 (ssname ss6 0))
(setq N12 (entget N11))
(setq pnt20 (cdr (assoc 10 N12)))
(setq pnt21 (cdr (assoc 11 N12)))        
(setq dist9 (distance pnt20 pnt21))
(setq thick5 (cdr (assoc 39 N12)))
(setq dist10 (* thick5 dist9))
(setq total10 (+ dist10 total10))
(ssdel n11 ss6)
(setq count5 (1- count5))
);end while
 (setq total11 (/ total10 1000))
  (command "-STYLE" "simplex.txt" "simplex" "250" "1" "0" "n" "n" "n")  (command "color" "byl") ; changes text color to new layer
 (command "LAYER" "M" "area" "") ; Created a new layer
 (setq p5 (getpoint "Pick text location: ")) ; picking where you want the text
 (command "TEXT" "BC" p5 "" (strcat (rtos total11 2 3) " layer6m\U+00B2")) ; creates text and converts real number to string 


 (princ)
); end program



(defun test ( / ss ) (vl-load-com)
 
 (if (setq ss (ssget (setq l '((8 . "layer1,layer2,layer3,layer4,layer5,layer6")))))
   (
     (lambda ( l / i e sym )
       (repeat (setq i (sslength ss))
         (ssadd (setq e (ssname ss (setq i (1- i))))
           (cond
             (
               (eval
                 (setq sym
                   (read
                     (strcat "ss"
                       (
                         (lambda ( j )
                           (vl-some
                             (function
                               (lambda ( x ) (setq j (1+ j))
                                 (if (wcmatch (strcase (cdr (assoc 8 (entget e)))) (strcase x))
                                   (itoa j)
                                 )
                               )
                             )
                             l
                           )
                         )
                         0
                       )
                     )
                   )
                 )
               )
             )
             ( (set sym (ssadd)) )
           )
         )
       )
     )
     (LM:str->lst (cdar l) ",")
   )
 )
)

;;-------------------=={ String to List }==-------------------;;
;;                                                            ;;
;;  Separates a string into a list of strings using a         ;;
;;  specified delimiter string                                ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - string to process                                   ;;
;;  del - delimiter by which to separate the string           ;;
;;------------------------------------------------------------;;
;;  Returns:  A list of strings                               ;;
;;------------------------------------------------------------;;

(defun LM:str->lst ( str del / pos ) (vl-load-com)
 ;; © Lee Mac 2010
 (if (setq pos (vl-string-search del str))
   (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
   (list str)
 )
)

 

ooh ahh cantona

Link to comment
Share on other sites

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