Author Topic: Sum text on path  (Read 1596 times)

0 Members and 1 Guest are viewing this topic.

Logan

  • Newt
  • Posts: 41
Sum text on path
« on: January 29, 2014, 09:32:02 AM »
Hello everybody.
         
Am new to this forum and also in autolisp.

I found a very interesting solution that find the possible path between two selections amid rows of connections. The program prompts you to select the initial entity and the final entity then find the possible path for that connection.
Excellent program.
http://www.theswamp.org/index.php?PHPSESSID=eh92qsjg8qp0e2a77u0d09e013&topic=1749.msg22949#msg22949

I wonder if using the same concept, it is possible to make the program perform the sum of the texts above of lines?

Is this possible?

Code:
Code: [Select]
;;  ***************************************************************
;;   pline path finder.lsp
;;   Charles Alan Butler 07/08/2004
;;   Modified routine to find a path from picked start entity
;;   to picked end entity.
;;
;;   Returns the first path if it exist else nil, not the shortest path
;;   Selects & highlites the path also
;;  ***************************************************************

 ;shortcut
(defun c:plp () (c:PlinePath))

;;;  ***************************************************************
;;;               Original Routine                                 
;;;
;;;  ;; based on Inline.lsp by John Uhden
;;;  ;; modified Joe Burke 5/15/03
;;;  ;; pick a line, arc or lwpline
;;;  ;; creates a selection set of objects which meet end to end
;;;  ;; only selects objects on the same layer as picked object
;;;  ;; pass selection set to pedit join...
;;;
;;;  ***************************************************************


;;===================================
;;      -=<  Sub Routines  >=-       
;;===================================

;;  Return (ename Startpt Endpt)
(defun @arc (ent / e rp r ba ea p1 p2)
  (setq e  (cdr (assoc -1 ent))
        rp (cdr (assoc 10 ent))
        r  (cdr (assoc 40 ent))
        ba (cdr (assoc 50 ent))
        ea (cdr (assoc 51 ent))
        p1 (trans (polar rp ba r) e 0)
        p2 (trans (polar rp ea r) e 0)
  )
  (list e p1 p2)
) ;end

;;  Return (ename Startpt Endpt)
(defun @line (ent)
  (list
    (cdr (assoc -1 ent))
    (cdr (assoc 10 ent))
    (cdr (assoc 11 ent))
  )
) ;end

;;  Return (ename Startpt Endpt)
(defun @pline (ent / e)
  (setq e (cdr (assoc -1 ent)))
  (list
    e
    (car (getends e))
    (cadr (getends e))
  )
) ;end

;;  Add ent-> (ename Startpt Endpt) to list
(defun @list (e / ent)
  (setq ent (entget e))
  (cond
    ((= (cdr (assoc 0 ent)) "LINE")
     (setq sslist (cons (@line ent) sslist))
    )
    ((= (cdr (assoc 0 ent)) "ARC")
     (setq sslist (cons (@arc ent) sslist))
    )
    ((= (cdr (assoc 0 ent)) "LWPOLYLINE")
     (setq sslist (cons (@pline ent) sslist))
    )
  )
) ;end

;;argument: an ename - returns: Start and End points as a list
(defun getends (vobj / name stpt endpt)
  (if (= (type vobj) 'ename)
    (setq vobj (vlax-ename->vla-object vobj))
  )
  (and
    (setq name (vla-get-objectname vobj))
    (cond
      ((vl-position
         name
         '("AcDbArc"           "AcDbLine"          "AcDbEllipse"
           "AcDbSpline"        "AcDbPolyline"      "AcDb2dPolyline"
           "AcDb3dPolyline"
          )
       )
       (setq stpt (vlax-curve-getstartpoint vobj))
       (setq endpt (vlax-curve-getendpoint vobj))
      )
    ) ;cond
  ) ;and
  (list stpt endpt)
) ;end

;; get list of (ename startpt endpt) for picked ent
(defun get:elst(ent)
  (cond
    ((= (cdr (assoc 0 ent)) "ARC")
     (setq ent (@arc ent))
    )
    ((= (cdr (assoc 0 ent)) "LINE")
     (setq ent (@line ent))
    )
    ((= (cdr (assoc 0 ent)) "LWPOLYLINE")
     (setq ent (@pline ent))
    )
  )
  ent
); end defun


