Adding an vertex to existing polyline

Adding an vertex to existing polyline

dmitri_alyvajev
Community Visitor Community Visitor
288 Views
3 Replies
Message 1 of 4

Adding an vertex to existing polyline

dmitri_alyvajev
Community Visitor
Community Visitor

Hello everyone.

 

I have difficulties with writing LISP for adding vertex to existing polyline.

 

There is polyline with many vertices and there are known points, which are located on segments of polyline.

I need to make a LISP for adding vertex in all these points.

Below are two pictures, which illustrate the task.

 

 

dmitri_alyvajev_0-1736168303500.png

Circle center points are located right on the polyline.

Which steps I have to make to achieve next result>>

dmitri_alyvajev_1-1736168430699.png

 

Thank you in advance!!!

 

0 Likes
289 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor

@dmitri_alyvajev  hi,

 

You say you have difficulties? show us 🙏

it's more easy to draw a new pline on top (delete the existing) instead of editing after selecting the pline + 2 circles.

 

Moshe

 

0 Likes
Message 3 of 4

ВeekeeCZ
Consultant
Consultant

Here's a sub that should help. It's from Lee Mac or mostly.

 

(defun c:test ( / e p)


;; From Lee Mac's code
(defun :PAddVertex (e p / tan LM:LWVertices a b e h l n r w x z)
  
  (defun tan ( x ) (if (not (equal 0.0 (cos x) 1e-10)) (/ (sin x) (cos x))))
  
  (defun LM:LWVertices ( e )
    (if (setq e (member (assoc 10 e) e))
      (cons (list (assoc 10 e)
		  (assoc 40 e)
		  (assoc 41 e)
		  (assoc 42 e))
	    (LM:LWVertices (cdr e)))))
  
  
  
  (if (and p
	   e
	   (setq p (vlax-curve-getclosestpointto e (trans p 1 0))
		 n (vlax-curve-getparamatpoint e p))
	   )
    (if (not (equal n (fix n) 1e-8))
      (progn
	(setq e (entget e)
	      h (reverse (member (assoc 39 e) (reverse e)))
	      l (LM:LWVertices e)
	      z (assoc 210 e)
	      )
	(repeat (fix n)
	  (setq a (cons (car l) a)
		l (cdr l)))
	(setq x (car l)
	      r (- n (fix n))
	      w (cdr (assoc 40 x))
	      w (+ w (* r (- (cdr (assoc 41 x)) w)))
	      b (atan (cdr (assoc 42 x)))
	      )
	(entmod
	  (append h
		  (apply 'append (reverse a))
		  (list
		    (assoc 10 x)
		    (assoc 40 x)
		    (cons  41 w)
		    (cons  42 (tan (* r b)))
		    )
		  (list
		    (cons  10 (trans p 0 (cdr z)))
		    (cons  40 w)
		    (assoc 41 x)
		    (cons  42 (tan (* (- 1.0 r) b)))
		    )
		  (apply 'append (cdr l))
		  (list z)))))))


  (if (setq e (car (entsel "Polyline:")))
    (while (setq p (getpoint "Point: "))
      (:PAddVertex e p)))

  (princ)
  )

 

Message 4 of 4

Sea-Haven
Mentor
Mentor

Why not use Pedit has a add vertex option !

: PEDIT
Select polyline to edit [Multiple]:

Edit polyline [Edit vertices/Close/Decurve/Fit/Join/Linetype mode/Reverse direction/Spline/Taper/Width/Undo] <eXit>: E

Edit vertices [Next vertex/Previous vertex/Angle/Break/Insert vertex/Move/Regen/SElect/Straighten/Tangent/Width/eXit]: I

Location for new vertex: 
0 Likes