how to write length value on the polyline

This widget could not be displayed.

how to write length value on the polyline

Anonymous
Not applicable
automaticaly?
I have 5.000+ polylines and must, for one selfish reason, have all length
writen on the each polylines?
FIELD has useful for few plines, but takes too long, I must select each
plines and select
object, length, etc.

this text/number value can be, I saw, on the middle vertex of the pline.

some lisp, vba or something what I don't know yet was apreciated.
thx.
0 Likes
Reply
2,081 Views
8 Replies
Replies (8)

Anonymous
Not applicable
Hi pluton

Try this one:

;; helper function to calculate text angle
(defun alg-ang (obj pnt)
(setq tang (angle '(0. 0. 0.)(vlax-curve-getfirstderiv
obj
(vlax-curve-getparamatpoint
obj
pnt
)
)
)
)

(if (and (> tang 1.6) (< tang 4.6))
(setq tang (+ tang pi)))
tang
)

(defun C:lap (/ acsp axss cpt len tang txt_height txt_obj txt_pt)
(vl-load-com)

(setq acsp (vla-get-block
(vla-get-activelayout
(vla-get-activedocument
(vlax-get-acad-object)))))
(vl-cmdf "zoom" "e")
(if (ssget "_A" (list (cons 0 "*POLYLINE")))
(progn
(or (setq txt_height (getreal "\nSpecify text height <2.5>\n"))
(setq txt_height 2.5));change text height by suit
(setq axss (vla-get-activeselectionset
(vla-get-activedocument
(vlax-get-acad-object))
)
)
(vlax-for obj axss
(setq cpt
(vlax-curve-getpointatparam obj
(/ (vlax-curve-getendparam obj) 2)))
(setq txt_pt (vlax-3d-point
(polar cpt
(+ (alg-ang obj cpt) (/ pi 2))
(* txt_height 1.25))));change gap by suit
(setq len (rtos (vlax-curve-getdistatparam obj
(vlax-curve-getendparam obj)) 2 4));change units and precision by suit

(setq txt_obj (vla-addtext (vla-get-block
(vla-get-activelayout
(vla-get-activedocument
(vlax-get-acad-object))))
len txt_pt txt_height))

(vla-put-rotation txt_obj
(alg-ang obj cpt))
)
(vla-update txt_obj)
(vlax-release-object txt_obj)))
(vla-clear axss)
(vla-delete axss)
(vlax-release-object axss)

(princ)
)
(prompt "\n\t\t***\tType LAP to execute\t***")
(princ);eof


~'J'~

Anonymous
Not applicable
Hi Fatty,
I noticed a few things that should be addressed, I hope you don't mind me
pointing them out. In this bit of code:
(setq acsp (vla-get-block
(vla-get-activelayout
(vla-get-activedocument
(vlax-get-acad-object)))))

I'm guessing that you are making sure to get the Block that the polyline is
drawn in. This will not give correct results if the user is working in
Modelspace through a Paperspace viewport. This will give you the desired
result:
(setq acsp (if (= (getvar "CVPORT") 1)
(vla-get-paperspace
(vla-get-activedocument
(vlax-get-acad-object)))
(vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)))
)
)

Then later in your code you do the same thing to add the mtext. You should
just refer to the acsp variable instead:
(setq txt_obj (vla-addtext acsp len txt_pt txt_height))

Jeff

wrote in message news:5029394@discussion.autodesk.com...
Hi pluton

Try this one:

Anonymous
Not applicable
Thanks again Jeff!

Your notice is very important for me
Regards,

Fatty
0 Likes

Anonymous
Not applicable
There is corrected version
(Thanks to Jeff Mishler for the notice)
;; helper function to calculate text angle
(defun alg-ang (obj pnt)
(setq tang (angle '(0. 0. 0.)(vlax-curve-getfirstderiv
obj
(vlax-curve-getparamatpoint
obj
pnt
)
)
)
)

(if (and (> tang 1.6) (< tang 4.6))
(setq tang (+ tang pi)))
tang
)

(defun C:lap (/ acsp axss cpt len tang txt_height txt_obj txt_pt)
(vl-load-com)

(setq acsp (if (= (getvar "CVPORT") 1)
(vla-get-paperspace
(vla-get-activedocument
(vlax-get-acad-object)))
(vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)))
)
)
(vl-cmdf "zoom" "e")
(if (ssget "_A" (list (cons 0 "*POLYLINE")))
(progn
(or (setq txt_height (getreal "\nSpecify text height <2.5>\n"))
(setq txt_height 2.5));change text height by suit
(setq axss (vla-get-activeselectionset
(vla-get-activedocument
(vlax-get-acad-object))
)
)
(vlax-for obj axss
(setq cpt
(vlax-curve-getpointatparam obj
(/ (vlax-curve-getendparam obj) 2)))
(setq txt_pt (vlax-3d-point
(polar cpt
(+ (alg-ang obj cpt) (/ pi 2))
(* txt_height 1.25))));change gap by suit
(setq len (rtos (vlax-curve-getdistatparam obj
(vlax-curve-getendparam obj)) 2 4));change units and precision by suit

(setq txt_obj (vla-addtext acsp
len txt_pt txt_height))

(vla-put-rotation txt_obj
(alg-ang obj cpt))
)
(vla-update txt_obj)
(vlax-release-object txt_obj)))
(vla-clear axss)
(vla-delete axss)
(vlax-release-object axss)
(vla-regen (vla-get-activedocument
(vlax-get-acad-object)) acactiveviewport)
(princ)
)
(prompt "\n\t\t***\tType LAP to execute\t***")
(princ);eof


~'J'~

