Show Distance between two lines at fixed interval

Show Distance between two lines at fixed interval

Anonymous
Not applicable
8,070 Views
26 Replies
Message 1 of 27

Show Distance between two lines at fixed interval

Anonymous
Not applicable

Hi,

 

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. 

 

Is there a LISP code that can do this?

 

Please help.

 

Thanks

0 Likes
Accepted solutions (1)
8,071 Views
26 Replies
Replies (26)
Message 2 of 27

devitg
Advisor
Advisor

Yes, it could be possible . Please upload a dwg sample . 

0 Likes
Message 3 of 27

Anonymous
Not applicable

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. 

0 Likes
Message 4 of 27

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this routine

 

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

0 Likes
Message 5 of 27

Anonymous
Not applicable

Thanks BeeKeeCZ! This is exactly what i wanted. Thanks for pointing out the blind spots. I will remember to merge the polylines before applying it.

Thanks a ton!! 🙂

0 Likes
Message 6 of 27

devitg
Advisor
Advisor

 

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"

 

 

 

Message 7 of 27

Anonymous
Not applicable

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

Capture.PNG

 

 

0 Likes
Message 8 of 27

ВeekeeCZ
Consultant
Consultant

Next time post the entire code and some test dwg.

 

My approach would be:

 

(foreach pnt on pl1

 - get angle (vector of pl) at pnt using: (angle '(0 0 0) (vlax-curve-getFirstDeriv path pnt))))

 - entmakex templine, example HERE

 - find all intersection points tmp vs. pl2 using the intesectwith method, example HERE

 - if there is (are) any int-pnts, draw dim

 - erase templine)

 

Good luck

 

0 Likes
Message 9 of 27

brodie.mclean
Contributor
Contributor

Hey, 

 

I know this is an old thread, but i'm wondering if this code can be modified to dimension from an Alignment to a Corridor Created Feature Line?

 

Thanks, 

 

Brodie

0 Likes
Message 10 of 27

devitg
Advisor
Advisor

Please upload your sample.dwg 

0 Likes
Message 11 of 27

brodie.mclean
Contributor
Contributor

Sorry my sample drawing has short-cut data and can't be uploaded. 

 

Here's the jist: 

 

- I have an alignment from which I have created a corridor from that has varying widths. 

- From the corridor i created a linked feature line 

- I now want to auto-dimension between the Alignment and Feature line at a specified interval. 

0 Likes
Message 12 of 27

brodie.mclean
Contributor
Contributor

Here's a dwg showing what I'm after. 

0 Likes
Message 13 of 27

devitg
Advisor
Advisor

@brodie.mclean , please check the dwg , there aren't any alignment  , and  the feature line from corridor 

 

Either it is in true size, od scale 1:1 

devitg_0-1588287485746.png

 

 

0 Likes
Message 14 of 27

Sea-Haven
Mentor
Mentor

This appears to be a CSD dwg going by the layer names, have you looked at the peg/shift option in the CSD road software.

0 Likes
Message 15 of 27

brodie.mclean
Contributor
Contributor

It's a civil3d drawing. Are you opening it Civil? it' shows up correctly on my computer. 

 

0 Likes
Message 16 of 27

devitg
Advisor
Advisor

@brodie.mclean , hi . No. I use ACAD 2018. Please save as to ACAD 2018 

 

0 Likes
Message 17 of 27

brodie.mclean
Contributor
Contributor

Does this work? 

0 Likes
Message 18 of 27

devitg
Advisor
Advisor

@brodie.mclean , no way. Sorry 

Despite it line length, differs a lot from real  

0 Likes
Message 19 of 27

Sea-Haven
Mentor
Mentor

Civ3d will make alignments as proxy objects in Autocad.so will not have access.

0 Likes
Message 20 of 27

brodie.mclean
Contributor
Contributor

Here a jist of what I'm looking for in a picture then.. 

 

0 Likes