ArthurGanem

AGVD CAD Panel Estimator

Mar 28th, 2021 (edited)
652
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; AGVD CAD PANEL ESTIMATOR
  2. ;
  3. ; www.ArthurGanem.com
  4. ;
  5. ; up to 100 panels
  6.  
  7. (prompt "\nLoaded AGVD Panel Estimator! - TRIAL VERSION - NOT FOR COMMERCIAL USE - www.ArthurGanem.com")   
  8. (alert "\nLoaded AGVD Panel Estimator! - This is a TRIAL version and is not allowed for commercial use. (Trial version supports up to 100 panels) \n\nFor licensing information e-mail to contact@ArthurGanem.com")
  9.  
  10. (defun c:esti(/ ss1 ssIndex polyObject vla_poly vla_region mpCenter mpName mpText fileName mpArea mpPerimeter mpFlapArea mpPerimeterCut totalFaceArea totalFlapArea totalPerimeterCut cords mpWidth mpLength)
  11.  
  12.   (setq ss1 (ssget (list
  13.                   (cons 0 "POLYLINE,LWPOLYLINE")
  14.                   (cons -4 "&")
  15.                   (cons 70 1)
  16.                   )
  17.                 )
  18.     )
  19.  
  20.   (setq ssIndex 0)
  21.   (setq mpName (list))
  22.   (setq mpArea (list))
  23.   (setq mpFlapArea (list))
  24.   (setq mpPerimeterCut (list))
  25.   (setq mpLength (list))
  26.   (setq mpWidth (list))
  27.   (setq totalFaceArea 0.0)
  28.   (setq totalFlapArea 0.0)
  29.   (setq totalPerimeterCut 0.0)
  30.  
  31.   (setq fileName (getfiled "Where would you like to save TEXT file with panel estimates?" "" "txt" 1))
  32.   (setq fileName (open fileName "w"))
  33.   (write-line "TRIAL VERSION (Trial version supports up to 100 panels) - NOT FOR COMMERCIAL USE - www.ArthurGanem.com\n" fileName) 
  34.   (write-line "Panel Name\tPanel Length\tPanel Width\tFace Area\tFlap Area\tTotal Perimeter Cut\n" fileName)
  35.  
  36.   (vl-load-com)
  37.  
  38.   (repeat 100              
  39.     (setq polyObject (ssname ss1 ssIndex))
  40.  
  41.     (if (/= polyObject nil)
  42.       (progn                        
  43.  
  44.     (setq vla_poly (vlax-ename->vla-object polyObject))
  45.    
  46.     (setq mpName (append mpName (list (strcat "MP-" (itoa ssIndex)))))
  47.        
  48.     (progn             
  49.       (setq vla_region
  50.          (car (vlax-safearray->list
  51.             (vlax-variant-value
  52.               (vla-addregion
  53.                 (vla-objectidtoobject
  54.                   (vla-get-document vla_poly)
  55.                   (vla-get-ownerid vla_poly)
  56.                   )
  57.  
  58.                 (vlax-safearray-fill
  59.                   (vlax-make-safearray vlax-vbobject (cons 0 (1- (length (list vla_poly)))))
  60.                   (list vla_poly)
  61.                   )
  62.                 )
  63.               )
  64.             )
  65.               )
  66.         )
  67.  
  68.       (setq mpCenter (vlax-safearray->list
  69.                (vlax-variant-value
  70.                  (vla-get-centroid vla_region)
  71.                )
  72.              )
  73.         )
  74.      
  75.       (vla-delete vla_region)
  76.      
  77.     ) ; progn
  78.  
  79.     (setq mpText (vla-addtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (nth ssIndex mpName) (vlax-3d-point mpCenter) 4.5))
  80.     (vla-put-StyleName mpText "Standard")
  81.  
  82.  
  83.     (setq cords (vlax-safearray->list(vlax-variant-value (vla-get-coordinates vla_poly))))
  84.     (setq mpLength (append mpLength (list (/ (abs (- (nth 0 cords) (nth 4 cords))) 12))))
  85.     (setq mpWidth (append mpWidth (list (/ (abs (- (nth 1 cords) (nth 5 cords))) 12))))
  86.     (setq mpArea (append mpArea (list (/ (vla-get-Area vla_poly) 144))))
  87.     (setq mpPerimeter (vla-get-Length vla_poly))
  88.     (setq mpFlapArea (append mpFlapArea (list (/ (* mpPerimeter 1.0625) 144))))
  89.     (setq mpPerimeterCut (append mpPerimeterCut (list (+ (nth ssIndex mpArea) (nth ssIndex mpFlapArea)))))
  90.  
  91.     (write-line (strcat (nth ssIndex mpName) "\t" (rtos (nth ssIndex mpLength) 2) "\t" (rtos (nth ssIndex mpWidth) 2) "\t" (rtos (nth ssIndex mpArea) 2) "\t" (rtos (nth ssIndex mpFlapArea) 2) "\t" (rtos (nth ssIndex mpPerimeterCut) 2)) fileName)
  92.  
  93.     (setq totalFaceArea (+ totalFaceArea (nth ssIndex mpArea)))
  94.     (setq totalFlapArea (+ totalFlapArea (nth ssIndex mpFlapArea)))
  95.     (setq totalPerimeterCut (+ totalPerimeterCut (nth ssIndex mpPerimeterCut)))
  96.  
  97.     (setq ssIndex (+ ssIndex 1))
  98.    
  99.       ))
  100.    
  101.    )
  102.  
  103.  
  104.   (write-line (strcat "\n\nTOTAL FACE AREA:\t\t" (rtos totalFaceArea 2)) fileName)
  105.   (write-line (strcat "TOTAL FLAP AREA:\t\t" (rtos totalFlapArea 2)) fileName)
  106.   (write-line (strcat "TOTAL PERIMETER CUT (AREA):\t" (rtos totalPerimeterCut 2)) fileName)
  107.  
  108.   (close fileName)
  109.  
  110.   (prompt "\n-------- TEXT FILE EXPORTED --------")
  111.   (prompt (strcat "\n\nTOTAL FACE AREA:\t\t\t\t " (rtos totalFaceArea 2) "\n" ))
  112.   (prompt (strcat "TOTAL FLAP AREA:\t\t\t\t " (rtos totalFlapArea 2) "\n" ))
  113.   (prompt (strcat "TOTAL PERIMETER CUT (AREA):\t" (rtos totalPerimeterCut 2) "\n" ))
  114.  
  115.   (princ)
  116.   )
RAW Paste Data