Anonymous
Not applicable
hey, nice code here!
Many people do not realize the power of the vlax-curve functions but this should remove all doubt.
I have done code that does it the hard way, by analyzing lines and arcs and tracking the distance along.
This is pretty slick.

Fatty <>
|>There is corrected version
|>(Thanks to Jeff Mishler for the notice)
|>;; helper function to calculate text angle
|>(defun alg-ang (obj pnt)
|>(setq tang (angle '(0. 0. 0.)(vlax-curve-getfirstderiv
|>obj
|>(vlax-curve-getparamatpoint
|>obj
|>pnt
|>)
|>)
|>)
|>)
|>
|>(if (and (> tang 1.6) (< tang 4.6))
|>(setq tang (+ tang pi)))
|>tang
|>)
|>
|>(defun C:lap (/ acsp axss cpt len tang txt_height txt_obj txt_pt)
|>(vl-load-com)
|>
|>(setq acsp (if (= (getvar "CVPORT") 1)
|>(vla-get-paperspace
|>(vla-get-activedocument
|>(vlax-get-acad-object)))
|>(vla-get-modelspace
|>(vla-get-activedocument
|>(vlax-get-acad-object)))
|>)
|>)
|>(vl-cmdf "zoom" "e")
|>(if (ssget "_A" (list (cons 0 "*POLYLINE")))
|>(progn
|>(or (setq txt_height (getreal "\nSpecify text height <2.5>\n"))
|>(setq txt_height 2.5));change text height by suit
|>(setq axss (vla-get-activeselectionset
|>(vla-get-activedocument
|>(vlax-get-acad-object))
|>)
|>)
|>(vlax-for obj axss
|>(setq cpt
|>(vlax-curve-getpointatparam obj
|>(/ (vlax-curve-getendparam obj) 2)))
|>(setq txt_pt (vlax-3d-point
|>(polar cpt
|>(+ (alg-ang obj cpt) (/ pi 2))
|>(* txt_height 1.25))));change gap by suit
|>(setq len (rtos (vlax-curve-getdistatparam obj
|>(vlax-curve-getendparam obj)) 2 4));change units and precision by suit
|>
|>(setq txt_obj (vla-addtext acsp
|>len txt_pt txt_height))
|>
|>(vla-put-rotation txt_obj
|>(alg-ang obj cpt))
|>)
|>(vla-update txt_obj)
|>(vlax-release-object txt_obj)))
|>(vla-clear axss)
|>(vla-delete axss)
|>(vlax-release-object axss)
|>(vla-regen (vla-get-activedocument
|>(vlax-get-acad-object)) acactiveviewport)
|>(princ)
|>)
|>(prompt "\n\t\t***\tType LAP to execute\t***")
|>(princ);eof
|>
|>
|>~'J'~
James Maeding
Civil Engineer and Programmer
jmaeding - athunsaker - com

Anonymous
Not applicable
thanks,
this group have a power.
this is what I'm searching for.


wrote in message news:5029578@discussion.autodesk.com...
There is corrected version
(Thanks to Jeff Mishler for the notice)
;; helper function to calculate text angle
(defun alg-ang (obj pnt)
(setq tang (angle '(0. 0. 0.)(vlax-curve-getfirstderiv
obj
(vlax-curve-getparamatpoint
obj
pnt
)
)
)
)

(if (and (> tang 1.6) (< tang 4.6))
(setq tang (+ tang pi)))
tang
)

(defun C:lap (/ acsp axss cpt len tang txt_height txt_obj txt_pt)
(vl-load-com)

(setq acsp (if (= (getvar "CVPORT") 1)
(vla-get-paperspace
(vla-get-activedocument
(vlax-get-acad-object)))
(vla-get-modelspace
(vla-get-activedocument
(vlax-get-acad-object)))
)
)
(vl-cmdf "zoom" "e")
(if (ssget "_A" (list (cons 0 "*POLYLINE")))
(progn
(or (setq txt_height (getreal "\nSpecify text height <2.5>\n"))
(setq txt_height 2.5));change text height by suit
(setq axss (vla-get-activeselectionset
(vla-get-activedocument
(vlax-get-acad-object))
)
)
(vlax-for obj axss
(setq cpt
(vlax-curve-getpointatparam obj
(/ (vlax-curve-getendparam obj) 2)))
(setq txt_pt (vlax-3d-point
(polar cpt
(+ (alg-ang obj cpt) (/ pi 2))
(* txt_height 1.25))));change gap by suit
(setq len (rtos (vlax-curve-getdistatparam obj
(vlax-curve-getendparam obj)) 2 4));change units and precision by suit

(setq txt_obj (vla-addtext acsp
len txt_pt txt_height))

(vla-put-rotation txt_obj
(alg-ang obj cpt))
)
(vla-update txt_obj)
(vlax-release-object txt_obj)))
(vla-clear axss)
(vla-delete axss)
(vlax-release-object axss)
(vla-regen (vla-get-activedocument
(vlax-get-acad-object)) acactiveviewport)
(princ)
)
(prompt "\n\t\t***\tType LAP to execute\t***")
(princ);eof


~'J'~
0 Likes

Anonymous
Not applicable

thanks guys!

nice tool!!

z3rch

0 Likes

Kent1Cooper
Consultant
Consultant

If you'd like one that works on more than just Polylines, go to the thread that contains >>this Post<<, where there's one that puts the label at the middle  of the object's length.  But earlier in that thread are others that put it at the beginning [one of which may be the same as in this thread -- I haven't compared in detail].  Some are for Lines only, some for Polylines, and mine at the linked Post works on any kind of finite-length object with linearity.

Kent Cooper, AIA
0 Likes