TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pedroantonio on April 07, 2014, 04:50:06 AM

Title: line or polyline distance
Post by: pedroantonio on April 07, 2014, 04:50:06 AM
Hi, I try to write a lisp when i selected a line or polyline then  write the length on top of the line or polyline.

Can anyone help me to finish it. Thanks

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ e p ht scl)
  2.     "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" ""
  3.    )
  4.   (SETQ SCL (GETVAR "useri1"))
  5.   (SETQ HT (* 0.00175 SCL))
  6.   (COMMAND "style" "diast" "wgsimpl.shx" "" "" "" "" "")
  7.   (if (and (setq e (entsel "\n select line or polyline :"))
  8.            (member (cdr (assoc 0 (entget (car e))))
  9.                    '("LINE" "LWPOLYLINE" "POLYLINE")
  10.            )
  11.       )
  12.     (progn
  13.       (entmakex (list '(0 . "TEXT")
  14.                       '(100 . "AcDbEntity")
  15.                       '(100 . "AcDbText")
  16.                       (cons 40 HT)
  17.                       (cons 10 (trans p 1 0))
  18.                       (cons 1
  19.                             (strcat (rtos (car p) 2)
  20.                                     (rtos (cadr p) 2)
  21.                                     (rtos (caddr p) 2)
  22.                             )
  23.                       )
  24.                       (cons 50 1.5708)
  25.                 )
  26.       )
  27.     )
  28.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again....")
  29.   )
  30.  
  31.   (princ)
  32. )
Title: Re: line or polyline distance
Post by: irneb on April 07, 2014, 05:38:58 AM
First the vlax-curve-getPointAtDist is probably not what you're after. You might rather want the vlax-curve-getDistAtParam and vlax-curve-getEndParam.

Next all those vlax-curve-* functions require at least one argument: the object's ename or vla reference (can be used interchangeably). I.e. the car of e. Some might require an extra argument, like the getPointAtDist would require a distance along the curve so it can return the point, or the getDistAtParam requires the param (vector index) along the curve so it can return the distance. In the last scenario you get the end of the curve from getEndParam which is then passed as the 2nd argument to getDistAtParam so you get the curve's total length.

Finally, you can then place the text using the vlax-curve-getPointAtDist (e.g. middle of curve by dividing the distance by 2). You might also want to rotate the text to follow the curve using vlax-curve-getFirstDeriv (this gives a 3d point in the direction following the curve, so you can use angle from a (0 0 0) point to convert it to radians.
Title: Re: line or polyline distance
Post by: pedroantonio on April 07, 2014, 09:01:13 AM
Hi irneb, you confused me . I can not understand you .Can you fix the code?

Thanks
Title: Re: line or polyline distance
Post by: irneb on April 07, 2014, 09:15:27 AM
I'd rather show you how to do it yourself:
Title: Re: line or polyline distance
Post by: pedroantonio on April 07, 2014, 01:21:30 PM
 I try to write a lisp
1) select a line or polyline
2) write the length on top of the line or polyline.
I am not good in lisp. I know that you can find a lot of mistakes in the code. I am trying to learn some things. Can you helm me ?

But i want the code to have

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ e p ht scl)
  2.     "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" ""
  3.    )
  4.   (SETQ SCL (GETVAR "useri1"))
  5.   (SETQ HT (* 0.00175 SCL))
  6.   (COMMAND "style" "diast" "wgsimpl.shx" "" "" "" "" "")
  7.   (if (and (setq e (entsel "\n select line or polyline :"))
  8.            (member (cdr (assoc 0 (entget (car e))))
  9.                    '("LINE" "LWPOLYLINE" "POLYLINE")
  10.            )
  11.      )
  12.     ------------------------------------------
  13. ------------------------------------------
  14. ----------------------------------------------
  15. ---------------------------------------------------
  16.   (princ)
  17. )
