Author Topic: Automatic Nesting for lisp?  (Read 9759 times)

0 Members and 1 Guest are viewing this topic.

well20152016

  • Newt
  • Posts: 88
Re: Automatic Nesting for lisp?
« Reply #45 on: December 04, 2016, 10:52:26 AM »
How many kinds of large rectangular size by n small rectangle?

Result:((200 10) (180 10) (160 10) (140 10) (120 10) (100 20) (80 20) (60 30) (40 50)
(20 100))

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt()
  2.   (setq w 20 l 10 n 10)
  3.   (setq p (getpoint"\n insertion point") b p i 1 lst nil)
  4.   (repeat n
  5.     (repeat i
  6.        (repeat (fix(/ n i)) (LM:ENTMAKE-LWPOLYLINE (4boxs b w l)) (setq b (polar b 0 l)))
  7.         (setq b (list (car p) (+ w (cadr b)))))
  8.     (setq lst (cons(list (* i w) (* (fix(/ n i)) l)) lst) i (1+ i))
  9.     (setq b (list (car p) (+ (cadr b) 4)))
  10.     )
  11. (princ "\n")
  12. (princ lst)
  13.  
  14. (defun 4boxs (p w l)
  15.   (list p  (polar p (* 0.5 pi) w) (polar (polar p 0 l) (* 0.5 pi) w)  (polar p 0 l))
  16. )
  17.  
  18. (defun LM:ENTMAKE-LWPOLYLINE (lst  / p)
  19.               (list (cons 0 "LWPOLYLINE")
  20.                     (cons 100 "AcDbEntity")
  21.                     (cons 100 "AcDbPolyline")
  22.                     (cons 90 (length lst) )
  23.                     (cons 70 1 )
  24.                     (cons 62 2 )
  25.               )
  26.               (mapcar(function (lambda (p) (cons 10 p)))lst)
  27. )))    
  28.  

LULU1965

  • Mosquito
  • Posts: 14
Re: Automatic Nesting for lisp?
« Reply #46 on: December 04, 2016, 02:05:58 PM »
Minimum possibile number of platea .... Thanks forma all Grazie tanto

roy_043

  • Water Moccasin
  • Posts: 1858
  • BricsCAD 18
Re: Automatic Nesting for lisp?
« Reply #47 on: December 04, 2016, 08:27:13 PM »
@well20152016:
I think the result should be:
((200 10) (100 20) (40 50) (20 100))

well20152016

  • Newt
  • Posts: 88
Re: Automatic Nesting for lisp?
« Reply #48 on: December 06, 2016, 07:51:18 AM »
Code - Auto/Visual Lisp: [Select]
  1.  
  2. result:((200 10) (100 20) (40 50) (20 100))
  3.  
  4. (defun c:tt()
  5.   (setq w 20 l 10 n 10)
  6.   (setq p (getpoint"\n insertion point") b p i 1 lst nil)
  7.   (repeat n
  8.    (if (equal (rem n i) 0 0) (progn
  9.     (repeat i
  10.        (repeat (fix(/ n i)) (LM:ENTMAKE-LWPOLYLINE (4boxs b w l)) (setq b (polar b 0 l)))
  11.         (setq b (list (car p) (+ w (cadr b)))))
  12.     (setq lst (cons(list (* i w) (* (fix(/ n i)) l)) lst) )))
  13.     (setq i (1+ i))
  14.     (setq b (list (car p) (+ (cadr b) 4)))
  15.     )
  16. (princ "\n")
  17. (princ lst)
  18.  
  19. (defun 4boxs (p w l)
  20.   (list p  (polar p (* 0.5 pi) w) (polar (polar p 0 l) (* 0.5 pi) w)  (polar p 0 l))
  21. )
  22.  
  23. (defun LM:ENTMAKE-LWPOLYLINE (lst  / p)
  24.               (list (cons 0 "LWPOLYLINE")
  25.                     (cons 100 "AcDbEntity")
  26.                     (cons 100 "AcDbPolyline")
  27.                     (cons 90 (length lst) )
  28.                     (cons 70 1 )
  29.                     (cons 62 2 )
  30.               )
  31.               (mapcar(function (lambda (p) (cons 10 p)))lst)
  32. )))
  33.  
  34.  

