Jump to content

Polyline between last and next first point

Tanookh Momin

Recommended Posts

Hello everyone.

I created this lisp with the help of chatgpt

I need your help to complete this.


I've attached a CAD file for your reference as what I'm looking for.


I have some idea in my mind but I don't know how to execute that.
1. required distance between last and next 1st point (to creat red line- refer CAD file)
2. calculate the distance from next 1st point. (to extend the cyan line- refer CAD file)


If you modify in my lisp, it will be really helpful me to learning.

2023-04-30 Test.lsp 2023-04-30.dwg

Edited by Tanookh Momin
Link to comment
Share on other sites

I am still not convinced about ChatGPT as a way of doing things. Perhaps we only see here the ones that don't work of course, however the coding isn't quite there yet.


For this I would be tempted to create a list of points, and then draw the yellow and cyan lines afterward. You can draw the red lines as you go as a visual indication as what you have selected. Something like the below. I'd also use entmake to create the polylines (see the sub function in the code), a little more control that way and for those that like it, slightly faster.


I'd use these codes and study how they work, rather than just asking the computer to do it, far better to learn that way




(defun c:test ( / YOffset BlueOffset vertlength ptslist pt1 pt2 pt yptslist bptslist) ; create function, define local variables
  (setq YOffset 2000) ; default values: Y axis offset for lines
  (setq VertLength 450) ; vertical length of yellow line
  (setq BlueOffset 2490) ; blue line offset from point

;;Sub functions
  (defun isEven (number / even) ; even or odd numbers
    (if (= 0 (rem number 2))
      (setq even 1)
    ) ;_ end of if
  ) ; end defun
  (defun drawLWPoly (lst colour / MyPoly x) ; draw lines
    (setq MyPOly
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (cons 100 "AcDbPolyline")
        (cons 62 colour)
        (cons 90 (length lst))
    (foreach x lst
      (setq MyPoly (append MyPoly (list (cons 10 x))))
    ) ; end foreach
    (entmake MyPoly)
  ) ; end defun
;; End sub functions

;;Get first point
  (setq pt1 (getpoint "\nSelect Point 1: "))  ;Get point 1
  (setq ptslist (list pt1)) ; start to make a list of points

;;Create points list
  (setq pt2 pt1) ; for select point guide line
  (while (setq pt2 (getpoint pt2 "\nPick a point, or press ENTER to finish: ")) ; loop while points are selected
    (setq ptslist (append ptslist (list pt2))) l add to list of points
    (if (isEven (length ptslist)) ; draw red lines
       (drawLWPoly (list (mapcar '+ (list 0 YOffset 0) (cadr (reverse ptslist))) (mapcar '+ (list 0 YOffset 0) pt2)) 1)
    ) ; end if
  ) ; end while

;;Draw Lines
  (drawLWPoly (list (mapcar '+ (list 0 YOffset 0) pt1) (mapcar '+ (list 0 (+ YOffset VertLength) 0) pt1)) 2) ; draw line
  (setq acount 1)
  (while (< (+ acount 2) (length ptslist))
    (setq yptslist (list
      (mapcar '+ (list 0 YOffset 0) (nth acount ptslist))
      (mapcar '+ (list 0 (+ YOffset VertLength) 0) (nth acount  ptslist))
      (mapcar '+ (list 0 (+ YOffset VertLength) 0) (nth (+ acount 1)  ptslist))
      (mapcar '+ (list 0 YOffset 0) (nth (+ acount 1) ptslist))

    (setq bptslist (list
      (if (= 1 acount)
        (mapcar '+ (list -300 BlueOffset 0) (nth acount ptslist))        
        (mapcar '+ (list -300 BlueOffset 0) (nth (- acount 1) ptslist))         
      ) ; end if
      (mapcar '+ (list -380 BlueOffset 0) (nth (+ acount 1) ptslist))
      (mapcar '+ (list -300 (+ BlueOffset 40) 0) (nth (+ acount 1) ptslist))
      (mapcar '+ (list 300 (+ BlueOffset 40) 0) (nth (+ acount 2) ptslist))


    (drawLWPoly yptslist 2)
    (drawLWPoly bptslist 4)
    (setq acount (+ acount 2))
  ) ; end while





Link to comment
Share on other sites

Still think way better to look at the big picture. That is what customisation is about.


I provided a draw multi rectangs with X in other link that is 1st step. then remember the points and draw cross section.

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...