Title: Re: line or polyline distance
Post by: irneb on April 08, 2014, 04:30:17 AM
Fine
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  3.   (SETQ scl (GETVAR "useri1"))
  4.   (SETQ ht (* 0.00175 SCL))
  5.   (COMMAND "style" "diast" "romans.shx")
  6.   (while (> (getvar "CmdActive") 0) (command ""))
  7.   (if (and (setq e (entsel "\n select line or polyline :"))
  8.            (setq e (car e))
  9.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  10.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  11.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  12.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at midpoint
  13.            (entmakex (list '(0 . "TEXT")
  14.                            '(100 . "AcDbEntity")
  15.                            '(100 . "AcDbText")
  16.                            (cons 40 ht)
  17.                            '(7 . "diast") ;Text style
  18.                            (cons 10 pt) ;The insert point of the text
  19.                            (cons 1 (rtos len 2)) ;The length converted to text
  20.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  21.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  22.   (princ))
Title: Re: line or polyline distance
Post by: pedroantonio on April 09, 2014, 10:40:08 AM
Thank you irneb for the code.

I want the dimension text be 0.08m over the line .How can i do it ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  3.   (SETQ scl (GETVAR "useri1"))
  4.   (SETQ ht (* 0.00175 SCL))
  5.   (COMMAND "style" "diast" "romans.shx")
  6.   (while (> (getvar "CmdActive") 0) (command ""))
  7.   (if (and (setq e (entsel "\n select line or polyline :"))
  8.            (setq e (car e))
  9.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  10.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  11.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  12.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at midpoint
  13.            (entmakex (list '(0 . "TEXT")
  14.                            '(100 . "AcDbEntity")
  15.                            '(100 . "AcDbText")
  16.                            (cons 40 ht)
  17.                            '(7 . "diast") ;Text style
  18.                            (cons 71 1)
  19.                            (cons 10 pt) ;The insert point of the text
  20.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  21.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  22.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  23.   (princ))
Title: Re: line or polyline distance
Post by: ronjonp on April 09, 2014, 10:58:58 AM
Look into the POLAR function. See if you can figure out where to plug this in.


Code: [Select]
(polar pt (+ (/ pi 2) ang) 0.08)
Title: Re: line or polyline distance
Post by: pedroantonio on April 09, 2014, 11:09:56 AM
Hi  ronjonp, I don't know how to use it this

Code: [Select]
(polar pt (+ (/ pi 2) ang) 0.08)
Can you be more specific?

Thanks
Title: Re: line or polyline distance
Post by: ronjonp on April 09, 2014, 11:16:25 AM
Hi  ronjonp, I don't know how to use it this

Code: [Select]
(polar pt (+ (/ pi 2) ang) 0.08)
Can you be more specific?

Thanks


Really?  :?  .. Irneb commented the code he wrote for you .. I'm sure you can figure it out.
Title: Re: line or polyline distance
Post by: pedroantonio on April 09, 2014, 01:52:57 PM
I try to align the textin the midle center and I want the dimension text be 0.08m over the line . Can anyone help?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2. (setvar "cmdecho" 0)
  3. (setq flg 1)
  4. (setvar "cmdecho" 0)
  5.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  6.   (SETQ scl (GETVAR "useri1"))
  7.   (SETQ ht (* 0.00175 SCL))
  8.   (COMMAND "style" "diast" "romans.shx")
  9.   (while (> (getvar "CmdActive") 0) (command ""))
  10.   (if (and (setq e (entsel "\n select line or polyline :"))
  11.            (setq e (car e))
  12.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  13.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  14.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  15.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at midpoint
  16.            (entmakex (list '(0 . "TEXT")
  17.                            '(100 . "AcDbEntity")
  18.                            '(100 . "AcDbText")
  19.                            (cons 40 ht)
  20.                            '(7 . "diast") ;Text style
  21.                            '(72 . 1) ;; Center
  22.                            '(73 . 2) ;; Middle
  23.                            (cons 71 1) ; Text generation flags
  24.                            (cons 10 pt) ;The insert point of the text
  25.                            (cons 11 pt) ;The insert point of the text
  26.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  27.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  28.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  29.   (princ))
  30.  
Title: Re: line or polyline distance
Post by: irneb on April 09, 2014, 02:57:22 PM
I try to align the textin the midle center and I want the dimension text be 0.08m over the line . Can anyone help?
Ronjon's code will return a "moved" point (i.e. the XYZ value) from the one saved in the variable pt by moving it 0.08 units perpendicular to the angle saved in the variable ang.

Then as noted:
Irneb commented the code he wrote for you ... I'm sure you can figure it out.
Look for where I commented "The insertion point of the text" and replace the pt with either that code or another variable you've set to the return value of that code.

Please, I'd beg you to at least try and modify the code yourself instead of simply asking for someone to do it for you. Believe me, you'll be a lot better off if you can modify these things for yourself. Don't worry about making mistakes ... be glad of mistakes because they are the true teachers.
Title: Re: line or polyline distance
Post by: pedroantonio on April 09, 2014, 03:08:42 PM
Ok irneb ,thank you for the reply. I understand the part the 0.08 m ,but what about the midle center of the text ???
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2. (setvar "cmdecho" 0)
  3. (setq flg 1)
  4. (setvar "cmdecho" 0)
  5.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  6.   (SETQ scl (GETVAR "useri1"))
  7.   (SETQ ht (* 0.00175 SCL))
  8.   (COMMAND "style" "diast" "romans.shx")
  9.   (while (> (getvar "CmdActive") 0) (command ""))
  10.   (if (and (setq e (entsel "\n select line or polyline :"))
  11.            (setq e (car e))
  12.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  13.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  14.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  15.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at
  16.  
  17. midpoint
  18.            (entmakex (list '(0 . "TEXT")
  19.                            '(100 . "AcDbEntity")
  20.                            '(100 . "AcDbText")
  21.                            (cons 40 ht)
  22.                           '(7 . "diast") ;Text style
  23.                             (cons 71 1) ; Text generation flags
  24.                            (cons 10 (polar pt (+ (/ pi 2) ang) 0.08)) ;The insert point of the text
  25.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  26.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  27.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  28.   (princ))
  29.  

Thanks
Title: Re: line or polyline distance
Post by: roy_043 on April 09, 2014, 03:24:45 PM
... but what about the midle center of the text
If you compare an entity list from a left aligned text with that of a middle center aligned text you will find the group code items that need to be added to, or changed in, the entmakex list.
Title: Re: line or polyline distance
Post by: pedroantonio on April 09, 2014, 05:50:36 PM
I can't find the error .please help

I add this two lines for Middle Center Justification
               
Code: [Select]
(cons 72  1) ;Horizontal text justification type
(cons 73  2) ;Vertical text justification type

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2. (setvar "cmdecho" 0)
  3. (setq flg 1)
  4. (setvar "cmdecho" 0)
  5.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  6.   (SETQ scl (GETVAR "useri1"))
  7.   (SETQ ht (* 0.00175 SCL))
  8.   (SETQ kl (* 0.0004 SCL))
  9.   (COMMAND "style" "diast" "romans.shx")
  10.   (while (> (getvar "CmdActive") 0) (command ""))
  11.   (if (and (setq e (entsel "\n \n Επιλέξτε μια line ή polyline :"))
  12.            (setq e (car e))
  13.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  14.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  15.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  16.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at
  17.  
  18. midpoint
  19.            (entmakex (list '(0 . "TEXT")
  20.                            '(100 . "AcDbEntity")
  21.                            '(100 . "AcDbText")
  22.                            (cons 40 ht)
  23.                            '(7 . "diast") ;Text style
  24.                            (cons 71 1) ; Text generation flags
  25.                            (cons 72  1) ;Horizontal text justification type
  26.                            (cons 73  2) ;Vertical text justification type
  27.                            (cons 10 (polar pt (+ (/ pi 2) ang) kl)) ;The insert point of the text
  28.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  29.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  30.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  31.   (princ))
  32.  
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 03:19:31 AM
I try some combinations of this but i can't find the error

Code: [Select]

71

Text generation flags (optional, default = 0):
2 = Text is backward (mirrored in X).
4 = Text is upside down (mirrored in Y).

72

Horizontal text justification type (optional, default = 0) integer codes (not bit-coded)
0 = Left; 1= Center; 2 = Right
3 = Aligned (if vertical alignment = 0)
4 = Middle (if vertical alignment = 0)
5 = Fit (if vertical alignment = 0)
See the Group 72 and 73 integer codes table for clarification.

73

Vertical text justification type (optional, default = 0): integer codes (not bit- coded):
0 = Baseline; 1 = Bottom; 2 = Middle; 3 = Top
See the Group 72 and 73 integer codes table for clarification.

I want the text to be center not left

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2. (setvar "cmdecho" 0)
  3.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  4.   (SETQ scl (GETVAR "useri1"))
  5.   (SETQ ht (* 0.00175 SCL))
  6.   (SETQ kl (* 0.0004 SCL))
  7.   (COMMAND "style" "diast" "romans.shx")
  8.   (while (> (getvar "CmdActive") 0) (command ""))
  9.   (if (and (setq e (entsel "\n select line or polyline :"))
  10.            (setq e (car e))
  11.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  12.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to
  13.  
  14. its end
  15.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  16.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get
  17.  
  18. angle at
  19.  
  20. midpoint
  21.            (entmakex (list '(0 . "TEXT")
  22.                            '(100 . "AcDbEntity")
  23.                            '(100 . "AcDbText")
  24.                            (cons 40 ht)
  25.                            '(7 . "diast") ;Text style
  26.                            (cons 71 0) ; Text generation flags (optional, default = 0)
  27.                            (cons 72 1) ; Horizontal text justification type 1= Cente
  28.                            (cons 73 0) ; Vertical text justification type (optional, default = 0))
  29.                            (cons 10 (polar pt (+ (/ pi 2) ang) kl)) ;The insert point of the text
  30.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  31.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  32.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  33.   (princ))

Thanks
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 03:53:40 AM
You should compare more carefully. There are 4 differences not 2.

Left aligned text:
Code: [Select]
(
  (-1 . <Entity name: cb2deb0>)
  (0 . "TEXT")
  (5 . "AC")
  (330 . <Entity name: caeb090>)
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "0")
  (100 . "AcDbText")
  (10 819.719 207.205 0.0)
  (40 . 100.0)
  (1 . "aaa")
  (50 . 0.0)
  (41 . 1.0)
  (51 . 0.0)
  (7 . "Standard")
  (71 . 0)
  (72 . 0)
  (11 0.0 0.0 0.0)
  (210 0.0 0.0 1.0)
  (100 . "AcDbText")
  (73 . 0)
)

Middle center aligned text:
Code: [Select]
(
  (-1 . <Entity name: cbe0e38>)
  (0 . "TEXT")
  (5 . "AD")
  (330 . <Entity name: caeb090>)
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "0")
  (100 . "AcDbText")
  (10 703.319 157.205 0.0)  ; <-- First alignment point. Not the insertion point.
  (40 . 100.0)
  (1 . "aaa")
  (50 . 0.0)
  (41 . 1.0)
  (51 . 0.0)
  (7 . "Standard")
  (71 . 0)
  (72 . 1)                  ; <--
  (11 819.719 207.205 0.0)  ; <-- Second alignment point. Insertion point.
  (210 0.0 0.0 1.0)
  (100 . "AcDbText")
  (73 . 2)                  ; <--
)

For the first alignment point of a middle center aligned text you can use a dummy point for the entmake(x) list. But gc 10 must be present. At least on BricsCAD this applies.
Title: Re: line or polyline distance
Post by: irneb on April 10, 2014, 04:08:48 AM
For the first alignment point of a middle center aligned text you can use a dummy point for the entmake(x) list. But gc 10 must be present. At least on BricsCAD this applies.
Yep, I can confirm on AutoCAD 2014 it also works. E.g.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2.   (setvar "cmdecho" 0)
  3.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  4.   (SETQ scl (GETVAR "useri1"))
  5.   (SETQ ht (* 0.00175 SCL))
  6.   (SETQ kl (* 0.0004 SCL))
  7.   (COMMAND "style" "diast" "romans.shx")
  8.   (while (> (getvar "CmdActive") 0) (command ""))
  9.   (if (and (setq e (entsel "\n select line or polyline :"))
  10.            (setq e (car e))
  11.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  12.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  13.                  pt  (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  14.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at midpoint
  15.            (entmakex (list '(0 . "TEXT")
  16.                            '(100 . "AcDbEntity")
  17.                            '(100 . "AcDbText")
  18.                            (cons 40 ht)
  19.                            '(7 . "diast") ;Text style
  20.                            '(72 . 1) ; Horizontal text justification type 1= Center
  21.                            '(10 0.0 0.0 0.0) ;The base insert point of the text (ignored when not left aligned)
  22.                            (cons 11 (polar pt (+ (/ pi 2) ang) kl)) ;The insert point of the text when not left aligned
  23.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  24.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  25.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  26.   (princ))
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 04:19:42 AM
Thanks !! :-D
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 04:40:48 AM
I want to ask for something else. Look the direction of the lines in the attach file and the comments
thanks
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 04:52:01 AM
Code: [Select]
(setq ang (rem ang (* pi 0.5)))Edit: This does not work properly... See #23.
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 04:58:48 AM
I add this two lines for Middle Center Justification
Note: In the drawing the texts are center aligned. Not middle center aligned.
Title: Re: line or polyline distance
Post by: HasanCAD on April 10, 2014, 05:17:33 AM
Is it easy to convert this text to be annotative?
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 05:27:44 AM
Code: [Select]
(defun readableAngle (ang)
  (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  (if (< (* pi 0.5) ang (* pi 1.5))
    (+ ang pi)
    ang
  )
)
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 06:20:12 AM
roy_43 You are talking something about this !!! Is not working ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2. (setvar "cmdecho" 0)
  3.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  4.   (SETQ scl (GETVAR "useri1"))
  5.   (SETQ ht (* 0.00175 SCL))
  6.   (SETQ kl (* 0.0004 SCL))
  7.   (COMMAND "style" "diast" "romans.shx")
  8.   (while (> (getvar "CmdActive") 0) (command ""))
  9.   (if (and (setq e (entsel "\n select line or polyline :"))
  10.            (setq e (car e))
  11.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  12.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  13.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  14.                  ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))) ;Get angle at midpoint
  15.  (if (< (* pi 0.5) ang (* pi 1.5))
  16.     (+ ang pi)
  17.     ang
  18.   )
  19.            (entmakex (list '(0 . "TEXT")
  20.                            '(100 . "AcDbEntity")
  21.                            '(100 . "AcDbText")
  22.                            (cons 40 ht)
  23.                            '(7 . "diast") ;Text style
  24.                            (cons 71 0) ; Text generation flags (optional, default = 0)
  25.                            (cons 72 1) ; Horizontal text justification type 1= Cente
  26.                            (cons 73 0) ; Vertical text justification type (optional, default = 0))
  27.                            (cons 10 (polar pt (+ (/ pi 2) ang) kl)) ;The insert point of the text
  28.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  29.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  30.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  31.   (princ))
Title: Re: line or polyline distance
Post by: ChrisCarlson on April 10, 2014, 07:55:25 AM
Is it easy to convert this text to be annotative?

I borrowed this from lee-mac I beleive.

Code: [Select]
(entmake
                (list
                    (cons 0 "ENDBLK")
                    (cons 8 "0")
                )
            )
            (
                (lambda ( lst )
                    (regapp "ACAD")
                    (regapp "AcadAnnotative")
                    (entmod
                        (append (subst (cons 70 1) (assoc 70 lst) lst)
                            (list
                               (list -3
                                   (list "ACAD"
                                       (cons 1000 "DesignCenter Data")
                                       (cons 1002 "{")
                                       (cons 1070 1)
                                       (cons 1070 1)
                                       (cons 1002 "}")
                                   )
                                   (list "AcadAnnotative"
                                       (cons 1000 "AnnotativeData")
                                       (cons 1002 "{")
                                       (cons 1070 1)
                                       (cons 1070 1)
                                       (cons 1002 "}")
                                   )
                               )
                           )
                        )
                    )
                )
                (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" partnumber)))))
           )
                  (vl-load-com)
          (setq BLOCKS
          (vla-get-Blocks
           (vla-get-activedocument
            (vlax-get-acad-object)
           )
          )
         BLK (vla-Item BLOCKS partnumber)
       )
      (vla-put-explodable (vla-Item BLOCKS partnumber) :vlax-false) 
 

This makes the text of my block annotative and non-explodable
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 08:07:30 AM
@ HasanCAD: This is off topic. Can you start a new topic please.
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 08:21:12 AM
roy_43 You are talking something about this !!! Is not working ?

Try:
Code: [Select]
(defun readableAngle (ang)
  (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  (if (< (* pi 0.5) ang (* pi 1.5))
    (+ ang pi)
    ang
  )
)

(defun c:test  (/ e p ht scl len pt ang)
  ...
  ...
  (setq ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at midpoint
  (setq ang (readableAngle ang))
  ...
  ...
)

If you are really serious about learning Lisp you should choose a different approach. You have obvious trouble with some of the basic concepts of Lisp. Although the code in your first post suggests otherwise, at times you seem to be just copy/pasting without understanding what you are doing. Maybe http://www.afralisp.net/index.php is a good starting point for you.
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 09:52:00 AM
roy_043 Thank you but this is not what i want.

If you see the attach file

1) when the direction  is from left to right  (the red arrow )--> the text is over the line
2) when the direction  is from  right to left (the green arrow)--> the text is under the line

Now in this  two  options the text is over the line. I want this to wark with all angles in grad.

Thanks
Title: Re: line or polyline distance
Post by: mailmaverick on April 10, 2014, 01:15:27 PM
Try this :-

Code: [Select]

(defun c:test (/ e p ht scl len pt ang)
  (vl-load-com)
  (setvar "cmdecho" 0)
  (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  (SETQ scl (GETVAR "useri1"))
  (SETQ ht (* 0.00175 SCL))
  (SETQ kl (* 0.0004 SCL))
  (COMMAND "style" "diast" "romans.shx")
  (while (> (getvar "CmdActive") 0) (command ""))
  (if (and (setq e (entsel "\n select line or polyline :"))
   (setq e (car e))
   (member (cdr (assoc 0 (entget e)))
   '("LINE" "LWPOLYLINE" "POLYLINE")
   )
      )
    (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))
;Get the length of the line/pline to its end
pt  (vlax-curve-getPointAtDist e (/ len 2.0))
;Get the point at mid of line/pline
ang (angle '(0.0 0.0 0.0)
    (vlax-curve-getFirstDeriv
      e
      (vlax-curve-getParamAtPoint e pt)
    )
     )
   )
   (setq txtent
  (entmakex (list '(0 . "TEXT")
  '(100 . "AcDbEntity")
  '(100 . "AcDbText")
  (cons 40 ht)
  '(7 . "diast")
  '(72 . 1)
  '(10 0.0 0.0 0.0)
  (if (> ang pi)
    (cons 11 (polar pt (- (/ pi 2) ang) kl))
    (cons 11 (polar pt (+ (/ pi 2) ang) kl))
  )
  (cons 1 (rtos len 2 2))
  (cons 50 (readableAngle ang))
    )
  )
   )
   (setq txtobj (vlax-ename->vla-object txtent))
   (if (> ang pi)
     (vla-put-alignment txtobj acAlignmentTopCenter)
     (vla-put-alignment txtobj acAlignmentBottomCenter)
   )
    )
    (princ
      "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."
    )
  )
  (princ)
)

(defun readableAngle (ang)
  (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  (if (< (* pi 0.5) ang (* pi 1.5))
    (+ ang pi)
    ang
  )
)

Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 01:27:16 PM
Thank you mailmaverick but the problem still exist.Look the attach
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 02:44:36 PM
roy_043 Thank you but this is not what i want.

If you see the attach file

1) when the direction  is from left to right  (the red arrow )--> the text is over the line
2) when the direction  is from  right to left (the green arrow)--> the text is under the line

Now in this  two  options the text is over the line. I want this to wark with all angles in grad.

Thanks
I have never told you where exactly to change the ang value using the readableAngle function. If you think of the overall program flow it is easy to see where you should use (readableAngle ang) to get what you want. Let's call it a -={Challenge}=-. :-)
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 03:00:44 PM
Another -={Challenge}=-: Your function switches the current layer. It is more elegant to restore the previous CLAYER when the function finishes. Plenty of examples of how to do that on this forum.
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 03:10:12 PM
Thank you all . Now it work perfect
Title: Re: line or polyline distance
Post by: mailmaverick on April 10, 2014, 03:15:26 PM
Kindly post your final code.
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 03:29:57 PM
I use mailmaverick your code and i change
Code - Auto/Visual Lisp: [Select]
  1.     (vla-put-alignment txtobj acAlignmentBottomCenter)
  2. with
  3.    (vla-put-alignment txtobj acAlignmentCenter)
  4.  

But when the dimension is under the line the dimension text is not exactly in the center

Code - Auto/Visual Lisp: [Select]
  1. (defun readableAngle (ang)
  2.   (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  3.   (if (< (* pi 0.5) ang (* pi 1.5))
  4.     (+ ang pi)
  5.     ang
  6.   )
  7. )
  8. (defun c:test (/ e p ht scl len pt ang)
  9.   (setvar "cmdecho" 0)
  10.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  11.   (SETQ scl (GETVAR "useri1"))
  12.   (SETQ ht (* 0.00175 SCL))
  13.   (SETQ kl (* 0.0004 SCL))
  14.   (COMMAND "style" "diast" "romans.shx")
  15.   (while (> (getvar "CmdActive") 0) (command ""))
  16.   (if (and (setq e (entsel "\n select line or polyline :"))
  17.            (setq e (car e))
  18.            (member (cdr (assoc 0 (entget e)))
  19.                    '("LINE" "LWPOLYLINE" "POLYLINE")
  20.            )
  21.       )
  22.                                         ;Get the length of the line/pline to its end
  23.                  pt  (vlax-curve-getPointAtDist e (/ len 2.0))
  24.                                         ;Get the point at mid of line/pline
  25.                  ang (angle '(0.0 0.0 0.0)
  26.                             (vlax-curve-getFirstDeriv
  27.                               e
  28.                               (vlax-curve-getParamAtPoint e pt)
  29.                             )
  30.                      )
  31.            )
  32.            (setq txtent
  33.                   (entmakex (list '(0 . "TEXT")
  34.                                   '(100 . "AcDbEntity")
  35.                                   '(100 . "AcDbText")
  36.                                   (cons 40 ht)
  37.                                   '(7 . "diast")
  38.                                   '(72 . 1)
  39.                                   '(10 0.0 0.0 0.0)
  40.                                   (if (> ang pi)
  41.                                     (cons 11 (polar pt (- (/ pi 2) ang) kl))
  42.                                     (cons 11 (polar pt (+ (/ pi 2) ang) kl))
  43.                                   )
  44.                                   (cons 1 (rtos len 2 2))
  45.                                   (cons 50 (readableAngle ang))
  46.                             )
  47.                   )
  48.            )
  49.            (setq txtobj (vlax-ename->vla-object txtent))
  50.            (if (> ang pi)
  51.              (vla-put-alignment txtobj acAlignmentTopCenter)
  52.              (vla-put-alignment txtobj acAlignmentCenter)
  53.            )
  54.     )
  55.     (princ
  56.       "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."
  57.     )
  58.   )
  59.   (princ)
  60. )
  61.  

Thanks
Title: Re: line or polyline distance
Post by: roy_043 on April 10, 2014, 04:02:53 PM
Why not this:
Code - Auto/Visual Lisp: [Select]
  1. (defun readableAngle (ang)
  2.   (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  3.   (if (< (* pi 0.5) ang (* pi 1.5))
  4.     (+ ang pi)
  5.     ang
  6.   )
  7. )
  8.  
  9. (defun c:test  (/ e p ht scl len pt ang)
  10.   (setvar "cmdecho" 0)
  11.   (command "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  12.   (setq scl (getvar "useri1"))
  13.   (setq ht (* 0.00175 scl))
  14.   (setq kl (* 0.001275 scl)) ; Changed to account for text height.
  15.   (command "style" "diast" "romans.shx")
  16.   (while (> (getvar "cmdactive") 0) (command ""))
  17.   (if
  18.     (and
  19.       (setq e (entsel "\n select line or polyline :"))
  20.       (setq e (car e))
  21.       (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  22.     )
  23.     (progn
  24.       (setq len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) ; Get the length of the line/pline to its end.
  25.       (setq pt (vlax-curve-getpointatdist e (/ len 2.0))) ; Get the point at mid of line/pline.
  26.       (setq ang (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e pt)))) ; Get angle at midpoint.
  27.       (entmakex
  28.         (list
  29.           '(0 . "TEXT")
  30.           '(100 . "AcDbEntity")
  31.           '(100 . "AcDbText")
  32.           '(10 0.0 0.0 0.0) ; The base insert point of the text (ignored when not left aligned).
  33.           (cons 40 ht)          
  34.           (cons 1 (rtos len 2 2)) ; The length converted to text.
  35.           (cons 50 (readableAngle ang)) ; Rotate the text to follow the line/pline.
  36.           '(7 . "diast") ; Text style.
  37.           '(71 . 0)
  38.           '(72 . 1)
  39.           (cons 11 (polar pt (+ (/ pi 2) ang) kl)) ; The insert point of the text when not left aligned.
  40.           '(73 . 2)
  41.         )
  42.       )
  43.     )
  44.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again....")
  45.   )
  46.   (princ)
  47. )

Finally, to quote a more patient forum member, Pedro you really need to -> Study <- (http://www.theswamp.org/index.php?topic=46616.msg517285#msg517285).
Title: Re: line or polyline distance
Post by: pedroantonio on April 10, 2014, 04:37:43 PM
roy_043 you are playing with the text style now .I ask for center ,not midle center or top center or bottom center . It is easy to play with the text styles but i am searching for something specific .
Title: Re: line or polyline distance
Post by: roy_043 on April 11, 2014, 03:51:34 AM
I add this two lines for Middle Center Justification
roy_043 you are playing with the text style now .I ask for center ,not midle center or top center or bottom center . It is easy to play with the text styles but i am searching for something specific .
?
Title: Re: line or polyline distance
Post by: pedroantonio on April 11, 2014, 04:09:07 AM
Quote
I want the text to be center not left

you are not reading all the post.look at page2
Title: Re: line or polyline distance
Post by: Kerry on April 11, 2014, 05:06:49 AM
Quote
I want the text to be center not left

you are not reading all the post.look at page2

Just a note:

The First page is only page 2 if you have your profile set to show the latest post first and you happen to be on what is actually the second page.
Sometimes the details change with your perspective.

If you say  "look below for details" some of us will look above because our profile is configured to show the first post first and the last post last.

I hope you have as much fun reading that as I had composing it.



added:
And if you happen to have your profile set to display 50 posts per page  then page 2 doesn't exist yet.
Sort of mind bending ...
Title: Re: line or polyline distance
Post by: ChrisCarlson on April 11, 2014, 08:03:38 AM
If you want someone just to write your code a few members here provide this service for a nominal fee.

Code: [Select]
pt  (vlax-curve-getPointAtDist e (/ len 2.0))
;Get the point at mid of line/pline

This line finds the mid point of your line. however iirc vertexes will throw this "mid point" off
Title: Re: line or polyline distance
Post by: pedroantonio on May 09, 2014, 10:40:39 AM
hi ,I have a little problem with this lisp.Is not working in all angles .Look the red lines in the attach file with layer name Error (Red color) and you will understand

Code - Auto/Visual Lisp: [Select]
  1. (defun readableAngle (ang)
  2.   (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  3.   (if (< (* pi 0.5) ang (* pi 1.5))
  4.     (+ ang pi)
  5.     ang
  6.   )
  7. )
  8.  
  9. (defun c:linedim (/ e p ht scl len pt ang)
  10.   (setvar "cmdecho" 0)
  11.   (command "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  12.   (setq scl (getvar "useri1"))
  13.   (setq ht (* 0.00175 scl))
  14.   (setq kl (* 0.001275 scl)) ; Changed to account for text height.
  15.   (command "style" "diast" "wgsimpl.shx")
  16.   (while (> (getvar "cmdactive") 0) (command ""))
  17.   (if
  18.     (and
  19.       (setq e (entsel "\n select line or polyline :"))
  20.       (setq e (car e))
  21.       (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  22.     )
  23.     (progn
  24.       (setq len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) ; Get the length of the line/pline to its end.
  25.       (setq pt (vlax-curve-getpointatdist e (/ len 2.0))) ; Get the point at mid of line/pline.
  26.       (setq ang (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e pt)))) ; Get angle at midpoint.
  27.       (entmakex
  28.         (list
  29.           '(0 . "TEXT")
  30.           '(100 . "AcDbEntity")
  31.           '(100 . "AcDbText")
  32.           '(10 0.0 0.0 0.0) ; The base insert point of the text (ignored when not left aligned).
  33.           (cons 40 ht)          
  34.           (cons 1 (rtos len 2 2)) ; The length converted to text.
  35.           (cons 50 (readableAngle ang)) ; Rotate the text to follow the line/pline.
  36.           '(7 . "diast") ; Text style.
  37.           '(71 . 0)
  38.           '(72 . 1)
  39.           (cons 11 (polar pt (+ (/ pi 2) ang) kl)) ; The insert point of the text when not left aligned.
  40.           '(73 . 2)
  41.         )
  42.       )
  43.     )
  44.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again....")
  45.   )
  46.   (princ)
  47. )
  48.  
  49.  

Thanks
Title: Re: line or polyline distance
Post by: MORITZK on May 09, 2014, 02:32:21 PM
Hi Topographer,

(cons 11 (polar pt (+ (/ pi 2) ang) kl)) ;
your insertpoint is always left of the line. You must check the line direction!
Moritz
Title: Re: line or polyline distance
Post by: pedroantonio on May 09, 2014, 02:40:04 PM
Hi Moritzk. Is it possible

1) when the direction  is from left to right  --> the text insert over the line
2) when the direction  is from  right to left --> the text insert under the line

Thanks
Title: Re: line or polyline distance
Post by: CAB on May 09, 2014, 09:59:25 PM
Change to this:
 
Code: [Select]
       (cons 11 (polar pt (+ (/ pi 2) (readableAngle ang)) kl)) ; The insert point of the text when not left aligned.
Title: Re: line or polyline distance
Post by: pedroantonio on May 10, 2014, 02:47:59 AM
Thank you Cab. I do the change ,but i still have a problem. Why this lisp gives me this  message

Quote
    (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again....")

when  i select the red lines in the test.dwg? 

Code - Auto/Visual Lisp: [Select]
  1. (defun readableAngle (ang)
  2.   (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  3.   (if (< (* pi 0.5) ang (* pi 1.5))
  4.     (+ ang pi)
  5.     ang
  6.   )
  7. )
  8.  
  9. (defun c:linedim (/ e p ht scl len pt ang)
  10.   (setvar "cmdecho" 0)
  11.   (command "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  12.   (setq scl (getvar "useri1"))
  13.   (setq ht (* 0.00175 scl))
  14.   (setq kl (* 0.001275 scl)) ; Changed to account for text height.
  15.   (command "style" "diast" "wgsimpl.shx")
  16.   (while (> (getvar "cmdactive") 0) (command ""))
  17.   (if
  18.     (and
  19.       (setq e (entsel "\n select line or polyline :"))
  20.       (setq e (car e))
  21.       (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  22.     )
  23.     (progn
  24.       (setq len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) ; Get the length of the line/pline to its end.
  25.       (setq pt (vlax-curve-getpointatdist e (/ len 2.0))) ; Get the point at mid of line/pline.
  26.       (setq ang (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e pt)))) ; Get angle at midpoint.
  27.       (entmakex
  28.         (list
  29.           '(0 . "TEXT")
  30.           '(100 . "AcDbEntity")
  31.           '(100 . "AcDbText")
  32.           '(10 0.0 0.0 0.0) ; The base insert point of the text (ignored when not left aligned).
  33.           (cons 40 ht)          
  34.           (cons 1 (rtos len 2 2)) ; The length converted to text.
  35.           (cons 50 (readableAngle ang)) ; Rotate the text to follow the line/pline.
  36.           '(7 . "diast") ; Text style.
  37.           '(71 . 0)
  38.           '(72 . 1)
  39.        (cons 11 (polar pt (+ (/ pi 2) (readableAngle ang)) kl)) ; The insert point of the text when not left aligned.
  40.           '(73 . 2)
  41.         )
  42.       )
  43.     )
  44.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again....")
  45.   )
  46.   (princ)
  47. )
  48.  
  49.  
  50.  
Title: Re: line or polyline distance
Post by: CAB on May 10, 2014, 07:02:50 AM
vlax-curve- failes when too far from the origin.

You will need to move the object to 0,0 for it to work or use another method to get the angle.
Title: Re: line or polyline distance
Post by: CAB on May 10, 2014, 07:26:29 AM
Crude fix:
Code - Auto/Visual Lisp: [Select]
  1.     (defun readableAngle (ang)
  2.      (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  3.      (if (< (* pi 0.5) ang (* pi 1.5))
  4.        (+ ang pi)
  5.        ang
  6.      )
  7.     )
  8.      
  9.     (defun c:linedim (/ e p ht scl len pt ang)
  10.      (setvar "cmdecho" 0)
  11.      (command "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  12.      (setq scl (getvar "useri1"))
  13.      (setq ht (* 0.00175 scl))
  14.      (setq kl (* 0.001275 scl)) ; Changed to account for text height.
  15.      (command "style" "diast" "wgsimpl.shx")
  16.      (while (> (getvar "cmdactive") 0) (command ""))
  17.      (if
  18.        (and
  19.          (setq e (entsel "\n select line or polyline :"))
  20.          (setq e (car e))
  21.          (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  22.        )
  23.        (progn
  24.          (setq len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) ; Get the length of the line/pline to its end.
  25.          (setq pt (vlax-curve-getpointatdist e (/ len 2.0))) ; Get the point at mid of line/pline.
  26.            (setq ang (angle '(0.0 0.0 0.0)(vlax-curve-getfirstderiv e v))) ; Get angle at midpoint.
  27.            (setq ang (angle (vlax-curve-getpointatdist e (-(/ len 2.0) 0.01))(vlax-curve-getpointatdist e (+(/ len 2.0) 0.01)))) ; Get angle at midpoint.
  28.          )
  29.          (entmakex
  30.            (list
  31.              '(0 . "TEXT")
  32.              '(100 . "AcDbEntity")
  33.              '(100 . "AcDbText")
  34.              '(10 0.0 0.0 0.0) ; The base insert point of the text (ignored when not left aligned).
  35.              (cons 40 ht)          
  36.              (cons 1 (rtos len 2 2)) ; The length converted to text.
  37.              (cons 50 (readableAngle ang)) ; Rotate the text to follow the line/pline.
  38.              '(7 . "diast") ; Text style.
  39.              '(71 . 0)
  40.              '(72 . 1)
  41.           (cons 11 (polar pt (+ (/ pi 2) (readableAngle ang)) kl)) ; The insert point of the text when not left aligned.
  42.              '(73 . 2)
  43.            )
  44.          )
  45.        )
  46.        (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again....")
  47.      )
  48.      (princ)
  49.     )
Title: Re: line or polyline distance
Post by: pedroantonio on May 10, 2014, 10:02:59 AM
Thank you CAB