Author Topic: Line bearing and Distance  (Read 1804 times)

0 Members and 1 Guest are viewing this topic.

scottcd

  • Newt
  • Posts: 52
Line bearing and Distance
« on: September 01, 2017, 06:33:29 AM »
I am trying to create a lisp routine to annotate a line with the bearing and distance

I have ucs set to north and angles clockwise.

How do I get the bearing in this UCS when angle return anticlockwise in radians?

I would like to have the distance always centred on the top of the line with the bearing below?

Thanks

Scott
AutoCAD Dos R9 - 2018 and BricCAD 18.2

pedroantonio

  • Guest
Re: Line bearing and Distance
« Reply #1 on: September 01, 2017, 06:37:56 AM »
Hi Scottcd. I use this code

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. ;;; ROTINA PARA COTAR E OU AZIMUTAR POLYLINES - TEXTO NO DESENHO = 2.34 ou 2.34 - Az 23°15/7"
  4. ;;; AS MEDIDAS APARECEM COMO FORAM DIGITADAS NO DESENHO (METROS, MILIMETROS, ETC)
  5. ;;; A ALTURA DO TEXTO E SOLICITADA NA EXECUCAO DA ROTINA E O STYLE E O CORRENTE
  6. ;;; ACERTAR ALTURA DO TEXTO DE ACORDO COM A ESCALA DE PLOTAGEM. PARA DEIXAR EM DEFAULT USE O COMMAND: TEXTSIZE
  7. ;;; Forum www.autolisp.com.br - Nome da rotina original: AZPOL - Autor: Orlei 29/08/2006
  8. ;;; Adaptacao: Rogerio Zanini e Marcio
  9. ;;;---------------------------------------------------------- ------------------------
  10.  
  11.  
  12. (defun C:BDANNOT ()
  13. (COMMAND "_layer" "_m" "_bd" "_c" "150" "" "")
  14. (command "-style" "_bd" "arial.ttf" "_annotative" "_yes" "_no" 2.5 1.0 0.0 "_no" "_no" "_no")
  15. ;---------------Sub-functions - Start-------------
  16. (defun PARALELO ()
  17. ;---------------------------------------------------------------
  18. (setq A1 (polar A (+ (/ pi 2)(angle B A )) (+ (* 0.05 2.5))))
  19. (setq B1 (polar B (+ (/ pi 2)(angle B A )) (+ (* 0.05 2.5))))
  20. ;--------------------------------------------------------------
  21. (setq ptx (/ (+ (car B1) (car A1)) 2))
  22. (setq pty (/ (+ (cadr B1) (cadr A1)) 2))
  23. (setq ponto_meio (list ptx pty))
  24. ;(if (< (car A1)(car B1))
  25. ;(setq inicio B1)
  26. (setq inicio A1)
  27. ;)
  28. )
  29. ;----------------Sub-functions - End -------------
  30. (setvar"cmdecho" 0)
  31. (setq flagv "falso")
  32. (setq controle 0)
  33. (setq controle1 0)
  34. (setq contador 0)
  35. (while (= flagv "falso")
  36. (setq mostre (entsel "\nselect a polyline <2d> : "))
  37. (setq linha (entget (car mostre )))
  38. (setq verificador (cdr(assoc 0 linha)))
  39. (if (= verificador "LWPOLYLINE")
  40. (setq verif (cdr (assoc 70 linha)))
  41. (setq flagv "verdade")
  42. )
  43. (princ "\nthis is not a  Polyline !! ")
  44. )
  45. )
  46. (setq controle1 (length linha))
  47. (setq amostra '())
  48. (repeat controle1
  49. (setq x (caar linha))
  50. (if (= x 10)
  51. (setq item (car linha))
  52. (setq amostra (cons item amostra))
  53. (setq contador (1+ contador))
  54. )
  55. )
  56. (setq linha (cdr linha))
  57. )
  58. (setq amostra1 (reverse amostra))
  59. (if (= verif 1)
  60. (setq amostra (cons (car amostra1) amostra))
  61. (setq contador (1- contador))
  62. )
  63. (setq controle contador)
  64. (repeat controle
  65. (setq PTO1 (cdr(car amostra)))
  66. (setq PTO2 (cdr(car(cdr amostra))))
  67. (AZIMUTAR)
  68. (setq amostra(cdr amostra))
  69. )
  70. (command "undo" "end")
  71. (setvar "textsize" 2.5)
  72. (setvar"cmdecho" 1)
  73. )
  74. ;---------------------------------------------------------
  75. (defun AZIMUTAR ()
  76. (setq A PTO1)
  77. (setq B PTO2)
  78. (setq C " - Az ")
  79. (setq D (angtos (angle B A)))
  80. (setq PALAV D)
  81. ;------------- MODIFICACAO ROGERIO OPCAO AZIMUTE ----------------
  82. (setq E (strcat (rtos (distance A B) 2 2) "m"))
  83. (setq DADO (strcat E C PALAV))
  84. ;---------------------------------------------------------- ------
  85. (PARALELO)
  86. (if (zerop (cdr (assoc 40 (entget (tblobjname "style" (getvar 'textstyle))))))
  87.   (command "_.-text" "_justify" "_Bc" "_non" ponto_meio 2.5 "_non" inicio dado)
  88.   (command "_.-text" "_justify" "_Bc" "_non" ponto_meio "_non" inicio dado)
  89. )
  90. )
  91.  
  92.  


Mark

  • Custom Title
  • Seagull
  • Posts: 28762
TheSwamp.org  (serving the CAD community since 2003)

hanhphuc

  • Newt
  • Posts: 64
Re: Line bearing and Distance
« Reply #3 on: September 01, 2017, 08:37:12 AM »
I am trying to create a lisp routine to annotate a line with the bearing and distance

I have ucs set to north and angles clockwise.

How do I get the bearing in this UCS when angle return anticlockwise in radians?
angdir angbase

I would like to have the distance always centred on the top of the line with the bearing below?
MText justify middle center

Thanks

Scott
There are many examples, but
how's the output unit & format?
In our country we familiar degress format dd°mm'ss",
recently has been discussed here
« Last Edit: September 01, 2017, 09:23:42 AM by hanhphuc »
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments