Labeling lines with their lengths,
I got the attached lisp file from the web which automatically labels the lines with their length. Could you please help in resulting the values of the length in the absolute values of the length instead of saying that the length is in inch. i.e, i need to remove the inch sign (") from the suffix of the length.
Thank you in advance,
Best
Jamal
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
sorry, i don't know how to use "ADDLINES.vlx"
just i need to play a bit with the lisp file to have the length in meter.
best
Jamal
@JamaL9722060 wrote:Labeling lines with their lengths,
.... Could you please help in resulting the values of the length in the absolute values of the length instead of saying that the length is in inch. i.e, i need to remove the inch sign (") from the suffix of the length.
....
Change this:
(setq tStr (rtos (vla-get-length Obj) 3 2)
to this:
(setq tStr (rtos (vla-get-length Obj) 2 2)
to have it use decimal units instead of Engineering units. If your drawing unit is a Meter, so that it's measuring the length in Meters, that change should be all you need. See the AutoLISP Reference under (rtos).
many thanks kent.
i did it but still it gives wrong length! what might be the problem?
@JamaL9722060 wrote:many thanks kent.
i did it but still it gives wrong length! what might be the problem?
....
A closer look at the code reveals that it's putting a 1 onto the beginning of the 2.00 actual value. I think if you did more lines, the next one would have a 2 tacked onto the beginning of it, and the next one a 3, etc. I haven't studied it enough to know what that might be for (I'm guessing to sequence the lengths, but it seems to be used strangely), but I think you can get rid of it. Using your image for the values mentioned:
....
;; (setq x 1) ; ELIMINATE THIS [no use for the X variable except for that tacked-on initial character]
....
(setq tStr (rtos (vla-get-length Obj) 2 2) ; THIS [original 3 changed to a 2] RETURNS THE "2.00" PART
....
;; (setq rnum (rtos X 2 0)) ; ELIMINATE THIS [TURNS THAT INTEGER 1 INTO A STRING "1"]
;; (setq tstr (strcat " " rnum tStr)) ; ELIMINATE THIS [joins a space and "1" and "2.00" together]
....
;; (setq x (+ x 1)) ; ELIMINATE THIS
I would think if the intent is to put sequence numbers before the length values, it would put the space between rnum and tStr to separate them, but again, I haven't dug very deeply into it. But eliminating that (strcat) should leave the "2.00" alone as the text content.
Jamal
Here is working program I use
See if this good enough on your end
{code}
;;------------------------------------ DIMLP.LSP ----------------------------------;;
;; fixo () 2012 * all rights released
;; edited 3/3/12
(defun C:DIMLP(/ *error* acsp adoc ang curve deriv en mid mp ppt1 ppt2 prex sset txh txt txt1 txtpt1)
(defun *error* (msg)
(vla-endundomark (vla-get-activedocument
(vlax-get-acad-object))
)
(cond ((or (not msg)
(member msg '("console break" "Function cancelled" "quit / exit abort"))
)
)
((princ (strcat "\nError: " msg)))
)
(princ)
)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object))
acsp (vla-get-block(vla-get-activelayout adoc)))
(vla-startundomark adoc )
(setq txh (getvar "dimtxt")
prex (getvar "dimdec")
)
(while (not sset)
(setq sset (ssget '((0 . "*LINE")))
)
)
(while (setq en (ssname sset 0))
(setq curve (vlax-ename->vla-object en))
(setq txt (if (= (getvar "measurement") 0)
(rtos (vla-get-length curve) 3 2)
(rtos (vla-get-length curve) 2 prex))
)
(setq mid (/ (abs (- (vlax-curve-getendparam curve)
(vlax-curve-getstartparam curve))) 2.)
mp (vlax-curve-getpointatparam curve mid)
deriv (vlax-curve-getfirstderiv
curve
(vlax-curve-getparamatpoint curve mp))
)
(if (zerop (cadr deriv))
(setq ang 0)
(setq ang (- (/ pi 2) (atan (/ (car deriv) (cadr deriv)))))
)
(if (< (/ pi 2) ang (* pi 1.5))
(setq ang (+ pi ang))
)
(setq ppt1 (polar mp (+ ang (/ pi 2)) (* txh 0.5))
)
(setq txtpt1 (vlax-3d-point (trans ppt1 1 0)))
(setq txt1 (vla-addtext acsp txt txtpt1 txh))
(vla-put-alignment txt1 acalignmentbottomcenter)
(vla-put-textalignmentpoint txt1 txtpt1)
(vla-put-insertionpoint txt1 (vla-get-textalignmentpoint txt1))
(vla-put-rotation txt1 ang)
(ssdel en sset)
)
(*error* nil)
(princ)
)
(princ "\n\t---\tStart command with \"DIMLP\"\t---")
(princ)
(or (vl-load-com)
(princ))
;;------------------------------------ code end ----------------------------------;;
{code}
~'J'~
Thank you guys for the help.
I’m not sure guys if your time permits to send me the lisp file (that does the labeling) with the correct code. I got totally frustrated in trying to do it. It seems not to work with me.
Appreciated
Jamal
Perfect. finally it did work. just i needed to replace the "2" by "3" as Kent advised to have the kength without the inch sign.
(rtos (vla-get-length curve) 2 2)
many thanx Hallex. that's great.
best
Jamal
Glad you got it to work
Happy computing 🙂
~'J'~
Thanks for the support bro
Cheers 🙂
~'J'~
Hi Hallex,
It is me again.
Could you please indicate how can I modify the code so that:
Many thanks
Jamal
Try this code instead
{code}
;;------------------------------------ DIMLP.LSP ----------------------------------;;
;; fixo () 2012 * all rights released ;; edited 3/3/12 ;; edited 3/5/12
(defun C:DIMLP(/ *error* acsp adoc ang curve deriv en mid mp ppt1 ppt2 prex sset txh txt txt1 txtpt1) (defun *error* (msg) (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)) ) (cond ((or (not msg) (member msg '("console break" "Function cancelled" "quit / exit abort")) ) ) ((princ (strcat "\nError: " msg))) )
(princ) ) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) acsp (vla-get-block(vla-get-activelayout adoc)))
(vla-startundomark adoc ) (setq txh (getvar "dimtxt") prex (getvar "dimdec")
) (while (not sset) (setq sset (ssget '((0 . "*LINE"))) ) ) (while (setq en (ssname sset 0)) (setq curve (vlax-ename->vla-object en)) (setq txt (if (= (getvar "measurement") 0) (rtos (vla-get-length curve) 3 2) (rtos (vla-get-length curve) 2 prex))
) (setq mid (/ (abs (- (vlax-curve-getendparam curve) (vlax-curve-getstartparam curve))) 2.) mp (vlax-curve-getpointatparam curve mid)
deriv (vlax-curve-getfirstderiv curve (vlax-curve-getparamatpoint curve mp)) )
(if (zerop (cadr deriv)) (setq ang 0) (setq ang (- (/ pi 2) (atan (/ (car deriv) (cadr deriv))))) )
(if (< (/ pi 2) ang (* pi 1.5)) (setq ang (+ pi ang)) ) ;;; (setq ppt1 (polar mp (+ ang (/ pi 2)) (* txh 0.5)) ;;; ) (setq ppt1 (polar mp (+ ang (/ pi 2)) 0.15) ) (setq txtpt1 (vlax-3d-point (trans ppt1 1 0)))
;;; (setq txt1 (vla-addtext acsp txt txtpt1 txh))
(setq txt1 (vla-addtext acsp (strcat "L=" (strcat txt "m")) txtpt1 txh)) (vla-put-alignment txt1 acalignmentbottomcenter) (vla-put-textalignmentpoint txt1 txtpt1) (vla-put-insertionpoint txt1 (vla-get-textalignmentpoint txt1)) (vla-put-rotation txt1 ang)
(ssdel en sset)
) (*error* nil) (princ) ) (princ "\n\t---\tStart command with \"DIMLP\"\t---") (princ) (or (vl-load-com) (princ)) ;;------------------------------------ code end ----------------------------------;;
{code}
~'J'~
Please try ADDLINES.vlx, LAYERS.vlx and ALTEXT.vlx, use command APPLOAD to load vlx file if you don't know how to use vlx file in AutoCAD.
Following steps below to quickly label all lines as you expected.
1. Set up a new layer and set it as the current layer.
2. Set up proper Units and Precision (use command UNITS)
3. Use command ADDLINES to add length notation to all lines/plines. In the set up dialogue, do not select "Show bearing" and "Segment number", input a negative number in "Gap between text and object", you may need try different gap values to get desired result. Ensure "Orientation" is "Aligned"
4. Use command LI in LAYERS.vlx to isolate the new layer.
5. Use command ALTEXT to add prefix "L = "and suffix " m" to all new notations.
6. Use command LAYERP to retrieve previous layer status.
The result is exactly what you need, with prefix and suffix, with length notation at the bottom and right side of the object, and also you can control the gap by adjusting the gap value in Step 3.
3wood
Hi Hallex,
the code provided sounds not to work. i got the error shown in the screenshot below
best
Jamal
Try again I added hard code gap value of 0.15
~'J'~
As an alternative you can use a Dynamic Block.
Take care of scale. The correct way is to use it at scale 1, uniform.
It has a huge advantage if you need to extract data and put it in a table.
Many thanks Hallex.
The lisp file working very will but it does still show the inch sign (") and doesn't show the length UNDER or to the RIGHT of the measured line.
how can we decrease/increase the gap?
best
Jamal