;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;          main function               
;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
(defun c:plinepath (/      sslist elist  ss     ssres  i      e      e2
                    found  ent    ent2   ok     start  end    start2 end2
                    fuzz   layer  ssex   typlst
                   )
  ;; Get the start object
  (if ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    (and
      (cadr (ssgetfirst)) ;objects are selected
      ;;at least one arc, line or pline
      (setq ssex (ssget "i" (list (cons 0 "LINE,ARC,LWPOLYLINE"))))
    ) ;and

     ;; ======  then  =============
     (setq e (ssname ssex 0))
     ;; ======  else  =============
     (progn
       (sssetfirst)
       (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
       (while
         (or
           (not (setq e (car (entsel "\nSelect Starting line, pline or arc: "))))
           (not (member (cdr (assoc 0 (entget e))) typlst))
         )
          (princ "\nMissed pick or wrong object type: ")
       ) ;while
     ) ;progn
  ) ;if  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  ;;  Get the End object added by CAB
  (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
  (while
    (or
      (not (setq e2 (car (entsel "\nSelect Ending line, pline or arc: "))))
      (not (member (cdr (assoc 0 (entget e2))) typlst))
    )
     (princ "\nMissed pick or wrong object type: ")
  ) ;while

  (and
    (setq ok   1
          fuzz 1e-8 ; 0.00000001
    )
    (setq ent (entget e)) ; first or picked ent
    (setq ent2 (entget e2)) ; second picked ent, CAB
    (setq layer (cdr (assoc 8 ent))) ; layer to match
    (= layer (cdr (assoc 8 ent2))) ; layers match
    (setq ent    (get:elst ent)
          elist  '()
          start  (cadr ent)
          end    (caddr ent)
          ent2   (get:elst ent2); CAB
          start2 (cadr ent2)
          end2   (caddr ent2)
    )
    (setq ss ; get all objects that matched picked
           (ssget "X" (list '(0 . "LINE,ARC,LWPOLYLINE") (cons 8 layer)))
    )
    (ssdel e ss) ; remove picked start from selection set

    ;;  make a list of all from ss  ((ename startpt endpt) ....)
    (setq i 0)
    (repeat (sslength ss)
      (@list (ssname ss i))
      (setq i (1+ i))
    ) ;repeat
    ;;  CAB revised from here down
    ;;  find attached items, does not test all branches
    (@ckpoint start ent sslist)
    (if (not found)
      (@ckpoint end ent sslist)
    )
  ) ;and
  (if found
    (progn
      (setq elist (cons ent elist))
      (setq ssres (ssadd))
      (foreach x elist ; creat a selection set of the list
        (ssadd (car x) ssres)
      )
      (prompt "\n*-* Done *-*\n")
      (cadr(sssetfirst nil ssres)) ; display the selected items
    ); progn
    (prompt "\n*-* Path not found *-*")
  )
) ;end
;; -------------------------------

;;  @ckPoint by CAB
;;  check the list for matching points
;;  p point to match
;;  elst (ename startpt endpt) of pt
;;  |List list pf remaining elst
(defun @ckpoint( p elst |list / entx ex p1 p2 idx res)
  (setq idx (length |List))
  (while (and (not found) (>= (setq idx (1- idx)) 0))
    (setq entx (nth idx |List)
          ex  (car entx)
          p1  (cadr entx)
          p2  (caddr entx)
     )
    (cond ; test point match with fuzz factor
      ((equal p start2 fuzz) ; text for target
       (setq found 1)
       (setq elist (cons ent2 elist))
      )
      ((equal p end2 fuzz) ; text for target
       (setq found 1)
       (setq elist (cons ent2 elist))
      )
      ((equal p p1 fuzz) ; test for next branch
       (setq res (@ckpoint p2 entx (vl-remove entx |List)))
       (if found ; we are backing out collecting the path
        (setq elist (cons entx elist))
       )
      )
      ((equal p p2 fuzz) ; test for next branch
       (setq res (@ckpoint p1 entx (vl-remove entx |List)))
       (if found; we are backing out collecting the path
        (setq elist (cons entx elist))
       )
      )
    )
  ); while
  T ; return to satisfy AND
); defun

;;========================
;;   End Of File         
;;========================

As directed by the moderator CAB, I am attaching an example to make the point clearer.

Thank you all.

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Sum text on path
« Reply #1 on: January 29, 2014, 10:20:27 AM »
Here's a quick way to do it using a fence selection .. be aware that the text has to be visible for it to work. Welcome to TheSwamp :).


Code: [Select]
;;  ***************************************************************
;;   pline path finder.lsp
;;   Charles Alan Butler 07/08/2004
;;   Modified routine to find a path from picked start entity
;;   to picked end entity.
;;
;;   Returns the first path if it exist else nil, not the shortest path
;;   Selects & highlites the path also
;;  ***************************************************************


;shortcut
(defun c:plp () (c:plinepath))


;;;  ***************************************************************
;;;               Original Routine                                 
;;;
;;;  ;; based on Inline.lsp by John Uhden
;;;  ;; modified Joe Burke 5/15/03
;;;  ;; pick a line, arc or lwpline
;;;  ;; creates a selection set of objects which meet end to end
;;;  ;; only selects objects on the same layer as picked object
;;;  ;; pass selection set to pedit join...
;;;
;;;  ***************************************************************




;;===================================
;;      -=<  Sub Routines  >=-       
;;===================================


;;  Return (ename Startpt Endpt)
(defun @arc (ent / e rp r ba ea p1 p2)
  (setq e  (cdr (assoc -1 ent))
rp (cdr (assoc 10 ent))
r  (cdr (assoc 40 ent))
ba (cdr (assoc 50 ent))
ea (cdr (assoc 51 ent))
p1 (trans (polar rp ba r) e 0)
p2 (trans (polar rp ea r) e 0)
  )
  (list e p1 p2)
) ;end


;;  Return (ename Startpt Endpt)
(defun @line (ent) (list (cdr (assoc -1 ent)) (cdr (assoc 10 ent)) (cdr (assoc 11 ent)))) ;end


;;  Return (ename Startpt Endpt)
(defun @pline (ent / e) (setq e (cdr (assoc -1 ent))) (list e (car (getends e)) (cadr (getends e))))
;end


;;  Add ent-> (ename Startpt Endpt) to list
(defun @list (e / ent)
  (setq ent (entget e))
  (cond ((= (cdr (assoc 0 ent)) "LINE") (setq sslist (cons (@line ent) sslist)))
((= (cdr (assoc 0 ent)) "ARC") (setq sslist (cons (@arc ent) sslist)))
((= (cdr (assoc 0 ent)) "LWPOLYLINE") (setq sslist (cons (@pline ent) sslist)))
  )
) ;end


;;argument: an ename - returns: Start and End points as a list
(defun getends (vobj / name stpt endpt)
  (if (= (type vobj) 'ename)
    (setq vobj (vlax-ename->vla-object vobj))
  )
  (and (setq name (vla-get-objectname vobj))
       (cond ((vl-position
name
'("AcDbArc" "AcDbLine" "AcDbEllipse" "AcDbSpline" "AcDbPolyline" "AcDb2dPolyline"
  "AcDb3dPolyline")
      )
      (setq stpt (vlax-curve-getstartpoint vobj))
      (setq endpt (vlax-curve-getendpoint vobj))
     )
       ) ;cond
  ) ;and
  (list stpt endpt)
) ;end


;; get list of (ename startpt endpt) for picked ent
(defun get:elst (ent)
  (cond ((= (cdr (assoc 0 ent)) "ARC") (setq ent (@arc ent)))
((= (cdr (assoc 0 ent)) "LINE") (setq ent (@line ent)))
((= (cdr (assoc 0 ent)) "LWPOLYLINE") (setq ent (@pline ent)))
  )
  ent
) ; end defun




;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;          main function               
;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
(defun c:plinepath (/    sslist elist ss ssres  i      e      e2     found  ent   ent2
    ok    start  end start2 end2   fuzz   layer  ssex   typlst tmp   n
   )
  ;; Get the start object
  (if ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    (and (cadr (ssgetfirst)) ;objects are selected
;;at least one arc, line or pline
(setq ssex (ssget "i" (list (cons 0 "LINE,ARC,LWPOLYLINE"))))
    ) ;and
     ;; ======  then  =============
     (setq e (ssname ssex 0))
     ;; ======  else  =============
     (progn (sssetfirst)
    (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
    (while (or (not (setq e (car (entsel "\nSelect Starting line, pline or arc: "))))
       (not (member (cdr (assoc 0 (entget e))) typlst))
   )
      (princ "\nMissed pick or wrong object type: ")
    ) ;while
     ) ;progn
  ) ;if  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ;;  Get the End object added by CAB
  (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
  (while (or (not (setq e2 (car (entsel "\nSelect Ending line, pline or arc: "))))
     (not (member (cdr (assoc 0 (entget e2))) typlst))
)
    (princ "\nMissed pick or wrong object type: ")
  ) ;while
  (and (setq ok   1
     fuzz 1e-8 ; 0.00000001
       )
       (setq ent (entget e)) ; first or picked ent
       (setq ent2 (entget e2)) ; second picked ent, CAB
       (setq layer (cdr (assoc 8 ent))) ; layer to match
       (= layer (cdr (assoc 8 ent2))) ; layers match
       (setq ent    (get:elst ent)
     elist  '()
     start  (cadr ent)
     end    (caddr ent)
     ent2   (get:elst ent2) ; CAB
     start2 (cadr ent2)
     end2   (caddr ent2)
       )
       (setq ss ; get all objects that matched picked
      (ssget "X" (list '(0 . "LINE,ARC,LWPOLYLINE") (cons 8 layer)))
       )
       (ssdel e ss) ; remove picked start from selection set
       ;;  make a list of all from ss  ((ename startpt endpt) ....)
       (setq i 0)
       (repeat (sslength ss) (@list (ssname ss i)) (setq i (1+ i))) ;repeat
       ;;  CAB revised from here down
       ;;  find attached items, does not test all branches
       (@ckpoint start ent sslist)
       (if (not found)
(@ckpoint end ent sslist)
       )
  ) ;and
  (if found
    (progn (setq elist (cons ent elist))
   (setq ssres (ssadd))
   (foreach x elist ; create a selection set of the list
     (ssadd (car x) ssres)
   )
   ;; RJP added fence selection for text object
   (setq n 0)
   (foreach x elist ; create a selection set of the text **must be on screen**
     (if (setq ss (ssget "_F" (list (cadr x) (caddr x)) '((0 . "text"))))
       (progn (setq n (+ n (atof (cdr (assoc 1 (entget (ssname ss 0)))))))
      (ssadd (ssname ss 0) ssres)
       )
     )
   )
   (if (not (zerop n))
     (alert (vl-princ-to-string n))
   )
   (prompt "\n*-* Done *-*\n")
   (cadr (sssetfirst nil ssres)) ; display the selected items
    ) ; progn
    (prompt "\n*-* Path not found *-*")
  )
) ;end
;; -------------------------------




;;  @ckPoint by CAB
;;  check the list for matching points
;;  p point to match
;;  elst (ename startpt endpt) of pt
;;  |List list pf remaining elst
(defun @ckpoint (p elst |list / entx ex p1 p2 idx res)
  (setq idx (length |list))
  (while (and (not found) (>= (setq idx (1- idx)) 0))
    (setq entx (nth idx |list)
  ex   (car entx)
  p1   (cadr entx)
  p2   (caddr entx)
    )
    (cond ; test point match with fuzz factor
      ((equal p start2 fuzz) ; text for target
       (setq found 1)
       (setq elist (cons ent2 elist))
      )
      ((equal p end2 fuzz) ; text for target
       (setq found 1)
       (setq elist (cons ent2 elist))
      )
      ((equal p p1 fuzz) ; test for next branch
       (setq res (@ckpoint p2 entx (vl-remove entx |list)))
       (if found ; we are backing out collecting the path
(setq elist (cons entx elist))
       )
      )
      ((equal p p2 fuzz) ; test for next branch
       (setq res (@ckpoint p1 entx (vl-remove entx |list)))
       (if found ; we are backing out collecting the path
(setq elist (cons entx elist))
       )
      )
    )
  ) ; while
  t ; return to satisfy AND
) ; defun


;;========================
;;   End Of File         
;;========================

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Logan

  • Newt
  • Posts: 41
Re: Sum text on path
« Reply #2 on: January 29, 2014, 02:31:30 PM »
Hello Ron, thanks for the quick response.
 
Use the fence was a great idea. The end result was exactly what I expected but I am curious, is there any function or method that can reduce the chances of error?
 
Let me give you an example: suppose the user has the unfortunate idea of ​​using a polyline with rounded corners?

I know the design sample did not show this kind of possibility, but I'm curious if there is anything I can do that.

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Sum text on path
« Reply #3 on: January 29, 2014, 04:41:36 PM »
Logan,
Give this a try. The text will be found regardless of if it's on the screen or not :) .
Code - Auto/Visual Lisp: [Select]
  1. ;;  ***************************************************************
  2. ;;   pline path finder.lsp
  3. ;;   Charles Alan Butler 07/08/2004
  4. ;;   Modified routine to find a path from picked start entity
  5. ;;   to picked end entity.
  6. ;;
  7. ;;   Returns the first path if it exist else nil, not the shortest path
  8. ;;   Selects & highlites the path also
  9. ;;  ***************************************************************
  10.  
  11.  
  12.  
  13.  
  14.                ;shortcut
  15. (defun c:plp () (c:plinepath))
  16.  
  17.  
  18.  
  19.  
  20. ;;;  ***************************************************************
  21. ;;;               Original Routine                                  
  22. ;;;
  23. ;;;  ;; based on Inline.lsp by John Uhden
  24. ;;;  ;; modified Joe Burke 5/15/03
  25. ;;;  ;; pick a line, arc or lwpline
  26. ;;;  ;; creates a selection set of objects which meet end to end
  27. ;;;  ;; only selects objects on the same layer as picked object
  28. ;;;  ;; pass selection set to pedit join...
  29. ;;;
  30. ;;;  ***************************************************************
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. ;;===================================
  40. ;;      -=<  Sub Routines  >=-      
  41. ;;===================================
  42.  
  43.  
  44.  
  45.  
  46. ;;  Return (ename Startpt Endpt)
  47. (defun @arc (ent / e rp r ba ea p1 p2)
  48.   (setq   e  (cdr (assoc -1 ent))
  49.    rp (cdr (assoc 10 ent))
  50.    r  (cdr (assoc 40 ent))
  51.    ba (cdr (assoc 50 ent))
  52.    ea (cdr (assoc 51 ent))
  53.    p1 (trans (polar rp ba r) e 0)
  54.    p2 (trans (polar rp ea r) e 0)
  55.   )
  56.   (list e p1 p2)
  57. )               ;end
  58.  
  59.  
  60.  
  61.  
  62. ;;  Return (ename Startpt Endpt)
  63. (defun @line (ent) (list (cdr (assoc -1 ent)) (cdr (assoc 10 ent)) (cdr (assoc 11 ent)))) ;end
  64.  
  65.  
  66.  
  67.  
  68. ;;  Return (ename Startpt Endpt)
  69. (defun @pline (ent / e) (setq e (cdr (assoc -1 ent))) (list e (car (getends e)) (cadr (getends e))))
  70.                ;end
  71.  
  72.  
  73.  
  74.  
  75. ;;  Add ent-> (ename Startpt Endpt) to list
  76. (defun @list (e / ent)
  77.   (setq ent (entget e))
  78.   (cond   ((= (cdr (assoc 0 ent)) "LINE") (setq sslist (cons (@line ent) sslist)))
  79.    ((= (cdr (assoc 0 ent)) "ARC") (setq sslist (cons (@arc ent) sslist)))
  80.    ((= (cdr (assoc 0 ent)) "LWPOLYLINE") (setq sslist (cons (@pline ent) sslist)))
  81.   )
  82. )               ;end
  83.  
  84.  
  85.  
  86.  
  87. ;;argument: an ename - returns: Start and End points as a list
  88. (defun getends (vobj / name stpt endpt)
  89.   (if (= (type vobj) 'ename)
  90.     (setq vobj (vlax-ename->vla-object vobj))
  91.   )
  92.   (and (setq name (vla-get-objectname vobj))
  93.        (cond ((vl-position
  94.       name
  95.       '("AcDbArc" "AcDbLine" "AcDbEllipse" "AcDbSpline" "AcDbPolyline" "AcDb2dPolyline"
  96.         "AcDb3dPolyline")
  97.          )
  98.          (setq stpt (vlax-curve-getstartpoint vobj))
  99.          (setq endpt (vlax-curve-getendpoint vobj))
  100.         )
  101.        )            ;cond
  102.   )               ;and
  103.   (list stpt endpt)
  104. )               ;end
  105.  
  106.  
  107.  
  108.  
  109. ;; get list of (ename startpt endpt) for picked ent
  110. (defun get:elst   (ent)
  111.   (cond   ((= (cdr (assoc 0 ent)) "ARC") (setq ent (@arc ent)))
  112.    ((= (cdr (assoc 0 ent)) "LINE") (setq ent (@line ent)))
  113.    ((= (cdr (assoc 0 ent)) "LWPOLYLINE") (setq ent (@pline ent)))
  114.   )
  115.   ent
  116. )               ; end defun
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. ;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  126. ;;          main function              
  127. ;; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  128. (defun c:plinepath (/      _dxf     sslist elist   ss     ssres  i        e       e2      found  ent
  129.           ent2   ok     start    end   start2 end2   fuzz   layer  ssex   typlst tmp
  130.           n
  131.          )
  132.   (defun _dxf (code ename)
  133.     (if   (and ename (= (type ename) 'ename))
  134.       (cdr (assoc code (entget ename '("*"))))
  135.     )
  136.   )
  137.   ;; Get the start object
  138.   (if               ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  139.     (and (cadr (ssgetfirst))      ;objects are selected
  140.     ;;at least one arc, line or pline
  141.     (setq ssex (ssget "i" (list (cons 0 "LINE,ARC,LWPOLYLINE"))))
  142.     )               ;and
  143.      ;; ======  then  =============
  144.      (setq e (ssname ssex 0))
  145.      ;; ======  else  =============
  146.      (progn (sssetfirst)
  147.        (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
  148.        (while (or (not (setq e (car (entsel "\nSelect Starting line, pline or arc: "))))
  149.              (not (member (cdr (assoc 0 (entget e))) typlst))
  150.          )
  151.          (princ "\nMissed pick or wrong object type: ")
  152.        )            ;while
  153.      )               ;progn
  154.   )               ;if  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  155.   ;;  Get the End object added by CAB
  156.   (setq typlst '("LINE" "ARC" "LWPOLYLINE"))
  157.   (while (or (not (setq e2 (car (entsel "\nSelect Ending line, pline or arc: "))))
  158.         (not (member (cdr (assoc 0 (entget e2))) typlst))
  159.     )
  160.     (princ "\nMissed pick or wrong object type: ")
  161.   )               ;while
  162.   (and (setq ok     1
  163.         fuzz 1e-8         ; 0.00000001
  164.        )
  165.        (setq ent (entget e))      ; first or picked ent
  166.        (setq ent2 (entget e2))      ; second picked ent, CAB
  167.        (setq layer (cdr (assoc 8 ent)))   ; layer to match
  168.        (= layer (cdr (assoc 8 ent2)))   ; layers match
  169.        (setq ent    (get:elst ent)
  170.         elist  '()
  171.         start  (cadr ent)
  172.         end    (caddr ent)
  173.         ent2   (get:elst ent2)   ; CAB
  174.         start2 (cadr ent2)
  175.         end2   (caddr ent2)
  176.        )
  177.        (setq ss            ; get all objects that matched picked
  178.          (ssget "X" (list '(0 . "LINE,ARC,LWPOLYLINE") (cons 8 layer)))
  179.        )
  180.        (ssdel e ss)         ; remove picked start from selection set
  181.        ;;  make a list of all from ss  ((ename startpt endpt) ....)
  182.        (setq i 0)
  183.        (repeat (sslength ss) (@list (ssname ss i)) (setq i (1+ i))) ;repeat
  184.        ;;  CAB revised from here down
  185.        ;;  find attached items, does not test all branches
  186.        (@ckpoint start ent sslist)
  187.        (if (not found)
  188.     (@ckpoint end ent sslist)
  189.        )
  190.   )               ;and
  191.   (if found
  192.     (progn
  193.       (setq elist (cons ent elist))
  194.       ;; Grab all text in drawing
  195.       (setq ss (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "text"))))))
  196.       ;; Empty selection set to append
  197.       (setq ssres (ssadd))
  198.       ;; Counter to add text values to
  199.       (setq n 0)
  200.       (foreach x elist         ;; create a selection set of the list
  201.    (setq tmp
  202.           (vl-remove-if-not
  203.        '(lambda (txt)
  204.           ;; Text within distance of textheight to path entity
  205.           (<=   (distance (_dxf 10 txt) (vlax-curve-getclosestpointto (car x) (_dxf 10 txt)))
  206.          (_dxf 40 txt)
  207.           )
  208.         )
  209.        ss
  210.           )
  211.    )
  212.    ;; Add text to path selection set, sum text and remove from TEXT list (prevents getting summed twice)
  213.    (mapcar   '(lambda (txt) (ssadd txt ssres) (setq n (+ n (atof (_dxf 1 txt)))) (vl-remove txt ss))
  214.       tmp
  215.    )
  216.    (ssadd (car x) ssres)
  217.       )
  218. ;;;      ;; RJP added fence selection for text object
  219. ;;;      (setq n 0)
  220. ;;;      (foreach x elist      ; create a selection set of the text **must be on screen**
  221. ;;;        (if (setq ss (ssget "_F" (list (cadr x) (caddr x)) '((0 . "text"))))
  222. ;;;          (progn (setq n (+ n (atof (cdr (assoc 1 (entget (ssname ss 0)))))))
  223. ;;;            (ssadd (ssname ss 0) ssres)
  224. ;;;          )
  225. ;;;        )
  226. ;;;      )
  227.       (if (not (zerop n))
  228.       )
  229.       (prompt "\n*-* Done *-*\n")
  230.       (cadr (sssetfirst nil ssres))   ; display the selected items
  231.     )               ; progn
  232.     (prompt "\n*-* Path not found *-*")
  233.   )
  234. )               ;end
  235. ;; -------------------------------
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. ;;  @ckPoint by CAB
  245. ;;  check the list for matching points
  246. ;;  p point to match
  247. ;;  elst (ename startpt endpt) of pt
  248. ;;  |List list pf remaining elst
  249. (defun @ckpoint   (p elst |list / entx ex p1 p2 idx res)
  250.   (setq idx (length |list))
  251.   (while (and (not found) (>= (setq idx (1- idx)) 0))
  252.     (setq entx (nth idx |list)
  253.      ex   (car entx)
  254.      p1   (cadr entx)
  255.      p2   (caddr entx)
  256.     )
  257.     (cond            ; test point match with fuzz factor
  258.       ((equal p start2 fuzz)      ; text for target
  259.        (setq found 1)
  260.        (setq elist (cons ent2 elist))
  261.       )
  262.       ((equal p end2 fuzz)      ; text for target
  263.        (setq found 1)
  264.        (setq elist (cons ent2 elist))
  265.       )
  266.       ((equal p p1 fuzz)      ; test for next branch
  267.        (setq res (@ckpoint p2 entx (vl-remove entx |list)))
  268.        (if found         ; we are backing out collecting the path
  269.     (setq elist (cons entx elist))
  270.        )
  271.       )
  272.       ((equal p p2 fuzz)      ; test for next branch
  273.        (setq res (@ckpoint p1 entx (vl-remove entx |list)))
  274.        (if found         ; we are backing out collecting the path
  275.     (setq elist (cons entx elist))
  276.        )
  277.       )
  278.     )
  279.   )               ; while
  280.   t               ; return to satisfy AND
  281. )               ; defun
  282.  
  283.  
  284.  
  285.  
  286. ;;========================
  287. ;;   End Of File          
  288. ;;========================

edit:kdub-> code=cadlisp-7
« Last Edit: January 29, 2014, 04:53:35 PM by Kerry »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Logan

  • Newt
  • Posts: 41
Re: Sum text on path
« Reply #4 on: January 29, 2014, 05:08:54 PM »
Logan,
Give this a try. The text will be found regardless of if it's on the screen or not :) .


Sorry did not realize I was editing the post. I will test now.

Logan

  • Newt
  • Posts: 41
Re: Sum text on path
« Reply #5 on: January 29, 2014, 05:44:18 PM »
Logan,
Give this a try. The text will be found regardless of if it's on the screen or not :) .
edit:kdub-> code=cadlisp-7

Incredible works perfectly.

Tested in all visibility states and continued working. This is amazing.

This showed me that the "path" for me will be long.

I will analyze the code more carefully and try to get the objectsIDs selected to perform the sum and put in a fieldObject texts.

Thanks Ron for sharing your knowledge. :-D
You're the man.

Regards, Logan.

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Sum text on path
« Reply #6 on: January 29, 2014, 06:46:56 PM »
Glad to help out. Let me know if you have any questions.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC