Jump to content

Add text to polyline vertexes


RepCad

Recommended Posts

On 1/16/2019 at 10:26 PM, dlanorh said:

 

 

(defun c:LPV ( / ent ll ur m_pt last_v e_pt s_pt t_ht cnt v_pt)

  (cond ( (and  (setq ent (car (entsel "\nSelect Polyline to Label : ")))
                (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
          );end_and
          (vla-getboundingbox (vlax-ename->vla-object ent) 'll 'ur)

          (setq m_pt (mapcar '(lambda (x y) (/ (+ x y) 2.0)) (vlax-safearray->list ll)  (vlax-safearray->list ur))
                last_v (vlax-curve-getendparam ent)
                e_pt (vlax-curve-getendpoint ent)
                s_pt (vlax-curve-getstartpoint ent)
                t_ht (getvar 'textsize)
                t_fact 1.1
                cnt 0.0
          );end_setq
          (if (equal e_pt s_pt 0.001) (setq last_v (1- last_v)))
          (while (<= cnt last_v)
            (setq v_pt (vlax-curve-getpointatparam ent cnt))
            (entmakex (list
                          (cons 0 "TEXT")
                          (cons 7 (getvar 'textstyle))
                          (cons 40 t_ht)
                          (cons 10 (polar m_pt (angle m_pt v_pt) (+ (* t_ht t_fact) (distance m_pt v_pt))))
                          (cons 11 (polar m_pt (angle m_pt v_pt) (+ (* t_ht t_fact) (distance m_pt v_pt))))
                          (cons 1 (chr (+ 65 (fix cnt))))
                          (cons 72 1)
                          (cons 73 2)
                      );end_list
            );end_entmakex
           (setq cnt (1+ cnt))
          );end_while
        )
        ( (alert "Not a Polyline"))
  );end_cond
  (princ)	
);end_defun
(princ)

 

 

The script works fine, but  I need a modified version.

I need these features:

- At every vertex create a POINT entity;

- Instead of A..B..C labeling, I need to insert a number, like 1..2..3, but first number should be read from keyboard. So, if I enter 5 as first number, it should increment like 5..6..7..8..... every vertex of polyline.

 

Can someone modify the script, please? Thank you.

 

Link to comment
Share on other sites

Here you are, Sir!

Welcome in the forum, Ttee77!  :)

(defun c:LPV ( / ent ll ur m_pt last_v e_pt s_pt t_ht cnt v_pt)

  (cond ( (and  (setq ent (car (entsel "\nSelect Polyline to Label : ")))
                (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
          );end_and
          (vla-getboundingbox (vlax-ename->vla-object ent) 'll 'ur)

          (setq m_pt (mapcar '(lambda (x y) (/ (+ x y) 2.0)) (vlax-safearray->list ll)  (vlax-safearray->list ur))
                last_v (vlax-curve-getendparam ent)
                e_pt (vlax-curve-getendpoint ent)
                s_pt (vlax-curve-getstartpoint ent)
                t_ht (getvar 'textsize)
                t_fact 1.1
                cnt 0.0
          );end_set 
	 (setq i1 (getint "Starting number?") i1 (1- i1))
          (if (equal e_pt s_pt 0.001) (setq last_v (1- last_v)))
          (while (<= cnt last_v)
            (setq v_pt (vlax-curve-getpointatparam ent cnt))
            (entmakex (list
                          (cons 0 "TEXT")
                          (cons 7 (getvar 'textstyle))
                          (cons 40 t_ht)
                          (cons 10 (polar m_pt (angle m_pt v_pt) (+ (* t_ht t_fact) (distance m_pt v_pt))))
                          (cons 11 (polar m_pt (angle m_pt v_pt) (+ (* t_ht t_fact) (distance m_pt v_pt))))
			  ;(cons 1 (chr (+ 65 (fix cnt))))
                          (cons 1 (itoa (setq i1 (1+ i1)))) ;changed chr to integer
                          (cons 72 1)
                          (cons 73 2)
                      );end_list
            );end_entmakex
           (setq cnt (1+ cnt))
          );end_while
        )
        ( (alert "Not a Polyline"))
  );end_cond
  (princ)	
);end_defun
(princ)
Link to comment
Share on other sites

Ops! I forgot about the point!

See here a shorter version. It will put a point and it will add a number as you asked:

(defun c:pp()
  (setq pl (entget (car (entsel "Select polyline"))))
  (setq n (1- (getint "\nStarting number? ")))
  (while pl
    (setq pl (member (assoc 10 pl) pl))
    (setq a10 (car pl) pl (cdr pl))
    (entmake (list '(0 . "POINT") a10))
    (entmake (list '(0 . "TEXT") (cons 1 (itoa (setq n (1+ n)))) a10 (cons 40 (getvar "TEXTSIZE"))))
    )
  )

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...