Polyline between last and next first point

Polyline between last and next first point

Tanookh
Contributor Contributor
1,155 Views
7 Replies
Message 1 of 8

Polyline between last and next first point

Tanookh
Contributor
Contributor

Hello everyone.

I created this lisp with the help of chatgpt.

I need your help to complete this.

 

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)

 

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

 

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

 

Thanks in Advance.

0 Likes
Accepted solutions (1)
1,156 Views
7 Replies
Replies (7)
Message 2 of 8

Sea-Haven
Mentor
Mentor

My answer is start again I would build this as a  complete routine draw elevation Xbox's len,wid spacing then draw section all in one go. Other comment Chatgp has a long way to go. 

 

There is a few examples of doing repeat shapes with a spacing. Try this one. Save Multi getvals to a support path so can be autoloaded. press cancel or set gap to 0 to exit repeat.

 

 

; draw a rectang and put X in it
; added a repeat function
; By AlanH  May 2023


; cancel is set by multi getvals to 1 when Cancel is pressed.
; ans nil is cancel button presed.

(defun c:xbox ( / cancel)
(setq doagain 0)
(setq len 500 ht 1000 gap 3000)
(setq pt1 (getpoint "\nPick lower left point "))
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(while (= doagain 0)
(setq ans (AH:getvalsm (list "Enter values " "Length " 5 4 (rtos len 2 0) "Height " 5 4 (rtos ht 2 0) "Gap " 5 4 (rtos gap 2 0) )))
(if (= ans nil)
(princ)
(setq len (atof (nth 0 ans))
Ht (atof (nth 1 ans))
Gap (atof (nth 2 ans))
)
)
(if (or (= gap 0)(= ans nil))
(setq doagain 1)
(progn
(command "rectang" pt1 (mapcar '+ pt1 (list len ht 0.0)))
(command "line" pt1 (mapcar '+ pt1 (list len ht 0.0)) "")
(command "line" (mapcar '+ pt1 (list 0.0 ht 0.0)) (mapcar '+ pt1 (list len 0.0 0.0)) "")
(setq pt1 (mapcar '+ pt1 (list (+ gap len) 0.0 0.0)))
)
)
)
(princ)
)
(c:xbox)

 

 

SeaHaven_1-1682906386341.png

SeaHaven_2-1682906455025.png

 

Happy to discuss doing more. PM me.

 

 

 

 

 

0 Likes
Message 3 of 8

Tanookh
Contributor
Contributor
thanks for reply @Sea-Haven
but don't want to draw the rectangle
0 Likes
Message 4 of 8

Moshe-A
Mentor
Mentor
Accepted solution

@Tanookh  hi,

 

Here is my advanced version 😀

 

The program starts with defining some constant values (see lines 75-80)

than goes to collecting data points (see lines 82-85)

 

than shift points up +2000 [WRKLN  (see line 87)]

then sort points by distance from left base point (see line 88) this allows you to pick points in any order

(caution: no check for duplicate points is made)

 

next the red\yellow lines is drawn (see lines 90-103)

than the base point is advanced up +2000 [WRKLN (see line 105)

than shift points up +450 [DEPTH (see line 106)]

 

next points are grouped in fours to be prepared to draw the cyan  lines (see line 108)

next draw cyan lines (see lines 110-134)

 

study the beautiful local functions.

 

i know this is beyond your knowledge but hey to learn to swim you have to head dive 🤣

have more question? i'm here.

 

Your next challenge would be to get the data points by selecting the horizontal lines with (ssget) instead of picking them with (getpoint)

 

enjoy

Moshe

 

 

 

 

(defun c:test2 (/ getPairPoints _shf2wrkln sort_data grp2four ; local functions
		  WRKLN DEPTH EXTEND OFSET SLOP base points^ i t0 t1 t2 t3 grp4^ p0 p1 p2 p3)

 (defun getPairPoints (step bpt / askpoint ; local function
		                  p1 p3)

  (defun askpoint (n)
   (if (not bpt)
    (getpoint (strcat "\nSpecify " step " pt" (itoa n) ": "))
    (getpoint bpt (strcat "\nSpecify " step " pt" (itoa n) ": "))
   )
  ); askpoint
   
  (cond
   ((eq step "first")
    (and
     (setq p1 (askpoint 1))
     (setq base p1)
     (setq p3 (askpoint 3))
    )
   ); case
   ((and
     (setq p1 (askpoint 1))
     (setq p3 (askpoint 3))
    )
   ); case
  ); cond

  (if (and p1 p3)
   (setq points^ (cons p1 points^) points^ (cons p3 points^))
  )
 ); getPairPoints
  
 ; anonymous function, shift points to work line 
 (setq _shf2wrkln (lambda (b v lst) (mapcar (function (lambda (pt) (list (car pt) (+ (cadr b) v) 0.0))) lst)))

 ; sort points by distance from base 
 (defun sort_data (t0 l)
  (mapcar
    (function
      (lambda (itm)
       (cadr itm) 
      )
    ); function
    (vl-sort 
     (mapcar
       (function
         (lambda (t1)
          (list (distance t0 t1) t1)
         )
       ); function
       l
     ); mapcar
     (function (lambda (e0 e1) (< (car e0) (car e1)))) ; sort by this function
    ); vl-sort
  ); mapcar
 ); sort_data

 ; organize points in groups of fours
 (defun grp2four (l0 / j l1)
  (setq j 0) 
  (while (<= (+ j 3) (1- (vl-list-length l0)))
   (setq l1 (cons (list (nth j l0) (nth (1+ j) l0) (nth (+ j 2) l0) (nth (+ j 3) l0)) l1))
   (setq j (+ j 2)) 
  ); while
   
  (reverse l1)
 ); grp2four
  
  
 ; here start test2
 (setvar "cmdecho" 0) 
 (command "._undo" "_begin")

 ; define some constants 
 (setq WRKLN 2000) ; work line
 (setq DEPTH  450)
 (setq EXTEND 300)
 (setq OFSET   40)
 (setq SLOP    80) 
  
 ; get points 
 (if (getPairPoints "first" nil)
  (while (getPairPoints "next" base))
 ); if

 (setq points^ (_shf2wrkln base WRKLN (reverse points^))) ; shift point +WRKLN
 (setq points^ (sort_data base points^)) 		  ; sort by distance from base
  
 (setq i 0)
 (repeat (/ (vl-list-length points^) 2)
  (setq t1 (nth i points^))
  (setq t3 (nth (1+ i) points^))
   
  (setq t0 (polar t1 (* pi 0.5) DEPTH))
  (setq t2 (polar t3 (* pi 0.5) DEPTH))

  (command "._line" "_none" t1 "_none" t3 "" "._chprop" "_si" "_Last" "_Color" 1 "")
  (command "._line" "_none" t0 "_none" t1 "" "._chprop" "_si" "_Last" "_Color" 2 "")
  (command "._line" "_none" t2 "_none" t3 "" "._chprop" "_si" "_Last" "_Color" 2 "")
 
  (setq i (+ i 2))
 ); repeat

 (setq base (list (car base) (+ (cadr base) WRKLN) (caddr base))) ; shift base point +WRKLN
 (setq points^ (_shf2wrkln base DEPTH points^)) ; align points +DEPTH
  
 (setq grp4^ (grp2four points^)) ; make groups of four

 (setq i -1) 
 (foreach item grp4^
  (setq t0 (car item) t1 (cadr item) t2 (caddr item) t3 (cadddr item))
  (setq i (1+ i))
  (cond
   ((= i 0)
    (setq p0 (list (- (car t1) EXTEND) (+ (cadr t1) OFSET) (caddr t1)))
   ); case
   ( t
    (setq p0 (list (- (car t0) EXTEND) (+ (cadr t0) OFSET) (caddr t0)))
   ); case
  ); cond

  (setq p1 (list (- (car t2) EXTEND SLOP) (+ (cadr t2) OFSET) (caddr t2)))
  (setq p2 (list (+ (car p1) SLOP) (+ (cadr p1) OFSET) (caddr p1)))
  (setq p3 (list (+ (car t3) EXTEND) (+ (cadr t3) OFSET OFSET) (caddr t3)))
   
  (command "._line" "_none"  t1 "_none" t2 "" "._chprop" "_si" "_Last" "_Color" 2 "")  
  (command "._pline" "_none" p0 "_width" 0 0 "_none" p1 "_none" p2 "_none" p3 "" "_chprop" "_si" "_Last" "_Color" 4 "") 
 ); foreach

 ; last pline 
 (setq p1 (list (- (car t2) EXTEND) (+ (cadr t2) OFSET) (caddr t2)))
 (setq p2 (list (+ (car t3) EXTEND) (+ (cadr t3) OFSET) (caddr t3)))
 (command "._pline" "_none" p1 "_width" 0 0 "_none" p2 "" "_chprop" "_si" "_Last" "_Color" 4 "") 
  
 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
); c:test2

 

 

 

Message 5 of 8

Sea-Haven
Mentor
Mentor

Another step forward. Try this make sure you have multi getvals.lsp in a support path or add path to the load.

 

Will draw the boxes with a X any size and gap to next, then draw slab section line. Need to talk more about rules for reo as what if want overlap to go left not right, next step. Dims required ?

 

; draw a rectang and put X in it
; added a repeat function
; By AlanH  May 2023
; added a cross section as pline

; cancel button presed ans is nil.

(defun c:xbox ( / pt1 pt2 doagain lst lst2 ans len ht gap depth )
(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
   (cons 100 "AcDbEntity")
   (cons 100 "AcDbPolyline")
   (cons 90 (length lst))
   (cons 70 cls))
   (mapcar (function (lambda (p) (cons 10 p))) lst))
 )
)

(command "-layer" "m" "BOX" "c" 2 "")

(setq pt1 (getpoint "\nPick lower left point "))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(setq depth 450) ; change to a getreal
(setq doagain 0)
(setq lst '())
(setq len 500 ht 1000 gap 3000)

(while (= doagain 0)
  (setq ans (AH:getvalsm (list "Enter values " "Length " 5 4 (rtos len 2 0) "Height " 5 4 (rtos ht 2 0) "Gap " 5 4 (rtos gap 2 0) )))
  (if (= ans nil)
    (princ)
    (setq len (atof (nth 0 ans)) Ht (atof (nth 1 ans)) Gap (atof (nth 2 ans)))
  )
  (if (or (= gap 0)(= ans nil))
  (setq doagain 1)
  (progn
    (setq pt2 (mapcar '+ pt1 (list len ht 0.0)))
    (command "rectang" pt1 pt2 )
    (command "line" pt1 (mapcar '+ pt1 (list len ht 0.0)) "")
    (command "line" (mapcar '+ pt1 (list 0.0 ht 0.0)) (mapcar '+ pt1 (list len 0.0 0.0)) "")
    (setq pt2 (mapcar '+ pt1 (list len 0.0 0.0)))
    (setq lst (cons pt1 lst))
    (setq lst (cons pt2 lst))
    (setq pt1 (mapcar '+ pt1 (list (+ gap len) 0.0 0.0)))
  )
  )
)

(setq lst (reverse lst))

(setq lst2 '())
(setq x 0)

(repeat (/ (length lst) 2)
  (setq lst2 (cons (mapcar '+ (nth x lst) (list 0.0 (+ depth 2000) 0.0)) lst2))
  (setq lst2 (cons (mapcar '+ (nth x lst) (list 0.0 2000 0.0)) lst2))
  (setq lst2 (cons (mapcar '+ (nth (+ x 1) lst) (list 0.0 2000 0.0)) lst2))
  (setq lst2 (cons (mapcar '+ (nth (+ x 1) lst) (list 0.0 (+ depth 2000) 0.0)) lst2))
  (setq x (+ x 2))
)

(setq lst2 (reverse lst2))

(lwpoly lst2 0)

(princ)
)
(c:xbox)

 

SeaHaven_0-1683013858711.png

 

0 Likes
Message 6 of 8

Tanookh
Contributor
Contributor

WoW working perfectly.
@Moshe-A 
Thank you for explain this.
I have already Set my target to get the point by selecting the horizontal line

(which is intersect the vertical line Correct?)

 

And yes this is beyond my knowledge 😀 (that's why I asked to modify in my lisp) 😉

but your explanation will help me to understand this. 

I will get back with new challenge. 

 

0 Likes
Message 7 of 8

Tanookh
Contributor
Contributor
@Anonymous-Hanen
Not working getting
error: Function cancelled
0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Odd I tested it multiple times before posting. See image.

 

 

Copy these 2 lines to the command line should display "Multigetvals loaded" if displays not loaded then the lisp file is not found. Then appload "multi getvals.lsp" before trying code.

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (not AH:getvalsm)(Alert "multi getvals has not loaded ")(alert "Multi getvals has loaded"))

Please let me know. Can help you solve this problem.

 

 

0 Likes