Jump to content

Recommended Posts

Posted

hi guys, 
how can i add alphabet text to vertexes of polyline by select one polyline?? , as same below image

 

can someone help me?

 

1634491768_Screenshot(897).png.130d2f5438e0cf396049b5ab6c478ec6.png

 

Posted

What happens if there are 567 vertices in the polyline? :book:

Posted (edited)

hi,,, all polyline  have maximum  8 or 10 vertexes on my drawing.

Edited by amir0914
Posted

Try this, down and dirty and NOT tested as I have No access to AutoCAD at the moment.

(defun c:LPV ( / t_lst ent last_v cnt )

 	(setq t_lst (list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "M" "N"))
	
  (cond ( (and 	(setq ent (car (entsel "\nSelect Polyline to Label : ")))
		        (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
		  )
		  (setq last_v (vlax-curve-getendparam ent)
			    cnt 0.0
		  )
		  (while (<= cnt last_v)
			(entmakex  (list
						    (cons 0 "TEXT")
							(cons 7 (getvar 'textstyle))
							(cons 40 (getvar 'textsize))
							(cons 10 (vlax-curve-getpointatparam ent cnt))
							(cons 1 (nth (fix cnt) t_lst))
						)
			)
			(setq cnt (1+ cnt))
		  )
		)
  )
  (princ)	
)
(princ)

 

  • Like 1
Posted

Tested and revised.

 

(defun c:LPV ( / t_lst ent last_v e_pt s_pt cnt )

  (setq t_lst (list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "M" "N"))
	
  (cond ( (and 	(setq ent (car (entsel "\nSelect Polyline to Label : ")))
				(= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
		  )
				(setq last_v (vlax-curve-getendparam ent)
                      e_pt (vlax-curve-getendpoint ent)
                      s_pt (vlax-curve-getstartpoint ent)
					  cnt 0.0
				)
                (if (equal e_pt s_pt 0.001) (setq last_v (1- last_v)))
				(while (<= cnt last_v)
					  (entmakex	(list
													(cons 0 "TEXT")
													(cons 7 (getvar 'textstyle))
													(cons 40 (getvar 'textsize))
													(cons 10 (vlax-curve-getpointatparam ent cnt))
													(cons 1 (nth (fix cnt) t_lst))
												)
						)
						(setq cnt (1+ cnt))
					)
				)
  )
  (princ)	
)
(princ)

 

  • Like 1
Posted

Thank you dlanorh

That's what I want, is that possible to add alphabet text by select vertex on one polyline ? maybe i won't add text to all vertexes, it means i want to select vertexes , then program add alphabet text for only my selected vertex on one polyline...is it possible??

Posted

Hi,

Try this.

(defun c:Test ( / pnt ltr)
  (setq ltr 64)
  (while (setq pnt (getpoint "\nSpecify a point :"))
    (entmake (list '(0 . "TEXT") (cons 10 (trans pnt 0 1)) (cons 40 (getvar 'TEXTSIZE)) (cons 7 (getvar 'TEXTSTYLE))
                   (cons 1 (chr (if (= (setq ltr (1+ ltr)) 91) (setq ltr 65) ltr))))
             )
    )
  (princ)
  )

 

  • Like 2
Posted (edited)
18 hours ago, dlanorh said:

What happens if there are 567 vertices in the polyline? :book:

 

Below is a solution defining two commands (LPNT & LVTX) to label an arbitrary number of selected points, or a set of polylines with an arbitrary number of vertices:

(defun c:lpnt ( / ocs pnt str )
    (setq ocs (trans '(0 0 1) 1 0 t)
          str ""
    )
    (while (setq pnt (getpoint (strcat "\nSpecify point \"" (setq str (LM:alpha++ str)) "\" <exit>: ")))
        (entmaketext (trans pnt 1 ocs) str ocs)
    )
    (princ)
)

(defun c:lvtx ( / enx idx ocs sel str )
    (if (setq sel (ssget '((0 . "LWPOLYLINE"))))
        (repeat (setq idx (sslength sel))
            (setq idx (1- idx)
                  enx (entget (ssname sel idx))
                  ocs (cdr (assoc 210 enx))
                  str ""
            )
            (foreach dxf enx
                (if (= 10 (car dxf))
                    (entmaketext (cdr dxf) (setq str (LM:alpha++ str)) ocs)
                )
            )
        )
    )
    (princ)
)

(defun entmaketext ( ins str ocs )
    (entmake
        (list
           '(000 . "TEXT")
            (cons 010 ins)
            (cons 011 ins)
            (cons 001 str)
            (cons 040 (getvar 'textsize))
            (cons 007 (getvar 'textstyle))
            (cons 050 (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 ocs t)))
           '(072 . 1)
           '(073 . 2)
            (cons 210 ocs)
        )
    )
)

;; Alpha++  -  Lee Mac
;; Increments an uppercase alphabetical string by one, e.g. AZ => BA
;; a - [str] uppercase alphabetical string

(defun LM:alpha++ ( a / n )
    (if (= "" a)
        "A"
        (if (= "Z" (substr a (setq n (strlen a))))
            (strcat (LM:alpha++ (substr a 1 (1- n))) "A")
            (strcat (substr a 1 (1- n)) (chr (1+ (ascii (substr a n)))))
        )
    )
)

(princ "\n\"LPNT\" to label points | \"LVTX\" to label vertices")
(princ)

The commands should also operate successfully under all UCS & View settings.

Edited by Lee Mac
  • Like 2
Posted

Thanks you Tharwat and leemac, 

my problem is resolved, but Can you change code or add new code to add text outside of polyline,  like below image : 

 

Screenshot (902).png

Posted
10 minutes ago, amir0914 said:

Can you change code or add new code to add text outside of polyline

 

Whilst this is possible when labelling all vertices of a polyline (since the program can calculate the offset direction using the direction of the surrounding polyline segments), when supplied only with a point, the appropriate offset direction cannot be determined.

Posted
5 hours ago, amir0914 said:

 

Can you change code or add new code to add text outside of polyline,  like below image : 

 

 

If you select a single vertex does this vertex get the letter "A" or the letter of the vertex parameter (i.e. if it is the 3rd vertex in the polyline it would get the letter "C")?

 

This is the revised code to place the text outside the polyline for all vertices. I will try to incorporate a single vertex when I have the answer to the above question.

 

(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)

 

  • Like 1
Posted

Hi, Thank you dlanorh and also lee mac , I don't say to select single vertex, I mean that select several vertices that I want to add text, then program list coordinates of those vertices and then add text to selected vertices outside of polyline, (your last program is working but don't need to add text all vertices) (I hope I been able to express my meaning)

 

Posted (edited)
18 hours ago, amir0914 said:

Thanks you Tharwat and leemac, 

my problem is resolved, but Can you change code or add new code to add text outside of polyline,  like below image :

 

Screenshot (902).png

 

 

Offset the POLYLINE outside (or required side) , Use LeeMac'S  Code. Erase the outside or unwanted POLYLINE.

 

Thanks to LeeMac, Tharwat and dianorh for the codes.

 

Edited by MURAl_KMD
  • Thanks 1
Posted
3 hours ago, MURAl_KMD said:

Offset the POLYLINE outside (or required side) , Use LeeMac'S  Code. Erase the outside or unwanted POLYLINE.

 

Thanks to LeeMac, Tharwat and dianorh for the codes.

 

A good suggestion, and you're welcome. :thumbsup:

  • Thanks 1
Posted
11 hours ago, amir0914 said:

Hi, Thank you dlanorh and also lee mac , I don't say to select single vertex, I mean that select several vertices that I want to add text, then program list coordinates of those vertices and then add text to selected vertices outside of polyline, (your last program is working but don't need to add text all vertices) (I hope I been able to express my meaning)

 

 

Sorry, You've lost me. Attach a drawing saved in AutoCAD2010 format showing what you want. I'm unsure if you want the coords as tex, a letter as text or some other combination.

Posted

Hi, thank you all, I used MURAl_KMD's recommendation and my problem is resolved. (sorry for delay in replying)

Posted

Another idea as its a simple shape not a "U" shape then a average centroid could be found quickly so this would give a direction for the text cen pt -> pt angle just use co-ords of pline. As you pick a point it also picks the pline hence co-ords. Just use a radial offset point for the text location it could check the brg and offset more to make text correct offset to outside with a bit of a fuzzy factor. Technically could look at  brgs of the two matching line edges and get a 1/2 angle.

  • Like 1
  • 5 months later...
Posted

 

Hey friend, can anyone help me. How do I add alfabhet text to the polyline.

alfabet_autolisp.jpg

Posted
8 hours ago, kallderraid said:

 

Hey friend, can anyone help me. How do I add alfabhet text to the polyline.

alfabet_autolisp.jpg

 

Judging from your image you wish to label the polyline segment. Is that correct and, if so, on the inside or outside?

Posted
On 7/9/2019 at 7:03 PM, dlanorh said:

 

Judging from your image you wish to label the polyline segment. Is that correct and, if so, on the inside or outside?

 

I want to give letters and labels outside the line

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...