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

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #15 on: April 10, 2014, 03:19:31 AM »
I try some combinations of this but i can't find the error

Code: [Select]

71

Text generation flags (optional, default = 0):
2 = Text is backward (mirrored in X).
4 = Text is upside down (mirrored in Y).

72

Horizontal text justification type (optional, default = 0) integer codes (not bit-coded)
0 = Left; 1= Center; 2 = Right
3 = Aligned (if vertical alignment = 0)
4 = Middle (if vertical alignment = 0)
5 = Fit (if vertical alignment = 0)
See the Group 72 and 73 integer codes table for clarification.

73

Vertical text justification type (optional, default = 0): integer codes (not bit- coded):
0 = Baseline; 1 = Bottom; 2 = Middle; 3 = Top
See the Group 72 and 73 integer codes table for clarification.

I want the text to be center not left

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2. (setvar "cmdecho" 0)
  3.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  4.   (SETQ scl (GETVAR "useri1"))
  5.   (SETQ ht (* 0.00175 SCL))
  6.   (SETQ kl (* 0.0004 SCL))
  7.   (COMMAND "style" "diast" "romans.shx")
  8.   (while (> (getvar "CmdActive") 0) (command ""))
  9.   (if (and (setq e (entsel "\n select line or polyline :"))
  10.            (setq e (car e))
  11.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  12.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to
  13.  
  14. its end
  15.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  16.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get
  17.  
  18. angle at
  19.  
  20. midpoint
  21.            (entmakex (list '(0 . "TEXT")
  22.                            '(100 . "AcDbEntity")
  23.                            '(100 . "AcDbText")
  24.                            (cons 40 ht)
  25.                            '(7 . "diast") ;Text style
  26.                            (cons 71 0) ; Text generation flags (optional, default = 0)
  27.                            (cons 72 1) ; Horizontal text justification type 1= Cente
  28.                            (cons 73 0) ; Vertical text justification type (optional, default = 0))
  29.                            (cons 10 (polar pt (+ (/ pi 2) ang) kl)) ;The insert point of the text
  30.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  31.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  32.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  33.   (princ))

Thanks

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #16 on: April 10, 2014, 03:53:40 AM »
You should compare more carefully. There are 4 differences not 2.

Left aligned text:
Code: [Select]
(
  (-1 . <Entity name: cb2deb0>)
  (0 . "TEXT")
  (5 . "AC")
  (330 . <Entity name: caeb090>)
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "0")
  (100 . "AcDbText")
  (10 819.719 207.205 0.0)
  (40 . 100.0)
  (1 . "aaa")
  (50 . 0.0)
  (41 . 1.0)
  (51 . 0.0)
  (7 . "Standard")
  (71 . 0)
  (72 . 0)
  (11 0.0 0.0 0.0)
  (210 0.0 0.0 1.0)
  (100 . "AcDbText")
  (73 . 0)
)

Middle center aligned text:
Code: [Select]
(
  (-1 . <Entity name: cbe0e38>)
  (0 . "TEXT")
  (5 . "AD")
  (330 . <Entity name: caeb090>)
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "0")
  (100 . "AcDbText")
  (10 703.319 157.205 0.0)  ; <-- First alignment point. Not the insertion point.
  (40 . 100.0)
  (1 . "aaa")
  (50 . 0.0)
  (41 . 1.0)
  (51 . 0.0)
  (7 . "Standard")
  (71 . 0)
  (72 . 1)                  ; <--
  (11 819.719 207.205 0.0)  ; <-- Second alignment point. Insertion point.
  (210 0.0 0.0 1.0)
  (100 . "AcDbText")
  (73 . 2)                  ; <--
)

