Author Topic: dimension polyline with annotation text  (Read 2568 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
dimension polyline with annotation text
« on: September 06, 2015, 12:27:13 PM »
Hi. I am trying to convert an old code to work with annotation text but i have some probles with the code.

can any one help ?


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:linedimannot (/ e p ht scl len pt ang)
  10.      (setvar "cmdecho" 0)
  11.    (COMMAND "_layer" "_m" "_Diast" "_c" "93" "" "_lw" "0.30" "" "")
  12.    (command "-style" "_diast" "wgsimpl.shx" "A" "Y" "N" 1.75 "1" "0" "n" "n" "n")
  13.      (while (> (getvar "cmdactive") 0) (command ""))
  14.      (if
  15.        (and
  16.          (setq e (entsel "\n select line  or polyline :"))
  17.          (setq e (car e))
  18.          (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  19.        )
  20.        (progn
  21.          (setq len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) ; Get the length of the line/pline to its end.
  22.          (setq pt (vlax-curve-getpointatdist e (/ len 2.0))) ; Get the point at mid of line/pline.
  23.            (setq ang (angle '(0.0 0.0 0.0)(vlax-curve-getfirstderiv e v))) ; Get angle at midpoint.
  24.            (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.
  25.          )
  26.          (entmakex
  27.            (list
  28.              '(0 . "TEXT")
  29.              '(100 . "AcDbEntity")
  30.              '(100 . "AcDbText")
  31.              '(10 0.0 0.0 0.0) ; The base insert point of the text (ignored when not left aligned).
  32.              (cons 1 (rtos len 2 2)) ; The length converted to text.
  33.              (cons 50 (readableAngle ang)) ; Rotate the text to follow the line/pline.
  34.              '(7 . "_diast") ; Text style.
  35.              '(40 . 1.75)
  36.              '(71 . 0)
  37.              '(72 . 1)
  38.           (cons 11 (polar pt (+ (/ pi 2) (readableAngle ang)))) ; The insert point of the text when not left aligned.
  39.              '(73 . 2)
  40.            )
  41.          )
  42.        )
  43.     (princ "\ntry again")
  44.      )
  45.      (princ)
  46.     )
  47.  
  48.  

thanks
« Last Edit: September 07, 2015, 05:03:37 AM by Topographer »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: dimension polyline with annotation text
« Reply #1 on: September 07, 2015, 04:19:31 AM »
In line 39 of the code a closing parenthesis is missing.

pedroantonio

  • Guest
Re: dimension polyline with annotation text
« Reply #2 on: September 07, 2015, 05:05:07 AM »
I update the code but still not working .Any ideas?

Thanks

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: dimension polyline with annotation text
« Reply #3 on: September 07, 2015, 07:08:28 AM »
The signature of the polar function is:
Code: [Select]
(polar pt ang dist)You are not supplying dist.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: dimension polyline with annotation text
« Reply #4 on: September 07, 2015, 07:32:46 AM »
To preempt your next question:
To create annotative text entities you will probably need to switch from the entmake Lisp function to the use of the -TEXT command.

pedroantonio

  • Guest
Re: dimension polyline with annotation text
« Reply #5 on: September 07, 2015, 09:52:28 AM »
Hi roy_043 i update the code but the still be not annotated.

An a second qustion. Before change the code i use this command

Code - Auto/Visual Lisp: [Select]
  1. (setq kl (* 0.001275 scl)   ; scl = scale  kl = the insert text distance from the line

to calculate the insert text  distance from the line. Is any option to imput in the code the most use annotate scales in order to calculate the insert distanse ?

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:linedimannot (/ e p ht scl len pt ang)
  10.      (setvar "cmdecho" 0)
  11.    (COMMAND "_layer" "_m" "_Diast" "_c" "93" "" "_lw" "0.30" "" "")
  12.    (command "-style" "_diast" "wgsimpl.shx" "A" "Y" "N" 1.75 "1" "0" "n" "n" "n")
  13.      (while (> (getvar "cmdactive") 0) (command ""))
  14.      (if
  15.        (and
  16.          (setq e (entsel "\n select line  or polyline :"))
  17.          (setq e (car e))
  18.          (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  19.        )
  20.        (progn
  21.          (setq len (vlax-curve-getdistatparam e (vlax-curve-getendparam e))) ; Get the length of the line/pline to its end.
  22.          (setq pt (vlax-curve-getpointatdist e (/ len 2.0))) ; Get the point at mid of line/pline.
  23.            (setq ang (angle '(0.0 0.0 0.0)(vlax-curve-getfirstderiv e v))) ; Get angle at midpoint.
  24.            (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.
  25.          )
  26.          (entmakex
  27.            (list
  28.              '(0 . "TEXT")
  29.              '(100 . "AcDbEntity")
  30.              '(100 . "AcDbText")
  31.              '(10 0.0 0.0 0.0) ; The base insert point of the text (ignored when not left aligned).
  32.              (cons 1 (rtos len 2 2)) ; The length converted to text.
  33.              (cons 50 (readableAngle ang)) ; Rotate the text to follow the line/pline.
  34.              '(7 . "_diast") ; Text style.
  35.              '(40 . 1.75)
  36.              '(71 . 0)
  37.              '(72 . 1)
  38.           (cons 11 (polar pt (+ (/ pi 2) (readableAngle ang)) 0.25)) ; The insert point of the text when not left aligned.
  39.              '(73 . 2)
  40.            )
  41.          )
  42.        )
  43.     (princ "\ntry again")
  44.      )
  45.      (princ)
  46.     )
  47.  
  48.  

Thanks

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: dimension polyline with annotation text
« Reply #6 on: September 07, 2015, 03:49:51 PM »
I don't know a way to get the most frequently used annotative scales. It is possible to get a list of *all* scales that are defined in the drawing. But this would not be very useful for your purpose I think.

I would change the code to use the -TEXT command (as mentioned before) and change the justification of the text to bottom 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.  
  9. (defun Rad_To_Dgr (rad)
  10.   (* (/ rad pi) 180.0)
  11. )
  12.  
  13. ; Note 1: Only works for the WCS.
  14. ; Note 2: The code assumes that AUNITS=0.
  15. ; Note 3: Perhaps reset textstyle and clayer?
  16. (defun c:LineDimAnnot (/ ang en len pt par)
  17.   (setvar 'cmdecho 0)
  18.   (command "_.-layer" "_make" "_Diast" "_color" 93 "" "_lweight" 0.30 "" "")
  19.   (command "_.-style" "_Diast" "txt.shx" "_annotative" "_yes" "_no" 1.75 1.0 0.0 "_no" "_no" "_no")
  20.   (if
  21.     (and
  22.       (setq en (car (entsel "\nSelect line or polyline:")))
  23.       (member (cdr (assoc 0 (entget en))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  24.     )
  25.     (progn
  26.       (setq pt (vlax-curve-getpointatdist en (/ len 2.0)))
  27.         (setq ang (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv en par)))
  28.         (setq ang (angle pt (vlax-curve-getpointatdist en (+ (/ len 2.0) 0.01)))) ; When is this required?
  29.       )
  30.       (command "_.-text" "_justify" "_bc" "_non" pt (Rad_To_Dgr (ReadableAngle ang)) (rtos len 2 2))
  31.     )
  32.   )
  33.   (setvar 'cmdecho 1)
  34.   (princ)
  35. )

pedroantonio

  • Guest
Re: dimension polyline with annotation text
« Reply #7 on: September 08, 2015, 11:16:47 AM »
Hi roy_043 I test your code and the annotation works but now i have text rotation problem. look the dwg file to see my template settings for units



roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: dimension polyline with annotation text
« Reply #8 on: September 08, 2015, 02:08:44 PM »
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. ; Convert radians to gradians.
  10. (defun Rad_To_Grad (rad)
  11.   (* (/ rad pi) 200.0)
  12. )
  13.  
  14. ; Note 1: Only works for the WCS.
  15. ; Note 2: The code assumes that AUNITS=2. ANGBASE and ANGDIR may vary.
  16. ; Note 3: Perhaps reset textstyle and clayer?
  17. (defun c:LineDimAnnot (/ ang en len pt par)
  18.   (setvar 'cmdecho 0)
  19.   (command "_.-layer" "_make" "_Diast" "_color" 93 "" "_lweight" 0.30 "" "")
  20.   (command "_.-style" "_Diast" "txt.shx" "_annotative" "_yes" "_no" 1.75 1.0 0.0 "_no" "_no" "_no")
  21.   (if
  22.     (and
  23.       (setq en (car (entsel "\nSelect line or polyline:")))
  24.       (member (cdr (assoc 0 (entget en))) '("LINE" "LWPOLYLINE" "POLYLINE"))
  25.     )
  26.     (progn
  27.       (setq pt (vlax-curve-getpointatdist en (/ len 2.0)))
  28.         (setq ang (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv en par)))
  29.         (setq ang (angle pt (vlax-curve-getpointatdist en (+ (/ len 2.0) 0.01)))) ; When is this required?
  30.       )
  31.       (setq ang
  32.         (Rad_To_Grad
  33.           ((if (zerop (getvar 'angdir)) + -)
  34.             (- (ReadableAngle ang) (getvar 'angbase))
  35.           )
  36.         )
  37.       )
  38.       (command "_.-text" "_justify" "_bc" "_non" pt ang (rtos len 2 2))
  39.     )
  40.   )
  41.   (setvar 'cmdecho 1)
  42.   (princ)
  43. )

pedroantonio

  • Guest
Re: dimension polyline with annotation text
« Reply #9 on: September 08, 2015, 05:47:03 PM »
Thank you roy_043