Author Topic: Align vertices numbers  (Read 2141 times)

0 Members and 1 Guest are viewing this topic.

slimthu

  • Guest
Align vertices numbers
« on: October 22, 2014, 02:47:00 AM »
I have this LISP routine which autonumbers vertices. Everything works great except the position of numbers. I want them to appear a bit outside of the polygon.

After running my current routine:


This is how it is supposed to work:


Code: [Select]
(defun c:vername ( / e i j m n p s )
(if (setq s (ssget '((0 . "LWPOLYLINE"))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i)))
n (cdr (assoc 210 (entget e)))
m (vlax-curve-getendparam e)
j -1
)
(while (<= (setq j (1+ j)) m)
(setq p (trans (vlax-curve-getpointatparam e j) 0 e))
(entmakex
(list
(cons 0 "TEXT")
(cons 7 (getvar 'TEXTSTYLE))
(cons 40 (getvar 'TEXTSIZE))
(cons 10 p)
(cons 11 p)
(cons 72 1)
(cons 73 2)
(cons 1 (itoa (1+ j)))
(cons 210 n)
)
)
)
)
)
(princ)
)


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Align vertices numbers
« Reply #1 on: October 22, 2014, 03:46:14 AM »
Look at the vlax-curve-getfirstderiv function.

slimthu

  • Guest
Re: Align vertices numbers
« Reply #2 on: October 22, 2014, 04:01:50 AM »
I am completely new to AutoLISP programming. Could anyone add the required code? I would be so helpful.

GP

  • Newt
  • Posts: 83
  • Vercelli, Italy
Re: Align vertices numbers
« Reply #3 on: October 22, 2014, 06:19:37 AM »
Try this:

Code: [Select]
(defun c:vername (/ s vertex_pos L_v)
    (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
    (if (setq s (car (entsel "\nSelect Polyline ")))
        (progn
            (setq vertex_pos "out") ;;;  "ins" for inside
            (setq L_v (pl_coord s))
            (num_v L_v)
        )
    )   
    (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
    (princ)
)

;*************************************************************************

(defun pl_coord (# / p_ m)
    (setq p_ (if (vlax-curve-IsClosed #)
                (fix (vlax-curve-getEndParam #))
                (1+ (fix (vlax-curve-getEndParam #)))
            )
    )
    (while (/= 0 p_)
        (setq m (cons (vlax-curve-getPointAtParam # (setq p_ (1- p_))) m))
    )
)

;*************************************************************************
; Numera i vertici della polilinea
(defun num_v ( :lst /  _a_ :pt dT nv)

    (setq dT (* (getvar 'textsize) 1.1)) ;distanza del testo dal vertice
    (if (or
           (and (LM:ListClockwise-p :lst) (= vertex_pos "out"))
           (and (null (LM:ListClockwise-p :lst)) (= vertex_pos "ins"))
        )
        (setq dT (- dT))
    )
    (setq nv 0)
    (mapcar
        (function
            (lambda (a b c)
                (setq _a_ (/ (+ (angle b c) (angle b a)) 2))
                (if (minusp (- (angle b c) (angle b a))) (setq _a_ (+ _a_ pi)))
                (setq :pt (polar b _a_ dT))
                (entmake
                    (list
                        (cons 0 "TEXT")
                        (cons 7 (getvar 'textstyle))
                        (cons 10 :pt )
                        (cons 11 :pt )
                        (cons 40 (getvar 'textsize))
                        (cons 72 1)
                        (cons 73 2)
                        (cons 1 (itoa (setq nv (1+ nv))))
                    )
                )
            )
        )
        (cons (last :lst) :lst) :lst (append (cdr :lst) (list (car :lst)))
    )
)

;*************************************************************************
;; List Clockwise-p - Lee Mac                                             
;; Returns T if the point list is clockwise oriented                     
(defun LM:ListClockwise-p ( lst )
    (minusp
        (apply '+
            (mapcar
                (function
                    (lambda ( a b )
                        (- (* (car b) (cadr a)) (* (car a) (cadr b)))
                    )
                )
                lst (cons (last lst) lst)
            )
        )
    )
)


;*************************************************************************

(vl-load-com)

;*************************************************************************

slimthu

  • Guest
Re: Align vertices numbers
« Reply #4 on: October 22, 2014, 07:13:45 AM »
Thank you so much! Would it also be possible to specify the distance from the polygon?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Align vertices numbers
« Reply #5 on: October 22, 2014, 08:25:46 AM »
Modify this line of code.

    (setq dT (* (getvar 'textsize) 1.1)) ;distanza del testo dal vertice
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.