I have a project where a cable is laid along a road. I need to show the perpendicular distance of the cable from the road centerline at every 10m interval. I cannot do it manually as the cable length is in 100s of kms. I have been using autocad for a long time but am new to LISP.
Thanks for the reply devitg. PFA the sample drawing.
I have put chainage on the cable route (red line). The black line is the road centerline. I need the perpendicular distance from the cable to the road centerline at every 10m. I have done it for the first four chainage points (from 00+000 t0 00+040) points manually to make it clear.
(vl-load-com)
(defun c:DimPl2Pl ( / en1 en2 int len stt len pt1 pt2)
(if (and (setq en1 (car (entsel "\nSelect 1st polyline (dim from): ")))
(= "LWPOLYLINE" (cdr (assoc 0 (entget en1))))
(setq en2 (car (entsel "\nSelect 2nd polyline (dim to): ")))
(= "LWPOLYLINE" (cdr (assoc 0 (entget en2))))
(setq int (getdist "\nInterval: "))
(setq len (vlax-curve-getDistAtParam en1 (vlax-curve-getEndParam en1)))
(not (initget 4))
(setq stt (cond ((getreal "\nDistance at the beginning <0>: "))
(0)))
(not (initget 4))
(setq len (cond ((getreal (strcat "\nDistance at the end <along the entire polyline = " (rtos len 2 2) ">: ")))
(len)))
)
(while (and (<= stt len)
(setq pt1 (vlax-curve-getPointAtDist en1 stt))
(setq pt2 (vlax-curve-getClosestPointTo en2 pt1)))
(command "_.DIMALIGNED"
"_none" (trans pt1 0 1)
"_none" (trans pt2 0 1)
"_none" (polar (trans pt1 0 1)
(+ (* 1.5 pi)
(angle (trans pt1 0 1) (trans pt2 0 1)))
1.5))
(setq stt (if (= stt (min (+ stt int) ; if next point is beyond the end length
len))
(+ stt int) ; then use that it because which (while) does not pass
(min (+ stt int) ; else use middle point or max
len))))
(princ "\nWrong selection. Two LWPolylines are required.")
)
(princ)
)
- make sure that the first polyline (which on would be applied the interval) is in the correct direction - in your sample is NOT!
- make sure that the both polylines are correctly joined (the second polyline in your sample is NOT)
- i would recommend flat both (3d)polylines to polylines
- I think the better result you'll get if you would dimension from the cable line, not from the axis (at least at some parts.. - dim is put at the clostest point on second polyline).
Sorry @devitg, I hope you don't mind. I just quickly adjusted some older routine of mine.
Hi BeekeeCZ , do noy worry , all help is wellcome , I just ask the OP to upload the DWG.
All poster think that with words, they can get answer .
Seem to be they think this forum is a ORACLE " A person considered to be a source of wise counsel or prophetic opinions."
Or in a rude way "NO CORPSE, NO COFFIN"
Hey BeekeeCZ, I was attempting to modify your code you created here.
I was attempting to modify it where it found a line perpendicular off of the first line you select, but keep running into a wall. See screenshot for intent.
Would appreciate any direction, thanks!
(if (and (setq en1 (car (entsel "\nSelect polyline to dimension from: ")))
(= "LWPOLYLINE" (cdr (assoc 0 (entget en1))))
(setq en2 (car (entsel "\nSelect polyline to dimension to: ")))
(= "LWPOLYLINE" (cdr (assoc 0 (entget en2))))
(setq int (getdist "\nSpecify spacing interval: "))
(setq len (vlax-curve-getDistAtParam en1 (vlax-curve-getEndParam en1)))
(not (initget 4))
(setq stt (cond ((getdist "\nSpecify offset from beginning <0>: ")) (0)))
(not (initget 4))
(setq len (cond ((getdist (strcat "\nSpecigy length of path to use for measurement <" (if (= (getvar 'measurement) 0) (rtos len 4 5) (rtos len 2 2)) ">: "))) (len)))
)
(while (and (<= stt len)
(setq pt1 (vlax-curve-getPointAtDist en1 stt))
(setq pt2 (vlax-curve-getPointAtDist en1 int))
(setq pt3 (polar (trans pt1 0 1) (+ (/ pi 2) (angle (trans pt1 0 1) (trans pt2 0 1))) 1.5))
(setq pt4 (vlax-curve-getPointAtDist en2 stt))
(setq pt5 (vlax-curve-getPointAtDist en2 int))
(setq pt6 (inters pt1 pt3 pt4 pt5 nil))
)
(command "_.DIMALIGNED"
"_none" (trans pt1 0 1)
"_none" (trans pt6 0 1)
"_none" (polar (trans pt1 0 1) (+ (* 1.5 pi) (angle (trans pt1 0 1) (trans pt6 0 1))) 1.5))
(setq stt (if (= stt (min (+ stt int) ; if next point is beyond the end length
len))
(+ stt int) ; then use the beyond len which (while) does not pass
(min (+ stt int) ; else use middle point or max
len))))
(princ "\nError. Two polylines are required.")
)