For the first alignment point of a middle center aligned text you can use a dummy point for the entmake(x) list. But gc 10 must be present. At least on BricsCAD this applies.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: line or polyline distance
« Reply #17 on: April 10, 2014, 04:08:48 AM »
For the first alignment point of a middle center aligned text you can use a dummy point for the entmake(x) list. But gc 10 must be present. At least on BricsCAD this applies.
Yep, I can confirm on AutoCAD 2014 it also works. E.g.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2.   (setvar "cmdecho" 0)
  3.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  4.   (SETQ scl (GETVAR "useri1"))
  5.   (SETQ ht (* 0.00175 SCL))
  6.   (SETQ kl (* 0.0004 SCL))
  7.   (COMMAND "style" "diast" "romans.shx")
  8.   (while (> (getvar "CmdActive") 0) (command ""))
  9.   (if (and (setq e (entsel "\n select line or polyline :"))
  10.            (setq e (car e))
  11.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  12.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  13.                  pt  (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  14.                  ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at midpoint
  15.            (entmakex (list '(0 . "TEXT")
  16.                            '(100 . "AcDbEntity")
  17.                            '(100 . "AcDbText")
  18.                            (cons 40 ht)
  19.                            '(7 . "diast") ;Text style
  20.                            '(72 . 1) ; Horizontal text justification type 1= Center
  21.                            '(10 0.0 0.0 0.0) ;The base insert point of the text (ignored when not left aligned)
  22.                            (cons 11 (polar pt (+ (/ pi 2) ang) kl)) ;The insert point of the text when not left aligned
  23.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  24.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  25.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  26.   (princ))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #18 on: April 10, 2014, 04:19:42 AM »
Thanks !! :-D

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #19 on: April 10, 2014, 04:40:48 AM »
I want to ask for something else. Look the direction of the lines in the attach file and the comments
thanks

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #20 on: April 10, 2014, 04:52:01 AM »
Code: [Select]
(setq ang (rem ang (* pi 0.5)))Edit: This does not work properly... See #23.
« Last Edit: April 10, 2014, 05:29:03 AM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #21 on: April 10, 2014, 04:58:48 AM »
I add this two lines for Middle Center Justification
Note: In the drawing the texts are center aligned. Not middle center aligned.

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: line or polyline distance
« Reply #22 on: April 10, 2014, 05:17:33 AM »
Is it easy to convert this text to be annotative?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #23 on: April 10, 2014, 05:27:44 AM »
Code: [Select]
(defun readableAngle (ang)
  (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  (if (< (* pi 0.5) ang (* pi 1.5))
    (+ ang pi)
    ang
  )
)

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #24 on: April 10, 2014, 06:20:12 AM »
roy_43 You are talking something about this !!! Is not working ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ e p ht scl len pt ang)
  2. (setvar "cmdecho" 0)
  3.   (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  4.   (SETQ scl (GETVAR "useri1"))
  5.   (SETQ ht (* 0.00175 SCL))
  6.   (SETQ kl (* 0.0004 SCL))
  7.   (COMMAND "style" "diast" "romans.shx")
  8.   (while (> (getvar "CmdActive") 0) (command ""))
  9.   (if (and (setq e (entsel "\n select line or polyline :"))
  10.            (setq e (car e))
  11.            (member (cdr (assoc 0 (entget e))) '("LINE" "LWPOLYLINE" "POLYLINE")))
  12.     (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) ;Get the length of the line/pline to its end
  13.                  pt (vlax-curve-getPointAtDist e (/ len 2.0)) ;Get the point at mid of line/pline
  14.                  ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))) ;Get angle at midpoint
  15.  (if (< (* pi 0.5) ang (* pi 1.5))
  16.     (+ ang pi)
  17.     ang
  18.   )
  19.            (entmakex (list '(0 . "TEXT")
  20.                            '(100 . "AcDbEntity")
  21.                            '(100 . "AcDbText")
  22.                            (cons 40 ht)
  23.                            '(7 . "diast") ;Text style
  24.                            (cons 71 0) ; Text generation flags (optional, default = 0)
  25.                            (cons 72 1) ; Horizontal text justification type 1= Cente
  26.                            (cons 73 0) ; Vertical text justification type (optional, default = 0))
  27.                            (cons 10 (polar pt (+ (/ pi 2) ang) kl)) ;The insert point of the text
  28.                            (cons 1 (rtos len 2 2)) ;The length converted to text
  29.                            (cons 50 ang)))) ;Rotate the text to follow the line/pline
  30.     (princ "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."))
  31.   (princ))

ChrisCarlson

  • Guest
Re: line or polyline distance
« Reply #25 on: April 10, 2014, 07:55:25 AM »
Is it easy to convert this text to be annotative?

I borrowed this from lee-mac I beleive.

Code: [Select]
(entmake
                (list
                    (cons 0 "ENDBLK")
                    (cons 8 "0")
                )
            )
            (
                (lambda ( lst )
                    (regapp "ACAD")
                    (regapp "AcadAnnotative")
                    (entmod
                        (append (subst (cons 70 1) (assoc 70 lst) lst)
                            (list
                               (list -3
                                   (list "ACAD"
                                       (cons 1000 "DesignCenter Data")
                                       (cons 1002 "{")
                                       (cons 1070 1)
                                       (cons 1070 1)
                                       (cons 1002 "}")
                                   )
                                   (list "AcadAnnotative"
                                       (cons 1000 "AnnotativeData")
                                       (cons 1002 "{")
                                       (cons 1070 1)
                                       (cons 1070 1)
                                       (cons 1002 "}")
                                   )
                               )
                           )
                        )
                    )
                )
                (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" partnumber)))))
           )
                  (vl-load-com)
          (setq BLOCKS
          (vla-get-Blocks
           (vla-get-activedocument
            (vlax-get-acad-object)
           )
          )
         BLK (vla-Item BLOCKS partnumber)
       )
      (vla-put-explodable (vla-Item BLOCKS partnumber) :vlax-false) 
 

This makes the text of my block annotative and non-explodable

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #26 on: April 10, 2014, 08:07:30 AM »
@ HasanCAD: This is off topic. Can you start a new topic please.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: line or polyline distance
« Reply #27 on: April 10, 2014, 08:21:12 AM »
roy_43 You are talking something about this !!! Is not working ?

Try:
Code: [Select]
(defun readableAngle (ang)
  (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  (if (< (* pi 0.5) ang (* pi 1.5))
    (+ ang pi)
    ang
  )
)

(defun c:test  (/ e p ht scl len pt ang)
  ...
  ...
  (setq ang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e pt)))) ;Get angle at midpoint
  (setq ang (readableAngle ang))
  ...
  ...
)

