Offset line

Offset line

bedyr
Advocate Advocate
1,049 Views
4 Replies
Message 1 of 5

Offset line

bedyr
Advocate
Advocate

Hi,

I created this lisp but I didn't go on. Anybody can help me?

I want to draw offset line along the reference  object.

 

(defun c:ofsline () 
  (setq p1 (getpoint "get first point : "))
  (setq p1x (car p1))
  (setq p1y (cadr p1))
  (setq count 1)
  (while (< count 100) 
    (setq p2 (getpoint p1 "reference line"))
    (setq p3 (getpoint "side"))
    (setq p2x (car p2))
    (setq p2y (cadr p2))
    (setq p3x (car p3))
    (setq p3y (cadr p3))
    (cond 
      ((and (< p2y p3y) (= p1x p2x) (setq p4 (list p1x (+ p2y 5)))))
      ((and (> p2y p3y) (= p1x p2x) (setq p4 (list p1x (- p2y 5)))))
      ((and (< p2x p3x) (= p1y p2y) (setq p4 (list (+ p2x 5) p1y))))
      ((and (> p2x p3x) (= p1y p2y) (setq p4 (list (- p2x 5) p1y))))
      ((and (< p2x p3x) (< p1x p3x) (< p1x p2x)) (setq p4 (list (+ p2x 5) p1y)))
      ((and (> p2x p3x) (< p1x p3x) (< P1x p2x)) (setq p4 (list (- p2x 5) p1y)))
    )
    (command "pline" p1 p4 "")
    (setq p1 p4)
    (setq count (+ count 1))
  )
)
0 Likes
1,050 Views
4 Replies
Replies (4)
Message 2 of 5

devitg
Advisor
Advisor

@bedyr For better understanding, and to get further help, please upload such sample.dwg 

 

0 Likes
Message 3 of 5

Sea-Haven
Mentor
Mentor

I wrote this for services water etc where they would swap sides maintaining an offset. Its possibly a goo

; draw offsets from points for random shape object making pline
; By Alan H AUG 2019


