Author Topic: Offset polyline from coordinates - Lisp  (Read 6972 times)

0 Members and 1 Guest are viewing this topic.

venkat241

  • Guest
Offset polyline from coordinates - Lisp
« on: February 14, 2013, 10:52:30 AM »
Dear All,

I want to draw offset polyline to a reference polyline from offset widths LHS or RHS to reference polyline.

I want to draw offset lines w.r.t coordinates of reference line instead of Station, beacause my reference line is not straight one but combination of lines and arc.


To understand my problem, iam attaching herewith the data for ready reference.

Regards

Venkat

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Offset polyline from coordinates - Lisp
« Reply #1 on: February 14, 2013, 01:06:14 PM »
Maybe this will get you started  :-) .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _addlwpolyline _angleatpoint _readfile _parse a data e file l l1 l2 pt)
  2.   (defun _readfile (filename / handle result stream)
  3.     (cond ((and (eq 'str (type filename)) (setq handle (open filename "r")))
  4.            (while (setq stream (read-line handle)) (setq result (cons stream result)))
  5.            (close handle)
  6.            (reverse result)
  7.           )
  8.     )
  9.   )
  10.   (defun _addlwpolyline (layer width ptlst 0or1)
  11.                      (list (list '(0 . "LWPOLYLINE")
  12.                                  (cons 100 "AcDbEntity")
  13.                                  (cons 8 layer)
  14.                                  (cons 100 "AcDbPolyline")
  15.                                  (cons 90 (length ptlst))
  16.                                  (cons 43 width)
  17.                                  (cons 38 (caddr (trans '(0 0 0) 1 (trans '(0. 0. 1.) 1 0))))
  18.                                  (cons 70 0or1)
  19.                            )
  20.                            (mapcar '(lambda (x) (list 10 (car x) (cadr x))) ptlst)
  21.                            (list (cons 210 (trans '(0. 0. 1.) 1 0)))
  22.                      )
  23.               )
  24.     )
  25.   )
  26.   (defun _angleatpoint (ename pt / ang clpt e param)
  27.     (if (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list ename))))
  28.              (setq clpt (vlax-curve-getclosestpointto ename pt))
  29.              (setq param (vlax-curve-getparamatpoint ename clpt))
  30.              (setq ang (angle '(0 0) (vlax-curve-getfirstderiv ename param)))
  31.         )
  32.       ang
  33.     )
  34.   )
  35.   (defun _parse (del str / p result)
  36.     (if (vl-string-search del str)
  37.       (progn (while str
  38.                (setq p (vl-string-search del str))
  39.                (setq result (cons (substr str 1 p) result))
  40.                (if p
  41.                  (setq str (substr str (+ 1 p (strlen del))))
  42.                  (setq str nil)
  43.                )
  44.              )
  45.              (vl-remove "" (reverse result))
  46.       )
  47.       str
  48.     )
  49.   )
  50.   (if (and (setq e (car (entsel "\nPick center line: ")))
  51.            (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list e))))
  52.            (setq file (getfiled "Pick CSV !<--must be CSV! File" (getvar 'dwgprefix) "csv" 0))
  53.            (setq data (_readfile file))
  54.       )
  55.     (progn (foreach line data
  56.              (setq l (_parse "," line))
  57.              ;; If the line has 7 items and they are all numbers rock and roll
  58.              (if (and (= (length l) 7) (vl-every '(lambda (x) (numberp (read x))) l))
  59.                (progn (setq pt (list (read (nth 2 l)) (read (nth 3 l))))
  60.                       (setq a (+ (/ pi 2.) (_angleatpoint e pt)))
  61.                       (setq l1 (cons (list pt (polar pt a (read (nth 5 l)))) l1))
  62.                       (setq l2 (cons (list pt (polar pt a (read (last l)))) l2))
  63.                )
  64.              )
  65.            )
  66.            (_addlwpolyline "LHS" 0 (mapcar 'cadr l1) 0)
  67.            (foreach p l1
  68.              (entmakex (list '(0 . "LINE")
  69.                              '(100 . "AcDbEntity")
  70.                              '(8 . "LHS")
  71.                              '(100 . "AcDbLine")
  72.                              (cons 10 (car p))
  73.                              (cons 11 (cadr p))
  74.                        )
  75.              )
  76.            )
  77.            (_addlwpolyline "RHS" 0 (mapcar 'cadr l2) 0)
  78.            (foreach p l2
  79.              (entmakex (list '(0 . "LINE")
  80.                              '(100 . "AcDbEntity")
  81.                              '(8 . "RHS")
  82.                              '(100 . "AcDbLine")
  83.                              (cons 10 (car p))
  84.                              (cons 11 (cadr p))
  85.                        )
  86.              )
  87.            )
  88.     )
  89.   )
  90.   (princ)
  91. )
« Last Edit: February 14, 2013, 01:12:11 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

venkat241

  • Guest
Re: Offset polyline from coordinates - Lisp
« Reply #2 on: February 15, 2013, 09:20:12 AM »

Dear ronjonp,

Thank You very much.

Rgds

Venkat

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Offset polyline from coordinates - Lisp
« Reply #3 on: February 15, 2013, 09:27:08 AM »

Dear ronjonp,

Thank You very much.

Rgds

Venkat

You're welcome  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Q1241274614

  • Guest
Re: Offset polyline from coordinates - Lisp
« Reply #4 on: February 15, 2013, 11:44:43 AM »
(setq a (+ (/ pi 2.) (_angleatpoint e pt)))
A is not the angle bisector

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Offset polyline from coordinates - Lisp
« Reply #5 on: February 15, 2013, 11:48:19 AM »
(setq a (+ (/ pi 2.) (_angleatpoint e pt)))
A is not the angle bisector

It is a perpendicular offset which I thought the OP wanted? How would you suggest fixing the code?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Konstantin Kil

  • Mosquito
  • Posts: 2
Re: Offset polyline from coordinates - Lisp
« Reply #6 on: August 11, 2020, 06:16:12 AM »
(setq a (+ (/ pi 2.) (_angleatpoint e pt)))
A is not the angle bisector

It is a perpendicular offset which I thought the OP wanted? How would you suggest fixing the code?

Dear Ronjonp! Please tell me if I can use this Lisp without entering the East and North coordinates in .csv format. if I have a polyline in AutoCAD, from which will be will  built :Chainage, LHS, RHS?   P.S. sorry for my english)

DEVITG

  • Bull Frog
  • Posts: 479
Re: Offset polyline from coordinates - Lisp
« Reply #7 on: August 11, 2020, 05:09:26 PM »
Hi Konstantin Kil .

Quote
For better understanding, and to get further help,  please upload such sample.dwg  and sample.csv
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

d2010

  • Bull Frog
  • Posts: 326
Re: Offset polyline from coordinates - Lisp
« Reply #8 on: August 11, 2020, 05:54:05 PM »
(setq a (+ (/ pi 2.) (_angleatpoint e pt)))
A is not the angle bisector
I lock your program.Lisp. You cannot run without (isInside18_jsldatinDwg) .
You program now -you see a new-version.
« Last Edit: August 17, 2020, 10:49:41 AM by d2010 »

Konstantin Kil

  • Mosquito
  • Posts: 2
Re: Offset polyline from coordinates - Lisp
« Reply #9 on: August 12, 2020, 04:22:46 AM »
Hi Konstantin Kil .

Quote
For better understanding, and to get further help,  please upload such sample.dwg  and sample.csv

Good day DEVITG! having 2 files available: axis and data.  I want to get something similar to the result.

sanju2323

  • Newt
  • Posts: 68
Re: Offset polyline from coordinates - Lisp
« Reply #10 on: August 15, 2020, 11:58:58 PM »
Hi ronjonp,
  Konstantin Kil has shared the file wouldn't it be possible by Lisp? It is also very useful for me.

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Offset polyline from coordinates - Lisp
« Reply #11 on: August 16, 2020, 09:28:25 PM »
Have a look at this https://www.cadtutor.net/forum/topic/70992-how-to-write-lisp-to-following-problem/

Using parse csv make a list (Ch off1 off2)(Ch off1 off2)(Ch off1 off2)
just run twice getpointatdist, get-1st-derivative polar to work out new point for off1 add to list make pline all off1's then do again for off2.

Add dims etc as you go, look at any of the Chainage.lsp for a code starting point.
A man who never made a mistake never made anything

sanju2323

  • Newt
  • Posts: 68
Re: Offset polyline from coordinates - Lisp
« Reply #12 on: August 16, 2020, 11:24:16 PM »
Thank you BIGAL for the reply, but I am not an expert in lisp code, can you give me the complete code?

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: Offset polyline from coordinates - Lisp
« Reply #13 on: August 17, 2020, 12:24:59 AM »
Posted at Cadtutor now. Note needs a dim style set.
A man who never made a mistake never made anything