Here is solution for Case 1
If direction of newly added polyline is to wrong direction use command REVERSE on base polyline and start again.
I'll leave case 2 to someone else since you didn't provide sufficient details.
Next time you can try to write down some code and also attach dwg sample for easier work on code. If you attach screenshots it's a plus.
(defun c:nps ( / *error* take pointlist2d adoc e eo p1 p2 d1 d2 pts i rev)
(defun *error* ( msg )
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ)
)
(setvar 'cmdecho 1)
(princ)
)
(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
(defun pointlist2d (lst / ret) (while lst (setq ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
(setq e (car (entsel "\nSelect polyline >")))
(cond
((and e)
(setq eo (vlax-ename->vla-object e))
(cond
((= (vlax-get eo 'Objectname) "AcDbPolyline")
(setq p1 (take 2(getpoint "\nSelect point >")))
(setq p2 (take 2(vlax-curve-getClosestPointTo eo p1)))
(setvar 'cmdecho 0)
(setq d1 (vlax-curve-getdistatparam eo (vlax-curve-getParamAtPoint eo p2)))
(setq pts (pointlist2d (vlax-get eo 'Coordinates)))
(setq i 0)
(while (< (vlax-curve-getDistAtPoint eo (nth i pts)) d1) (setq i(1+ i)))
(setq pts (append (take i pts)(list p2 p1)))
(entmakex
(apply 'append
(cons
(list
'(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(410 . "Model")
'(8 . "0")
'(38 . 0)
'(62 . 3)
'(67 . 0)
'(70 . 0)
(cons 90 (length pts))
)
(mapcar 'list (mapcar '(lambda (a) (cons 10 a)) pts))
)
)
)
(setvar 'cmdecho 1)
)
)
)
)
(princ)
)
Miljenko Hatlak
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.