If you are really serious about learning Lisp you should choose a different approach. You have obvious trouble with some of the basic concepts of Lisp. Although the code in your first post suggests otherwise, at times you seem to be just copy/pasting without understanding what you are doing. Maybe http://www.afralisp.net/index.php is a good starting point for you.
« Last Edit: April 10, 2014, 08:25:04 AM by roy_043 »

pedroantonio

  • Guest
Re: line or polyline distance
« Reply #28 on: April 10, 2014, 09:52:00 AM »
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

mailmaverick

  • Bull Frog
  • Posts: 493
Re: line or polyline distance
« Reply #29 on: April 10, 2014, 01:15:27 PM »
Try this :-

Code: [Select]

(defun c:test (/ e p ht scl len pt ang)
  (vl-load-com)
  (setvar "cmdecho" 0)
  (COMMAND "_layer" "_m" "dist" "_c" "3" "" "_lw" "0.30" "" "")
  (SETQ scl (GETVAR "useri1"))
  (SETQ ht (* 0.00175 SCL))
  (SETQ kl (* 0.0004 SCL))
  (COMMAND "style" "diast" "romans.shx")
  (while (> (getvar "CmdActive") 0) (command ""))
  (if (and (setq e (entsel "\n select line or polyline :"))
   (setq e (car e))
   (member (cdr (assoc 0 (entget e)))
   '("LINE" "LWPOLYLINE" "POLYLINE")
   )
      )
    (progn (setq len (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e))
;Get the length of the line/pline to its end
pt  (vlax-curve-getPointAtDist e (/ len 2.0))
;Get the point at mid of line/pline
ang (angle '(0.0 0.0 0.0)
    (vlax-curve-getFirstDeriv
      e
      (vlax-curve-getParamAtPoint e pt)
    )
     )
   )
   (setq txtent
  (entmakex (list '(0 . "TEXT")
  '(100 . "AcDbEntity")
  '(100 . "AcDbText")
  (cons 40 ht)
  '(7 . "diast")
  '(72 . 1)
  '(10 0.0 0.0 0.0)
  (if (> ang pi)
    (cons 11 (polar pt (- (/ pi 2) ang) kl))
    (cons 11 (polar pt (+ (/ pi 2) ang) kl))
  )
  (cons 1 (rtos len 2 2))
  (cons 50 (readableAngle ang))
    )
  )
   )
   (setq txtobj (vlax-ename->vla-object txtent))
   (if (> ang pi)
     (vla-put-alignment txtobj acAlignmentTopCenter)
     (vla-put-alignment txtobj acAlignmentBottomCenter)
   )
    )
    (princ
      "\nSelect a LINE or POLYLINE !! Error selection .... Try again...."
    )
  )
  (princ)
)

(defun readableAngle (ang)
  (setq ang (rem (+ (rem ang (* pi 2.0)) pi pi) (* pi 2.0)))
  (if (< (* pi 0.5) ang (* pi 1.5))
    (+ ang pi)
    ang
  )
)