Jump to content

Add polyline vertices at chainage points from a list


Recommended Posts

Posted

Hi, 

 

I have a Polyline that is 17km long. I need to add vertices at approximately 250 unevenly spaced points along the line. For instance, I need a point at distance from start = 175.65m, another at 186.7m, 270.6m, etc. 

 

I have tried to modify the vtxdist.lsp I found online to iterate through a list but was unable to do so. 

 

Could anyone help me out with a lisp routine which allows me to read a list from a text file, or that I can paste my list directly into the lisp code?

 

Copy of vtxdist.lsp to save you time:

 

;Add polyline vertices in intervals
;CAD Studio, www.cadstudio.cz  www.cadforum.cz
(defun C:VTXDIST ( / pline plineo pt ptpar stan int seg)
 (vl-load-com)
 (setq pline (entsel "\nSelect a polyline to divide/measure: "))
 (if pline (progn
    (setq pline (car pline))
	(setq plineo (vlax-ename->vla-object pline))
	(if (member (cdr (assoc 0 (entget pline))) '("LWPOLYLINE" "SECTION")) (progn
		(if _lastVTXDIST (initget 6 "Number")(initget 7 "Number"))
		(setq int (getdist (strcat "\nSpecify the segment size or [Number]" (if _lastVTXDIST (strcat " <" (rtos _lastVTXDIST 2) ">") "") ":")))
		 (if (eq int "Number")(progn
		  (initget 7)
		  (setq seg (getint "\nNumber of segments: "))
		  (setq int (/ (vlax-get-property plineo 'Length) seg))
		  (princ (strcat " (size: " (rtos int 2) ")"))
		 ))
		(if (not int)(setq int _lastVTXDIST)(setq _lastVTXDIST int))
		(setq stan int)
		(while (setq pt (vlax-curve-getPointAtDist plineo stan))
		  (setq ptpar (vlax-curve-getParamAtPoint plineo pt))
		  (vlax-invoke plineo 'AddVertex (1+ (fix ptpar))  (list (car pt)(cadr pt)))
		  (setq stan (+ stan int))
		);
		(princ " added.")
		(sssetfirst nil (ssadd pline))
	) ;else
	(princ " not a lwpolyline ! ")
	) ;if eq
 )) ;if pline
 (prin1)
)

 

Many thanks, 

 

Will

Posted
;Add polyline vertices in intervals
;CAD Studio, www.cadstudio.cz  www.cadforum.cz

;;https://www.cadtutor.net/forum/topic/72403-add-polyline-vertices-at-chainage-points-from-a-list/



(defun C:READVTXDIST ( / pline plineo pt ptpar stan int seg F FILEPATH LN)
 (vl-load-com)
 
 (if (and
       (setq pline (entsel "\nSelect a polyline to divide/measure: "))
       (setq FilePath (getfiled "Select TEXT file to read :"
			       (getvar "dwgprefix")
			       "txt"
			       4
		     )
      )
       )
   (progn
     
     
        (setq pline (car pline))
	(setq plineo (vlax-ename->vla-object pline))
     
	(if (member (cdr (assoc 0 (entget pline))) '("LWPOLYLINE" "SECTION"))
	  (progn
	    (setq f (open FilePath "r"))
;;;		(if _lastVTXDIST
;;;		  (initget 6 "Number")
;;;		  (initget 7 "Number"))
	    
;;;		(setq int (getdist (strcat "\nSpecify the segment size or [Number]" (if _lastVTXDIST (strcat " <" (rtos _lastVTXDIST 2) ">") "") ":")))
	    
;;;		 (if (eq int "Number")
;;;		   (progn
;;;		  (initget 7)
;;;		  (setq seg (getint "\nNumber of segments: "))
;;;		  (setq int (/ (vlax-get-property plineo 'Length) seg))
;;;		  (princ (strcat " (size: " (rtos int 2) ")"))
;;;		 ))


	    
;;;		(if (not int)(setq int _lastVTXDIST)(setq _lastVTXDIST int))
	    
;;;		(setq stan int)
	    
		(while (setq ln (read-line f))
		  (IF (<= (atof ln) (vla-get-length plineo) )
		  (progn
		    
		  (setq pt (vlax-curve-getPointAtDist plineo (atof ln)))
		  
		  (setq ptpar (vlax-curve-getParamAtPoint plineo pt))
		  
		  (vlax-invoke plineo 'AddVertex (1+ (fix ptpar))  (list (car pt)(cadr pt)))
		  
;;;		  (setq stan (+ stan int))
		  )
		  )
		);  	(while 

	    
		(princ " added.")
		(sssetfirst nil (ssadd pline))
	) ;else
	(princ " not a lwpolyline ! ")
	) ;if eq
 )) ;if pline
 (prin1)
)

 

 

 

AAaa.txt

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...