Originally Posted by
Abusaru
Hi Bruno,
one last update what if I want to show the length of the selected lines at the end of each line instead of the x or y. or at an offset distance along with the x or y like. x et end of the line and distance at 2 units away from the x value. I tried using the midlength lisp from leemac to modify your code to get the distances on the same layer but no success.
Thanks
A change for exemple for length with field.
Code:
(vl-load-com)
(defun c:label_length ( / l_var js htx AcDoc Space nw_style n obj ename dxf_ent pt_start pt_end deriv alpha nw_obj)
(setq l_var (mapcar 'getvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS")))
(mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") '(4 3 2 2))
(princ "\nSelect lines.")
(while (null (setq js (ssget (list
'(0 . "*POLYLINE,LINE,ARC,CIRCLE")
(cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
(cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
'(-4 . "<NOT")
'(-4 . "&")
'(70 . 112)
'(-4 . "NOT>")
))))
(princ "\nSelection is empty or isn't LINE,POLYLINE,ARC or CIRCLE!")
)
(initget 6)
(setq htx (getdist (getvar "VIEWCTR") (strcat "\nSpecify text height <" (rtos (getvar "TEXTSIZE")) ">: ")))
(if htx (setvar "TEXTSIZE" htx))
(setq
AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
Space
(if (= 1 (getvar "CVPORT"))
(vla-get-PaperSpace AcDoc)
(vla-get-ModelSpace AcDoc)
)
)
(vla-startundomark AcDoc)
(cond
((null (tblsearch "STYLE" "ELEV_ARIAL_1"))
(setq nw_style (vla-add (vla-get-textstyles AcDoc) "ELEV_ARIAL_1"))
(mapcar
'(lambda (pr val)
(vlax-put nw_style pr val)
)
(list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
(list (strcat (getenv "windir") "\\fonts\\arial.ttf") 0.0 0.0 1.0 0.0)
)
)
)
(repeat (setq n (sslength js))
(setq
obj (ssname js (setq n (1- n)))
ename (vlax-ename->vla-object obj)
dxf_ent (entget obj)
pt_start (vlax-curve-GetStartPoint ename)
pt_end (vlax-curve-GetEndPoint ename)
deriv (vlax-curve-getFirstDeriv ename (vlax-curve-getStartParam ename))
alpha (- (atan (cadr deriv) (car deriv)) (angle '(0 0 0) (getvar "UCSXDIR")))
)
(if (and (< alpha (* pi 0.5)) (> alpha (* pi 1.5))) (setq alpha (+ alpha pi)))
(setq nw_obj
(vla-addMtext Space
;(vlax-3d-point (setq pt (polar pt_start (+ alpha (* pi 0.5)) (getvar "TEXTSIZE"))))
(vlax-3d-point pt_start)
0.0
(strcat
"{\\fArial|b0|i0|c0|p34;"
"%<\\AcObjProp.16.2 Object(%<\\_ObjId "
(itoa (vla-get-ObjectID ename))
">%)."
(cond
((eq (vla-get-ObjectName ename) "AcDbArc")
"ArcLength"
)
((eq (vla-get-ObjectName ename) "AcDbCircle")
"Circumference"
)
(T
"Length"
)
)
" \\f \"%lu2%pr2%ps[L=,"
"m]\">%"
)
)
)
(mapcar
'(lambda (pr val)
(vlax-put nw_obj pr val)
)
(list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
;(list 8 (getvar "TEXTSIZE") 5 pt "ELEV_ARIAL_1" (cdr (assoc 8 dxf_ent)) alpha)
(list 5 (getvar "TEXTSIZE") 5 pt_start "ELEV_ARIAL_1" (cdr (assoc 8 dxf_ent)) alpha)
)
)
(vla-endundomark AcDoc)
(mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") l_var)
(prin1)
)