ahsattarian

  • Newt
  • Posts: 59
Re: Automatic Nesting for lisp?
« Reply #49 on: January 19, 2021, 02:28:36 PM »
This works on several sheets   :



Code - Auto/Visual Lisp: [Select]
  1. (defun c:nest ()
  2.   (prompt "\n Select nesting 2D entities : ")
  3.   (setq ss1 (ssget "_:L"))
  4.   (prompt "\n Pick boundary rectangle to nest to :")
  5.   (setq filter (list '(0 . "lwpolyline") '(90 . 4) '(-4 . "<or") '(70 . 1) '(70 . 129) '(-4 . "or>") '(-4 . "<not") '(-4 . "<>") '(42 . 0.0)
  6.                      '(-4 . "not>"))
  7.   )
  8.   ;;(setq ss2 (ssget "_+.:E:S" filter))
  9.   (setq ss2 (ssget filter))
  10.   (setq el nil)
  11.   (setq n1 (sslength ss1))
  12.   (setq k1 -1)
  13.   (repeat n1
  14.     (setq k1 (1+ k1))
  15.     (setq s1 (ssname ss1 k1))
  16.     (setq obj1 (vlax-ename->vla-object s1))
  17.     (vla-getboundingbox obj1 'eminp 'emaxp)
  18.     (mapcar 'set '(eminp emaxp) (mapcar 'safearray-value (list eminp emaxp)))
  19.     (setq ew (- (car emaxp) (car eminp)))
  20.     (setq eh (- (cadr emaxp) (cadr eminp)))
  21.     (cond
  22.       ((> ew eh)
  23.        (setq po (mapcar '/ (mapcar '+ eminp emaxp) (list 2.0 2.0 2.0)))
  24.        (vla-rotate obj1 (vlax-3d-point po) (* 0.5 pi))
  25.        (vla-getboundingbox obj1 'eminp 'emaxp)
  26.        (mapcar 'set '(eminp emaxp) (mapcar 'safearray-value (list eminp emaxp)))
  27.        (setq ew (- (car emaxp) (car eminp)))
  28.        (setq eh (- (cadr emaxp) (cadr eminp)))
  29.       )
  30.     )
  31.     (setq el (cons (list eminp ew eh s1) el))
  32.   )
  33.   (setq el (vl-sort el
  34.                     '(lambda (a b)
  35.                        (if (equal (caddr a) (caddr b) 1e-3)
  36.                          (< (cadr a) (cadr b))
  37.                          (< (caddr a) (caddr b))
  38.                        )
  39.                      )
  40.            )
  41.   )
  42.   (setq n2 (sslength ss2))
  43.   (setq k2 -1)
  44.   (repeat n2
  45.     (setq k2 (1+ k2))
  46.     (setq s2 (ssname ss2 k2))
  47.     (setq obj2 (vlax-ename->vla-object s2))
  48.     (vla-getboundingbox obj2 'minp 'maxp)
  49.     (mapcar 'set '(minp maxp) (mapcar 'safearray-value (list minp maxp)))
  50.     (setq w (- (car maxp) (car minp)))
  51.     (setq h (- (cadr maxp) (cadr minp)))
  52.     (setq x nil)
  53.     (setq y nil)
  54.     (setq yn nil)
  55.     (setq ell nil)
  56.     (setq elll nil)
  57.     (while
  58.       (and
  59.         (car el)
  60.         (cond
  61.           ((null x) (setq x 0.0) (setq y 0.0) (setq f x))
  62.           ((> (+ x (cadar el)) w)
  63.            (setq x 0.0)
  64.            (foreach e elll (setq ell (vl-remove e ell)))
  65.            (setq elll ell)
  66.            (setq y (+ (cadr (car (reverse ell))) (caddr (caddr (car (reverse ell))))))
  67.            (vl-some '(lambda (e) (cond ((< (cadar el) (+ (car e) 1e-3)) (setq yn (+ (cadr e) (caddr (caddr e)))))))
  68.                     (reverse ell)
  69.            )
  70.            (cond ((> yn y) (setq y yn)))
  71.            (setq f x)
  72.           )
  73.           (t
  74.            (if
  75.              (not
  76.                (vl-some '(lambda (e) (cond ((< (+ x (cadar el)) (+ (car e) 1e-3)) (setq yn (+ (cadr e) (caddr (caddr e)))))))
  77.                         (reverse ell)
  78.                )
  79.              )
  80.               (vl-some
  81.                 '(lambda (e)
  82.                    (cond ((or (< (+ x (cadar el)) (car e)) (< (+ x 1e-3) (car e))) (setq yn (+ (cadr e) (caddr (caddr e))))))
  83.                  )
  84.                 (vl-sort ell '(lambda (a b) (> (car a) (car b))))
  85.               )
  86.            )
  87.            (cond ((> yn y) (setq y yn)))
  88.            (setq f x)
  89.           )
  90.         )
  91.         (< f w)
  92.         (or (< (+ y (caddar el)) h) (equal (+ y (caddar el)) h 1e-3))
  93.       )
  94.        (if (= x 0.0)
  95.          (setq bp (list (car minp) (+ y (cadr minp)) 0.0))
  96.          (setq bp (list (+ x (car minp)) (+ y (cadr minp)) 0.0))
  97.        )
  98.        (setq x (+ x (cadar el)))
  99.        (vla-move (vlax-ename->vla-object (cadddr (car el))) (vlax-3d-point (caar el)) (vlax-3d-point bp))
  100.        (setq ell (cons (list x y (car el)) ell))
  101.        (setq el (cdr el))
  102.     )
  103.   )
  104.   (princ)
  105. )





ScottMC

  • Newt
  • Posts: 72
  • ...if we don't ask, we won't receive..
Re: Automatic Nesting for lisp?
« Reply #50 on: January 21, 2021, 06:53:13 PM »
NICE lsp y'all!!

Tried for a bit to get the vars assigned and won't give.. responds with:

 Command: NEST
; error: too few arguments

[a b bp e eh el ell elll ew f h k1 k2 n n2 n1 s1 s2
ss1 ss2 t w x y yn filter obj1 po eminp emaxp maxp minp]

vlide responds saying the "t" var is incorrect.

just feel safer having those vars assigned Thanks

Really like it for cut file setup!
« Last Edit: January 21, 2021, 06:58:42 PM by ScottMC »

ahsattarian

  • Newt
  • Posts: 59
Re: Automatic Nesting for lisp?
« Reply #51 on: January 24, 2021, 11:59:01 AM »
Hello

T   is not used in my LISP  above  !!!

It works in my laptop.

R U sure about it????

ScottMC

  • Newt
  • Posts: 72
  • ...if we don't ask, we won't receive..
Re: Automatic Nesting for lisp?
« Reply #52 on: January 24, 2021, 07:06:39 PM »
Must be the "t" is not a variable .. really WAY over my head!

          (t   
           (if
             (not
               (vl-some

had to play with it [takes alot for me to understand] still
like it very much but still would like to assign the local vars..
any help would be REALLY appreciated!!  :idiot2:
« Last Edit: February 05, 2021, 12:56:56 PM by ScottMC »


ScottMC

  • Newt
  • Posts: 72
  • ...if we don't ask, we won't receive..
Re: Automatic Nesting for lisp?
« Reply #54 on: April 30, 2021, 11:55:58 AM »
Just to ease the cad-vars.. here's the working list for "Nest":
( / a b bp e eh el ell elll ew f h k1 k2 n n2 n1 s1 s2 ss1 ss2 w x yy yn filter obj1 obj2 po eminp emaxp maxp minp )

ronjonp

  • Needs a day job
  • Posts: 7269
Re: Automatic Nesting for lisp?
« Reply #55 on: April 30, 2021, 04:57:43 PM »
Just to ease the cad-vars.. here's the working list for "Nest":
( / a b bp e eh el ell elll ew f h k1 k2 n n2 n1 s1 s2 ss1 ss2 w x yy yn filter obj1 obj2 po eminp emaxp maxp minp )
I've tried to educate this poster a few times on localizing variables but it fell on deaf ears.  :roll:

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

ScottMC

  • Newt
  • Posts: 72
  • ...if we don't ask, we won't receive..
Re: Automatic Nesting for lisp?
« Reply #56 on: May 01, 2021, 06:46:49 PM »
I've seen others which place a combined (setq xx nil..) later in the code. Why they choose this as it could clear vars out on other working pgms...  ouch