Author Topic: line or polyline distance  (Read 12693 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: line or polyline distance
« Reply #45 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.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #46 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.  

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: line or polyline distance
« Reply #47 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.
« Last Edit: May 10, 2014, 07:10:40 AM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: line or polyline distance
« Reply #48 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.     )
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #49 on: May 10, 2014, 10:02:59 AM »
Thank you CAB