Author Topic: Sum of length of different diameter pipes  (Read 4891 times)

0 Members and 1 Guest are viewing this topic.

tanvirme2k9

  • Guest
Sum of length of different diameter pipes
« on: February 26, 2016, 12:46:39 PM »
Hi All,

I am interesting in a lisp which will sum up the pipe lengths of different diameters.Then make a table of total pipe length according to diameters and count number of times the same diameter is used. I am attaching drawing for reference. Is it possible? :-(

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Sum of length of different diameter pipes
« Reply #1 on: February 26, 2016, 01:19:45 PM »
do you use MAP or Civil 3d?

IF yes, then yes with a simple MAP Query


otherwise....you're stuck with LISP or other solution
Be your Best


Michael Farrell
http://primeservicesglobal.com/

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Sum of length of different diameter pipes
« Reply #2 on: February 26, 2016, 01:22:05 PM »
actually seeing all your data on layer "test" then not with a query until you put those 'pipes' on unique pipe size layers, or embed some object data


at this point they are just dumb cad lines and not much use....for MAP
Be your Best


Michael Farrell
http://primeservicesglobal.com/

ChrisCarlson

  • Guest
Re: Sum of length of different diameter pipes
« Reply #3 on: February 26, 2016, 01:30:44 PM »
As-is no, split up layers and use a simple line counter routine.

Code - Auto/Visual Lisp: [Select]
  1. ;;--------------------=={ Total Length }==--------------------;;
  2. ;;                                                            ;;
  3. ;;  Displays the total length of selected objects at the      ;;
  4. ;;  command line. The units and precision format of the       ;;
  5. ;;  printed result is dependent upon the settings of the      ;;
  6. ;;  LUNITS & LUPREC system variables respectively.            ;;
  7. ;;------------------------------------------------------------;;
  8. ;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
  9. ;;------------------------------------------------------------;;
  10.  
  11. (defun c:tlen ( / e i l s )
  12.     (if (setq s
  13.             (ssget
  14.                '(   (0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
  15.                     (-4 . "<NOT")
  16.                         (-4 . "<AND")
  17.                             (0 . "POLYLINE") (-4 . "&") (70 . 80)
  18.                         (-4 . "AND>")
  19.                     (-4 . "NOT>")
  20.                 )
  21.             )
  22.         )
  23.         (progn
  24.             (setq l 0.0)
  25.             (repeat (setq i (sslength s))
  26.                 (setq e (ssname s (setq i (1- i)))
  27.                       l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
  28.                 )
  29.             )
  30.             (princ "\nTotal Length: ")
  31.             (princ (rtos l))
  32.         )
  33.     )
  34.     (princ)
  35. )

tanvirme2k9

  • Guest
