Author Topic: get angle of line and insert at the end  (Read 7198 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
get angle of line and insert at the end
« on: March 22, 2012, 12:37:46 PM »
im trying to get the angle of a selected line and put that angle in degrees at the end of the line. i dont think im getting the angle part im getting the reverse of the actual angle im after

here is my starting off code currently in progress

Code: [Select]
(defun c:angl (/ scale lne selpt pt1 pt2 dist1 dist2 bp bp2 rad)
  (setq scale (getvar "dimscale"))
  (setq lne (entsel "\nSelect line: "))
  (setq selpt (cadr lne))
  (setq pt1 (cdr (assoc 10 (entget (car lne)))))
  (setq pt2 (cdr (assoc 11 (entget (car lne)))))
 
  (SETQ AG1 (ANGLE pt1 pt2))
  (SETQ AG2 (ANGLE pt2 pt1))
 (IF (< AG1 AG2)
   (SETQ AN1 AG1)
   (SETQ AN1 AG2)
 )
 (SETQ AN2 (ANGTOS AN1 0 3))
 
  (setq dist1 (/ (distance pt1 pt2) 2))
  (setq dist2 (distance pt1 selpt))
  (if (< dist1 dist2)
    (progn
    (setq rad (angle pt2 pt1))
    (setq bp (polar pt1 rad (* (* 1.125 scale) (/ 12 scale))))
    (setq bp2 (polar bp rad 8.5))
    (command "text" "J" "M" bp "" "" an2 )
    )
    (progn
    (setq rad (angle pt2 pt1))
    (setq bp (polar pt1 rad (* (* 1.125 scale) (/ 12 scale))))
    (setq bp2 (polar bp rad 8.5))
    (command "text" "J" "M" bp "" "" an2 )
    )
  )
  (princ)
)

the following picture is what im after
going in a clockwork direction

Tharwat

  • Swamp Rat
  • Posts: 712
  • Hypersensitive
Re: get angle of line and insert at the end
« Reply #1 on: March 22, 2012, 01:25:34 PM »
This .... ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:TesT (/ ss i sn e p1 p2 p ang st h)
  2. ;;; Tharwat 22. march . 2012 ;;;
  3.   (if (setq ss (ssget '((0 . "LINE"))))
  4.     (repeat (setq i (sslength ss))
  5.       (setq sn (ssname ss (setq i (1- i))))
  6.       (setq p1 (cdr (assoc 10 (setq e (entget sn)))))
  7.       (setq p2 (cdr (assoc 11 e)))
  8.       (if (> (cadr p1) (cadr p2))
  9.         (progn
  10.           (setq p p1)
  11.           (setq ang (angle p1 p2))
  12.         )
  13.         (progn
  14.           (setq p p2)
  15.           (setq ang (angle p2 p1))
  16.         )
  17.       )
  18.       (entmakex (list (cons 0 "MTEXT")
  19.                       (cons 100 "AcDbEntity")
  20.                       (cons 100 "AcDbMText")
  21.                       (cons 40
  22.                             (setq h (if (zerop (cdr (assoc 40
  23.                                                            (setq st
  24.                                                                   (entget
  25.                                                                     (tblobjname "STYLE" (getvar 'textstyle))
  26.                                                                   )
  27.                                                            )
  28.                                                     )
  29.                                                )
  30.                                         )
  31.                                       (cdr (assoc 42 st))
  32.                                       (cdr (assoc 40 st))
  33.                                     )
  34.                             )
  35.                       )
  36.                       (cons 71 5)
  37.                       '(50 . 0.0)
  38.                       (cons 10 (polar p (+ pi ang) (/ h 2.)))
  39.                       (cons 1 (strcat (rtos (angtof (rtos ang 2) 0 ) 2) "%%d"))
  40.                 )
  41.       )
  42.     )
  43.     (princ)
  44.   )
  45.   (princ)
  46. )

andrew_nao

  • Guest
Re: get angle of line and insert at the end
« Reply #2 on: March 22, 2012, 01:32:57 PM »
thanks for the reply
but thats it almost like what i already have but it puts the info in decimal

Tharwat

  • Swamp Rat
  • Posts: 712
  • Hypersensitive
Re: get angle of line and insert at the end
« Reply #3 on: March 22, 2012, 01:37:29 PM »
So you want the angle in Radians or what ?

andrew_nao

  • Guest
Re: get angle of line and insert at the end
« Reply #4 on: March 22, 2012, 01:44:44 PM »
im looking to get the angle of a line (whatever line is picked) in degrees, just like the picture i attached.

my code and your code are giving me undesired results.

im missing something simple it has to be. it cant be this hard but but i just cant see it

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: get angle of line and insert at the end
« Reply #5 on: March 22, 2012, 01:50:46 PM »
Normally zero is at 3:00 and not 12:00, for me that is.  :-)
And the rotation is CCW.
« Last Edit: March 22, 2012, 01:54:57 PM 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.

Tharwat

  • Swamp Rat
  • Posts: 712
  • Hypersensitive
Re: get angle of line and insert at the end
« Reply #6 on: March 22, 2012, 02:00:49 PM »
I guess the problem is within your drawing units , so try the code on another new drawing .

andrew_nao

  • Guest
Re: get angle of line and insert at the end
« Reply #7 on: March 22, 2012, 02:08:36 PM »
Normally zero is at 3:00 and not 12:00, for me that is.  :-)
And the rotation is CCW.

in a perfect world it would be...

my company has to be different

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: get angle of line and insert at the end
« Reply #8 on: March 22, 2012, 03:30:17 PM »
When you select the line marked 30 deg in your example what does the property box display as the ANGEL?
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.

andrew_nao

  • Guest
Re: get angle of line and insert at the end
« Reply #9 on: March 22, 2012, 03:57:29 PM »
When you select the line marked 30 deg in your example what does the property box display as the ANGEL?

if i list it, it displays 240 deg
if i run my code, it displays 60 deg

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: get angle of line and insert at the end
« Reply #10 on: March 22, 2012, 04:02:23 PM »
One more question, What is the angle on the line marked zero?
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.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: get angle of line and insert at the end
« Reply #11 on: March 22, 2012, 04:10:35 PM »
Ensure:

ANGBASE = 90.0
ANGDIR  = 1


Then try this:

Code - Auto/Visual Lisp: [Select]
  1. ;; Line Angle  -  Lee Mac
  2. ;; Displays the Angle of a Line at its endpoint using a Field
  3.  
  4. (defun c:LineAng ( / acdoc acsel acspc mtx objid pnt )
  5.  
  6.           acspc ((if (= 1 (getvar 'CVPORT)) vla-get-paperspace vla-get-modelspace) acdoc)
  7.     )
  8.     (setq objid
  9.         (eval
  10.             (list 'lambda '( obj )
  11.                 (if
  12.                     (and
  13.                         (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  14.                         (vlax-method-applicable-p (vla-get-utility acdoc) 'getobjectidstring)
  15.                     )
  16.                     (list 'vla-getobjectidstring (vla-get-utility acdoc) 'obj ':vlax-false)
  17.                    '(itoa (vla-get-objectid obj))
  18.                 )
  19.             )
  20.         )
  21.     )
  22.    
  23.     (if (ssget '((0 . "LINE")))
  24.         (progn
  25.             (while (= 8 (logand 8 (getvar 'UNDOCTL)))
  26.                 (vla-endundomark acdoc)
  27.             )
  28.             (vla-startundomark acdoc)
  29.             (vlax-for obj (setq acsel (vla-get-activeselectionset acdoc))
  30.                 (setq pnt
  31.                     (vlax-3D-point
  32.                         (polar
  33.                             (vlax-get obj 'endpoint)
  34.                             (vlax-get obj 'angle)
  35.                             (getvar 'TEXTSIZE)
  36.                         )
  37.                     )
  38.                 )
  39.                 (setq mtx
  40.                     (vla-addmtext acspc pnt 0.0
  41.                         (strcat
  42.                             "%<\\AcObjProp Object(%<\\_ObjId "
  43.                             (objid obj)
  44.                             ">%).Angle \\f \"%au0\">%"
  45.                         )
  46.                     )
  47.                 )
  48.                 (vla-put-attachmentpoint mtx acattachmentpointmiddlecenter)
  49.                 (vla-put-insertionpoint  mtx pnt)
  50.             )
  51.             (vla-delete acsel)
  52.             (vla-endundomark acdoc)
  53.         )
  54.     )
  55.     (princ)
  56. )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: get angle of line and insert at the end
« Reply #12 on: March 22, 2012, 05:18:08 PM »
I think the problem is that he is not allowed to change those or at least he must
change them back to there company standard.
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.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: get angle of line and insert at the end
« Reply #13 on: March 22, 2012, 05:28:27 PM »
I think the problem is that he is not allowed to change those or at least he must
change them back to there company standard.

Looking at the drawing practice in the example, I would have thought the company standard would require the aforementioned System Variables to be set to precisely those values - otherwise surely the CAD environment would contradict the company drafting standards?

andrew_nao

  • Guest
Re: get angle of line and insert at the end
« Reply #14 on: March 23, 2012, 07:29:29 AM »
One more question, What is the angle on the line marked zero?

270