@bedyr Here is finalized code, at least from my side. It works as follows:
1) Create lines from objects that you want to join that are perpendicular to object you are offsetting from so that this lines finish at that object
2) Star to create offset polyline starting from a point where first joining line touches object you are offsetting from, and finishes at similar point at the end. Finish this sequence with <enter>
3) Code will start commands TRIM and JOIN to trim or extend joining lines and finaly to join all segments into a single polyline. Command TRIM have option to extend a line when <shift> is pressed, so follow command options in console.
This is from my perspective the best I can do, and I hope this will work for you. It is not fully automated as you would like but I guess you get used to way it works.
(defun c:pp ( / off ss p1 p2 s m enr seg seglist p1 p2 p3 p4 i n int ptlist fst lst i k n *error* point2d perperdicular_from_point_to_line)
;Creates polyline that is offested to left or right from object egdes
;Author: hak_vz (27.06.2020.)
(defun *error* (msg)
;(vl-bt)
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
(progn
(princ (strcat "\nOops an Error : ( " msg " ) occurred."))
)
)
(setvar 'osmode old)
(setvar 'cmdecho 1)
(princ)
)
(defun point2d (pt) (list (car pt) (cadr pt)))
(defun perperdicular_from_point_to_line (lin1 lin2 p / x1 y1 x2 y2 x3 y3 k m n ret)
;returns point on a line (line1 line2) as a perpendicular projection from point p
(mapcar 'set '(x1 x2 x3) (mapcar 'car (list lin1 lin2 p)))
(mapcar 'set '(y1 y2 y3) (mapcar 'cadr (list lin1 lin2 p)))
(setq
m (-(*(- y2 y1) (- x3 x1))(*(- x2 x1) (- y3 y1)))
n (+(* (- y2 y1)(- y2 y1))(*(- x2 x1)(- x2 x1)))
)
(cond
((/= n 0.0)
(setq
k (/ m n)
ret (list(- x3 (* k(- y2 y1)))(+ y3 (* k(- x2 x1))))
)
)
)
ret
)
(setq old (getvar 'osmode))
(setvar 'cmdecho 0)
(setvar 'osmode 1)
(setq
off (getreal "\nEnter offset value >")
ptlist nil
ss (ssadd)
p1 (point2d(getpoint "\nSelect 1. point >"))
p2 (point2d(getpoint "\nSelect 2. point >"))
k p2
)
(setvar 'osmode 0)
(setq
s (point2d(getpoint "\nPick side> "))
m (perperdicular_from_point_to_line p1 p2 s)
)
(command "_.line" p1 p2 "")
(command "_.move" (entlast) "" m (polar m (angle m s) off))
(setq
p1 (mapcar '+ p1 (mapcar '- (polar m (angle m s) off) m))
p2 (mapcar '+ p2 (mapcar '- (polar m (angle m s) off) m))
seg (mapcar 'point2d (list p1 p2))
fst (car seg)
)
(ssadd (entlast) ss)
(setq
seglist (cons seg seglist)
p1 k
p2 nil
)
(setvar 'osmode 1)
(while (and (setq p2 (getpoint "\nSelect 2. point >")))
(setq p2 (point2d p2) k p2)
(setvar 'osmode 0)
(setq s (point2d(getpoint "\nPick side> ")))
(setq m (perperdicular_from_point_to_line p1 p2 s))
(command "_.line" p1 p2 "")
(command "_.move" (entlast) "" m (polar m (angle m s) off))
(setq p1 (mapcar '+ p1 (mapcar '- (polar m (angle m s) off) m)))
(setq p2 (mapcar '+ p2 (mapcar '- (polar m (angle m s) off) m)))
(ssadd (entlast) ss)
(setq seg (mapcar 'point2d (list p1 p2)))
(ssadd (entlast) ss)
(setq seglist (cons seg seglist))
(setq p1 k p2 nil)
(setvar 'osmode 1)
)
(setq lst (cadr seg))
(setq seglist (reverse seglist))
(setq i 0 n (- (length seglist) 1))
(while (< i n)
(setq seg1 (nth i seglist) seg2 (nth (+ i 1) seglist))
(setq p1 (car seg1) p2 (cadr seg1) p3 (car seg2) p4 (cadr seg2))
(setq int (inters p1 p2 p3 p4 nil) ptlist (cons int ptlist))
(setq i (+ i 1))
)
(setvar 'osmode 0)
(setq ptlist (reverse ptlist))
(command "_.erase" ss "")
(command "_.pline" fst)
(setvar 'osmode old)
(setvar 'cmdecho 1)
(while ptlist (command (car ptlist)) (setq ptlist (cdr ptlist)))
(command lst "")
(princ "\nCommand TRIM is started. Cut or extend connecting lines or hit <enter> to continue")
(command "_.trim" (entlast) "")
(while (> (getvar 'cmdactive) 0) (command pause))
(princ "\nCommand JOIN is started. Select segments to join into single polyline or hit <enter> to exit")
(command "_.join" (entlast))
(while (> (getvar 'cmdactive) 0) (command pause))
(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.