Re: Sum of length of different diameter pipes
« Reply #4 on: February 26, 2016, 01:33:01 PM »
Mjfarrell, I am using Autocad 2016. Oh.. sorry! the lines,blocks and dia, all will be in different layers :tongue2:
ChrisCarlson, Thanks for your reply, I use this routine for different purpose. But here I am wanting total length with respect to diameter, separated by blocks.
« Last Edit: February 26, 2016, 01:39:19 PM by tanvirme2k9 »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Sum of length of different diameter pipes
« Reply #5 on: February 27, 2016, 01:53:41 AM »
This lisp calculate per layer and show data on excel may helps
this lisp is not mine and I did not remember either from where I got or the coder.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mlen (/ m ss clist temp xls sort combine mlen4_1)
  2.   (defun sort (lst predicate)
  3.     (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst predicate))
  4.   )
  5.   (defun combine (inlist is-greater is-equal / sorted current result)
  6.     (setq sorted (sort inlist is-greater))
  7.     (setq current (list (car sorted)))
  8.     (foreach item (cdr sorted)
  9.       (if (apply is-equal (list item (car current)))
  10.         (setq current (cons item current))
  11.         (progn
  12.           (setq result (cons current result))
  13.           (setq current (list item))
  14.         )
  15.       )
  16.     )
  17.     (cons current result)
  18.   )
  19.   (defun xls (Data-list      header         Colhide
  20.               Name_list      /              *aplexcel*
  21.               *books-colection*             Currsep
  22.               *excell-cells* *new-book*     *sheet#1*
  23.               *sheet-collection*            col
  24.               iz_listo       row            cell
  25.               cols
  26.              )
  27.     (defun Letter (N / Res TMP)
  28.       (setq Res "")
  29.       (while (> N 0)
  30.         (setq TMP (rem N 26)
  31.               TMP (if (zerop TMP)
  32.                     (setq N   (1- N)
  33.                           TMP 26
  34.                     )
  35.                     TMP
  36.                   )
  37.               Res (strcat (chr (+ 64 TMP)) Res)
  38.               N   (/ N 26)
  39.         )
  40.       )
  41.       Res
  42.     )
  43.     (if (null Name_list)
  44.       (setq Name_list "")
  45.     )
  46.     (setq *AplExcel* (vlax-get-or-create-object "Excel.Application"))
  47.     (if (setq *New-Book* (vlax-get-property *AplExcel* "ActiveWorkbook"))
  48.       (setq *Books-Colection*  (vlax-get-property *AplExcel* "Workbooks")
  49.             *Sheet-Collection* (vlax-get-property *New-Book* "Sheets")
  50.             *Sheet#1*          (vlax-invoke-method *Sheet-Collection* "Add")
  51.       )
  52.       (setq *Books-Colection*  (vlax-get-property *AplExcel* "Workbooks")
  53.             *New-Book*         (vlax-invoke-method *Books-Colection* "Add")
  54.             *Sheet-Collection* (vlax-get-property *New-Book* "Sheets")
  55.             *Sheet#1*          (vlax-get-property *Sheet-Collection* "Item" 1)
  56.       )
  57.     )
  58.     (setq *excell-cells* (vlax-get-property *Sheet#1* "Cells"))
  59.     (setq Name_list (if (= Name_list "")
  60.                       (vl-filename-base (getvar "DWGNAME"))
  61.                       (strcat (vl-filename-base (getvar "DWGNAME"))
  62.                               "&"
  63.                               Name_list
  64.                       )
  65.                     )
  66.           col       0
  67.           cols      nil
  68.     )
  69.     (if (> (strlen Name_list) 26)
  70.       (setq Name_list
  71.              (strcat (substr Name_list 1 10)
  72.                      "..."
  73.                      (substr Name_list (- (strlen Name_list) 13) 14)
  74.              )
  75.       )
  76.     )
  77.     (vlax-for sh *Sheet-Collection*
  78.       (setq cols (cons (strcase (vlax-get-property sh 'Name)) cols))
  79.     )
  80.     (setq row Name_list)
  81.     (while (member (strcase row) cols)
  82.       (setq row (strcat Name_list " (" (itoa (setq col (1+ col))) ")"))
  83.     )
  84.     (setq Name_list row)
  85.     (vlax-put-property *Sheet#1* 'Name Name_list)
  86.     (setq Currsep (vlax-get-property *AplExcel* "UseSystemSeparators"))
  87.       *AplExcel*
  88.       "UseSystemSeparators"
  89.       :vlax-false
  90.     ) ;_?? ???????????? ????????? ?????????
  91.     (vlax-put-property *AplExcel* "DecimalSeparator" ".") ;_??????????? ??????? ? ????? ?????
  92.     (vlax-put-property *AplExcel* "ThousandsSeparator" " ") ;_??????????? ???????
  93.     (vla-put-visible *AplExcel* :vlax-true)
  94.     (setq row 1
  95.           col 1
  96.     )
  97.     (if (null header)
  98.       (setq header '("X" "Y" "Z"))
  99.     )
  100.     (repeat (length header)
  101.         *excell-cells*
  102.         "Item"
  103.         row
  104.         col
  105.         (vl-princ-to-string (nth (1- col) header))
  106.       )
  107.       (setq col (1+ col))
  108.     )
  109.     (setq row 2
  110.           col 1
  111.     )
  112.     (repeat (length Data-list)
  113.       (setq iz_listo (car Data-list))
  114.       (repeat (length iz_listo)
  115.         (vlax-put-property
  116.           *excell-cells*
  117.           "Item"
  118.           row
  119.           col
  120.           (vl-princ-to-string (car iz_listo))
  121.         )
  122.         (setq iz_listo (cdr iz_listo)
  123.               col      (1+ col)
  124.         )
  125.       )
  126.       (setq Data-list (cdr Data-list))
  127.       (setq col 1
  128.             row (1+ row)
  129.       )
  130.     )
  131.     (setq col (1+ (length header))
  132.           row (1+ row)
  133.     )
  134.     (setq cell (vlax-variant-value
  135.                  (vlax-invoke-method
  136.                    *Sheet#1*
  137.                    "Evaluate"
  138.                    (strcat "A1:" (letter col) (itoa row))
  139.                  )
  140.                )
  141.     ) ;_ end of setq
  142.     (setq cols (vlax-get-property cell 'Columns))
  143.     (vlax-invoke-method cols 'Autofit)
  144.     (vlax-release-object cols)
  145.     (vlax-release-object cell)
  146.     (foreach item ColHide
  147.       (if (numberp item)
  148.         (setq item (letter item))
  149.       )
  150.       (setq cell (vlax-variant-value
  151.                    (vlax-invoke-method
  152.                      *Sheet#1*
  153.                      "Evaluate"
  154.                      (strcat item "1:" item "1")
  155.                    )
  156.                  )
  157.       )
  158.       (setq cols (vlax-get-property cell 'Columns))
  159.       (vlax-put-property cols 'hidden 1)
  160.       (vlax-release-object cols)
  161.       (vlax-release-object cell)
  162.     )
  163.     (vlax-put-property *AplExcel* "UseSystemSeparators" Currsep)
  164.             (list *excell-cells*      *Sheet#1*
  165.                   *Sheet-Collection*  *New-Book*
  166.                   *Books-Colection*   *AplExcel*
  167.                  )
  168.     )
  169.     (setq *AplExcel* nil)
  170.     (gc)
  171.     (gc)
  172.     (princ)
  173.   )
  174.   (defun mlen4_1 (lst / sum_len)
  175.     (setq sum_len 0)
  176.     (foreach item (mapcar 'car lst)
  177.       (setq
  178.         sum_len (+ sum_len
  179.                    (if (vlax-property-available-p item 'length)
  180.                      (vla-get-length item)
  181.                      (cond
  182.                        ((=
  183.                           (strcase (vla-get-objectname item) t)
  184.                           "acdbarc"
  185.                         ) ;_  =
  186.                         (vla-get-arclength item)
  187.                        )
  188.                        ((=
  189.                           (strcase (vla-get-objectname item) t)
  190.                           "acbcircle"
  191.                         ) ;_  =
  192.                         (* pi 2.0 (vla-get-radius item))
  193.                        )
  194.                        (t 0.0)
  195.                      ) ;_  cond
  196.                    ) ;_  if
  197.                 ) ;_  +
  198.       )
  199.     )
  200.     (if (not (zerop sum_len))
  201.       (princ
  202.         (strcat "\n\t" (cdar lst) " = " (rtos (* sum_len m) 2 4))
  203.       )
  204.     )
  205.     (list (cdar lst) (rtos (* sum_len m) 2 4))
  206.   )
  207.   (if (null *M*)
  208.     (setq *M* 1)
  209.   )
  210.   (initget 6)
  211.   (and
  212.     (princ "\nEnter scale factor <")
  213.     (princ *M*)
  214.     (princ ">: ")
  215.     (or (setq m (getreal))
  216.         (setq m *M*)
  217.     )
  218.     (setq *M* m)
  219.     (setq ss (ssget "_:L"))
  220.     (setq ss (mapcar
  221.                (function vlax-ename->vla-object)
  222.                (vl-remove-if
  223.                  (function listp)
  224.                  (mapcar
  225.                    (function cadr)
  226.                    (ssnamex ss)
  227.                  ) ;_  mapcar
  228.                ) ;_ vl-remove-if
  229.              )
  230.     )
  231.     (mapcar '(lambda (x)
  232.                (setq temp (cons (cons x (vla-get-Layer x)) temp))
  233.              )
  234.             ss
  235.     )
  236.     (setq clist (combine temp
  237.                          '(lambda (a b)
  238.                             (> (cdr a) (cdr b))
  239.                           )
  240.                          '(lambda (a b)
  241.                             (eq (cdr a) (cdr b))
  242.                           )
  243.                 )
  244.     )
  245.     (princ
  246.       "\n\n  The total length of all line primitives by layers:"
  247.     )
  248.     (setq temp (mapcar 'mlen4_1 clist))
  249.     (xls temp '("Layer" "Length") nil "mlen41")
  250.   )
  251.   (princ)
  252. ) ;_  defun

tanvirme2k9

  • Guest
Re: Sum of length of different diameter pipes
« Reply #6 on: February 27, 2016, 04:22:28 AM »
Thanks Mr. Hasan.But it's very difficult to connect over thousands of blocks with different layered lines :shifty:

tanvirme2k9

  • Guest
Re: Sum of length of different diameter pipes
« Reply #7 on: March 03, 2016, 11:53:04 PM »
Anyone? :-(

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Sum of length of different diameter pipes
« Reply #8 on: March 07, 2016, 02:00:45 PM »
The more automated the process is, the more consistent the data must be.  If you cannot guarantee consistency across your data the process cannot be readily automated.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

tanvirme2k9

  • Guest
Re: Sum of length of different diameter pipes
« Reply #9 on: March 08, 2016, 09:40:11 AM »
dgorsman, the data is consistent  :-)

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Sum of length of different diameter pipes
« Reply #10 on: March 08, 2016, 10:14:38 AM »
Thanks Mr. Hasan.But it's very difficult to connect over thousands of blocks with different layered lines :shifty:

Would seem to indicate otherwise.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Sum of length of different diameter pipes
« Reply #11 on: March 08, 2016, 03:27:16 PM »
This should help break up the segments into layers .. only works with lines on layer 'test' your block 'b' & text items that match '%%C*'. Each segment has to have a label associated with it.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bazinga (/ _dxf _unq clr f fz i o p pts pts2 sp ss)
  2.   (defun _dxf (code ename)
  3.     (if   (and ename (= (type ename) 'ename))
  4.       (cdr (assoc code (entget ename '("*"))))
  5.     )
  6.   )
  7.   (defun _unq (i l f) (null (vl-some (function (lambda (x) (equal i x f))) l)))
  8.   (setq fz 0.5)
  9.   (if (setq ss (ssget "_x"
  10.             (list '(-4 . "<OR")    '(-4 . "<AND")         '(0 . "insert")
  11.              '(2 . "b")       '(-4 . "AND>")         '(-4 . "<AND")
  12.              '(0 . "line")    '(8 . "test")         '(-4 . "AND>")
  13.              '(-4 . "<AND")    '(0 . "text")         '(1 . "`%`%C*")
  14.              '(-4 . "AND>")    '(-4 . "OR>")
  15.             )
  16.           )
  17.       )
  18.     (progn (foreach x (mapcar 'cadr (ssnamex ss))
  19.         (cond ((= "INSERT" (_dxf 0 x))
  20.           (if   (_unq (setq p (_dxf 10 x)) pts fz)
  21.             (setq pts (cons p pts))
  22.           )
  23.          )
  24.          ((= "LINE" (_dxf 0 x))
  25.           (if   (_unq (setq p (_dxf 10 x)) pts fz)
  26.             (setq pts (cons p pts))
  27.           )
  28.           (if   (_unq (setq p (_dxf 11 x)) pts fz)
  29.             (setq pts (cons p pts))
  30.           )
  31.          )
  32.          ((= "TEXT" (_dxf 0 x))
  33.           (if   (_unq (setq p (list (_dxf 10 x) (_dxf 1 x))) pts2 fz)
  34.             (setq pts2 (cons p pts2))
  35.           )
  36.          )
  37.         )
  38.       )
  39.       (foreach x pts2
  40.         (setq p (car x))
  41.         (setq sp (vl-sort pts (function (lambda (a b) (< (distance p a) (distance p b))))))
  42.         (if (<= (setq clr (atoi (substr (cadr x) 4))) 0)
  43.           (setq clr 256)
  44.         )
  45.         (entmakex (list '(0 . "LWPOLYLINE")
  46.               '(100 . "AcDbEntity")
  47.               (cons 8 (vl-princ-to-string (atof (substr (cadr x) 4))))
  48.               (cons 62 clr)
  49.               '(100 . "AcDbPolyline")
  50.               '(90 . 2)
  51.               (cons 43 6.0)
  52.               (cons 10 (car sp))
  53.               (cons 10 (cadr sp))
  54.              )
  55.         )
  56.       )
  57.     )
  58.   )
  59.   (princ)
  60. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

tanvirme2k9

  • Guest
Re: Sum of length of different diameter pipes
« Reply #12 on: March 09, 2016, 06:45:56 AM »
Not working in my work drawing :sniffles: Please see attached.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Sum of length of different diameter pipes
« Reply #13 on: March 09, 2016, 08:54:15 AM »
Well full circle .. it's because your data is not consistent.  ;D  If you draw your map using just LINES, place your labels at the midpoint of the ends of your segment & be consistent with OSNAPS, you'd get decent results.
« Last Edit: March 09, 2016, 09:43:46 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

tanvirme2k9

  • Guest
Re: Sum of length of different diameter pipes
« Reply #14 on: March 09, 2016, 11:51:54 AM »
Yoo bro, inconsitent :yes:
Thanks a lot  :smitten:, though not 100% but it worked great!!