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

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #30 on: April 10, 2014, 01:27:16 PM »
Thank you mailmaverick but the problem still exist.Look the attach

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #31 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}=-. :-)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #32 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.

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #33 on: April 10, 2014, 03:10:12 PM »
Thank you all . Now it work perfect

mailmaverick

  • Bull Frog
  • Posts: 493
Re: line or polyline distance
« Reply #34 on: April 10, 2014, 03:15:26 PM »
Kindly post your final code.

pedroantonio

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

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #36 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 <-.

pedroantonio

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

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #38 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 .
?

pedroantonio

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: line or polyline distance
« Reply #40 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 ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ChrisCarlson

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

pedroantonio

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

MORITZK

  • Mosquito
  • Posts: 18
Re: line or polyline distance
« Reply #43 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

pedroantonio

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