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

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Sum of length of different diameter pipes
« Reply #15 on: March 09, 2016, 12:20:10 PM »
Yoo bro, inconsitent :yes:
Thanks a lot  :smitten: , though not 100% but it worked great!!
It's as accurate as your drafting  ;)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Sum of length of different diameter pipes
« Reply #16 on: March 09, 2016, 01:21:04 PM »
... Well actually there is an issue I believe. I am thinking of the case where a long section is relatively close to a shorter section.
Code: [Select]
O
|
|  O
|  |
|t |t
|  |
|  O
|
O

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Sum of length of different diameter pipes
« Reply #17 on: March 09, 2016, 01:38:53 PM »
You are correct .. but did not have time to address that. how would you solve it? Plus there are a few other things related to bad drafting that will stump it too :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Sum of length of different diameter pipes
« Reply #18 on: March 10, 2016, 05:08:43 AM »
The inaccuracies in the dwg are indeed problematic. A perfect solution is therefore not possible.
To solve the problem I have raised, I would adapt your code along these lines:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bazinga (/ _dxf _unq _ProcessPoints _OnLineP clr f fz i o p pts pts2 sp ss)
  2.  
  3.   (defun _dxf (code ename)
  4.     (if   (and ename (= (type ename) 'ename))
  5.       (cdr (assoc code (entget ename '("*"))))
  6.     )
  7.   )
  8.  
  9.   (defun _unq (i l f) (null (vl-some (function (lambda (x) (equal i x f))) l)))
  10.  
  11.   (defun _ProcessPoints (ptIns ptLst fuzz / enme ptSta ptEnd ss )
  12.     (if
  13.       (and
  14.         (setq ss
  15.           (ssget
  16.             "_C"
  17.             (mapcar '- ptIns (list fuzz fuzz))
  18.             (mapcar '+ ptIns (list fuzz fuzz))
  19.             '((0 . "LINE") (8 . "TEST"))
  20.           )
  21.         )
  22.         (= 1 (sslength ss))
  23.       )
  24.       (progn
  25.         (setq enme (ssname ss 0))
  26.         (setq ptSta (_dxf 10 enme))
  27.         (setq ptEnd (_dxf 11 enme))
  28.         (setq ptLst
  29.           (vl-remove-if-not
  30.             '(lambda (pt) (_OnLineP pt ptSta ptEnd fuzz))
  31.             ptLst
  32.           )
  33.         )
  34.         (setq ptLst
  35.           (vl-sort ptLst '(lambda (a b) (< (distance ptIns a) (distance ptIns b))))
  36.         )
  37.         (if (< 1 (length ptLst)) (list (car ptLst) (cadr ptLst)))
  38.       )
  39.     )
  40.   )
  41.  
  42.   (defun _OnLineP (pt ptSta ptEnd fuzz)
  43.     (equal
  44.       (distance ptSta ptEnd)
  45.       (+ (distance pt ptSta) (distance pt ptEnd))
  46.       fuzz
  47.     )
  48.   )
  49.  
  50.   (vla-zoomextents (vlax-get-acad-object)) ; Required for function _ProcessPoints.
  51.   (setq fz 0.5)
  52.   (if (setq ss  (ssget "_x"
  53.                   (list
  54.                     '(-4 . "<OR")
  55.                       '(-4 . "<AND") '(0 . "insert") '(2 . "b") '(-4 . "AND>")
  56.                       '(-4 . "<AND") '(0 . "line") '(8 . "test") '(-4 . "AND>")
  57.                       '(-4 . "<AND") '(0 . "text") '(1 . "`%`%C*") '(-4 . "AND>")
  58.                     '(-4 . "OR>")
  59.                   )
  60.                 )
  61.       )
  62.     (progn (foreach x (mapcar 'cadr (ssnamex ss))
  63.         (cond
  64.          ((= "INSERT" (_dxf 0 x))
  65.           (if   (_unq (setq p (_dxf 10 x)) pts fz)
  66.             (setq pts (cons p pts))
  67.           )
  68.          )
  69.          ((= "LINE" (_dxf 0 x))
  70.           (if   (_unq (setq p (_dxf 10 x)) pts fz)
  71.             (setq pts (cons p pts))
  72.           )
  73.           (if   (_unq (setq p (_dxf 11 x)) pts fz)
  74.             (setq pts (cons p pts))
  75.           )
  76.          )
  77.          ((= "TEXT" (_dxf 0 x))
  78.           (if   (_unq (setq p (list (_dxf 10 x) (_dxf 1 x))) pts2 fz)
  79.             (setq pts2 (cons p pts2))
  80.           )
  81.          )
  82.         )
  83.       )
  84.       (foreach x pts2
  85.         (if (setq sp (_ProcessPoints (car x) pts (* 5 fz))) ; Big fuzz required...
  86.           (progn
  87.             (if (<= (setq clr (atoi (substr (cadr x) 4))) 0)
  88.               (setq clr 256)
  89.             )
  90.             (entmakex (list '(0 . "LWPOLYLINE")
  91.                   '(100 . "AcDbEntity")
  92.                   (cons 8 (vl-princ-to-string (atof (substr (cadr x) 4))))
  93.                   (cons 62 clr)
  94.                   '(100 . "AcDbPolyline")
  95.                   '(90 . 2)
  96.                   (cons 43 6.0)
  97.                   (cons 10 (car sp))
  98.                   (cons 10 (cadr sp))
  99.                  )
  100.             )
  101.           )
  102.         )
  103.       )
  104.     )
  105.   )
  106.   (princ)
  107. )
  108.