(defun ah:ploffs (/ offdir offd x pt1 pt2 pt3 oldsnap ssp)

  (defun drawline (/ ang pt3 obj)
    (setq ang (angle pt1 pt2))
    (if (= offdir "L")
      (setq pt3 (polar pt2 (+ ang (/ pi 2.0)) 10))
      (setq pt3 (polar pt2 (- ang (/ pi 2.0)) 10))
    )
    (setvar 'osmode 0)
    (command "line" pt1 pt2 "")
    (setq obj (entlast))
    (command "offset" offd obj pt3 "")
    (setq ssp (ssadd (entlast) ssp))
    (command "erase" obj "")
    (setq pt1 pt2)
  )

  (defun swapr-l (/)
    (if (= (strcase offdir) "L")
      (setq offdir "R")
      (setq offdir "L")
    )
    (setvar 'osmode oldsnap)
    (setq pt1 (getpoint "\nPick  next point"))
    (setq pt2 (getpoint "\nPick  next point"))
    (drawline)
  )


; starts here
; add side pick
  (setq oldsnap (getvar 'osmode))
  (setq ssp nil)

  (initget 6 "R L")
  (setq offdir (strcase (getstring "Right or  Left")))
  (setq offd (getreal "Enter offset distance"))


  (setq pt1 (getpoint "pick 1st point"))
  (setq ssp (ssadd))

  (initget 6 "1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z")
  (while (setq pt2 (getpoint "\nPick  next point or [S Swap sides]:<"))
    (cond
      ((= (type pt2) 'LIST) (drawline))
      ((= (type pt2) 'str) (swapr-l))  ; also calls drawlines
      ((= pt2 nil) (quit))
    )
    (setvar 'osmode oldsnap)
    (initget 6 "Swap")
  )

  (setq x 0)
  (repeat (- (sslength ssp) 1)
    (setvar 'filletrad 0)
    (command "fillet" (ssname ssp x) (ssname ssp (1+ x)))
    (setq x (1+ x))
  )

  (setq x 0)
  (command "pedit" (entlast) "Y" "J")
  (repeat (- (sslength ssp) 1)
    (command (ssname ssp x))
    (setq x (1+ x))
  )
  (command "" "")

  (princ)

)
(ah:ploffs)

d starting point

0 Likes
Message 4 of 5

hak_vz
Advisor
Advisor

Hi @bedyr 

We have spent a lot of time working on a solution to your problem.

Here is old post https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/offset-polyline/m-p/9608463#M401890 

 

Please provide working dwg sample that you use in practice. And in details how you really want to be solved.

Miljenko Hatlak

EESignature

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.
0 Likes
Message 5 of 5

hak_vz
Advisor
Advisor

Try this

 

(defun ppinit () (setq pp_off (getreal "\nEnter offset value >")))
(defun pp ( / old p1 p1x p1y s  rx ry sx sy) 
(if (not pp_off) (ppinit))
 (setq old (getvar 'osmode))
 (setvar 'cmdecho 0)
  (setvar 'osmode 641)
  (setq p1 (getpoint "\nget first point : "))
  (setq ss (ssadd))
  (while (setq r (getpoint p1 "\nreference line or <exit> >")) 
    (setq p1x (car p1))
    (setq p1y (cadr p1))
	(setvar 'osmode 0)
    (setq s (getpoint "side"))
    (setvar 'osmode 641)
	(setq rx (car r))
    (setq ry (cadr r))
    (setq sx (car s))
    (setq sy (cadr s))
    (cond 
      ((and (= p1x rx) (> p1y ry) (> sy ry)) (setq p2 (list p1x (+ ry pp_off))))
      ((and (= p1x rx) (> p1y ry) (> ry sy)) (setq p2 (list p1x (- ry pp_off))))
      ((and (= p1x rx) (> ry p1y) (> sy ry)) (setq p2 (list p1x (+ ry pp_off))))
      ((and (= p1x rx) (> ry p1y) (> ry sy)) (setq p2 (list p1x (- ry pp_off))))
      ((and (= p1y ry) (> rx p1x) (> rx sx)) (setq p2 (list (- rx pp_off) p1y)))
      ((and (= p1y ry) (> rx p1x) (> sx rx)) (setq p2 (list (+ rx pp_off) p1y)))
      ((and (= p1y ry) (> p1x rx) (> sx rx)) (setq p2 (list (+ rx pp_off) p1y)))
      ((and (= p1y ry) (> p1x rx) (> rx sx)) (setq p2 (list (- rx pp_off) p1y)))
      ((and (> rx p1x) (> p1y ry) (> sx rx)) (setq p2 (list (+ rx pp_off) p1y)))
      ((and (> rx p1x) (> p1y ry) (> rx sx)) (setq p2 (list (- rx pp_off) p1y)))
      ((and (> p1x rx) (> p1y ry) (> ry sy)) (setq p2 (list p1x (- ry pp_off))))
      ((and (> p1x rx) (> p1y ry) (> sy ry)) (setq p2 (list p1x (+ ry pp_off))))
      ((and (> p1x rx) (> ry p1y) (> rx sx)) (setq p2 (list (- rx pp_off) p1y)))
      ((and (> p1x rx) (> ry p1y) (> sx rx)) (setq p2 (list (+ rx pp_off) p1y)))
      ((and (> rx p1x) (> ry p1y) (> sy ry)) (setq p2 (list p1x (+ ry pp_off))))
      ((and (> rx p1x) (> ry p1y) (> ry sy)) (setq p2 (list p1x (- ry pp_off))))
    )
    (if (and p1 p2) (progn (command "pline" "non" p1 "non" p2 "") (setq ss (ssadd (entlast) ss)  p1 p2 p2 nil)))
  )
  (initcommandversion)
  (command "_.join" "_All" ss "")
  (setvar 'osmode old)
  (setvar 'cmdecho 1)
  (princ)
)

(defun c:ppinit nil (ppinit))
(defun c:pp nil (pp))

 

Use command ppinit to define offset distance.

Miljenko Hatlak

EESignature

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.
0 Likes