P.S. What is 2440x1220 in dialog box?Probably the dimensions of a sheet of plywood.
I don't see a question here?I have a question:
;--------|-----------------------------|-------------------|
; 10 | description | string |
;--------|-----------------------------|-------------------|
; 20 | length | real |
;--------|-----------------------------|-------------------|
; 30 | width | real |
;--------|-----------------------------|-------------------|
; 50 | preference index | real |
;--------|-----------------------------|-------------------|
;
(;Wood panel code
("CP09702220" (10 . "Wood panel 970x2220")(20 . 970)(30 . 2220)(50 . 80))
("CP06152950" (10 . "Wood panel 615x2950")(20 . 615)(30 . 2950)(50 . 20))
("CP14602950" (10 . "Wood panel 1460x2950")(20 . 1460)(30 . 2950)(50 . 20))
)
;Example: CP14602950 = panel from commerce 1460x2950 - first dimension is the mood sense
; blade thickness = 3 (variable)
(;cutting list: quantity - length - width > first dimension is the mood sense
(3 1015 390) (57 490 1205) ...
)
Find the minimum number of panel proposing the computation starting at the highest preference index with the minimum number of rotations of the panel on the cutting machine (i.e. see the sequence A-B-C-D-F).I've always used (and continue to recommend) MyNesting (http://www.mynesting.com/) for this task.Very interesting, but is there something about the cutting of wood panels with circular blade?
grained and non grained materials? cutting tool thickness?Sorry for my english, I wrote "mood sense":
Reply to animated gif... Not 100% sure, but this is my simple version... Should work with imaginary rectangular bounding boxes like posted gif, but my version is using one single rectangle for entity where nesting is expected...Tested on my sample, this is the result:
<>
Regards, M.R.
Tested on my sample, this is the result:
The rotation is ok (I only draw a wrong cyan rectangle), this is the result:Tested on my sample, this is the result:
Note that you must rotate all parts before "nesting.lsp" as it don't account for rotation - it just uses "move"... So if you have unsatisfied results this is the cause for that...
There is a rule in my algorithm that is : rectangles that have smallest height comes first to be nested and nesting is processed from that rectangle to the rectangle that have largest height (not width)... Nesting is processed in arrays of rows from bottom to top row... There is no rotations... So your example isn't quite adequate for this kind of nesting, and I don't quite know how to program it for your case, but if it makes you more happy, change height of main rectangle so that last 2 parts jump in... You will then see that there is larger gap on the right side from which you can shrink bounding rectangle... The result should be almost the same looking in wasted material areas...Thanks Marko it is a good start. :-) But why not start from rectangles with largest heigth?
HTH, M.R.
There is a rule in my algorithm that is : rectangles that have smallest height comes first to be nested and nesting is processed from that rectangle to the rectangle that have largest height (not width)... Nesting is processed in arrays of rows from bottom to top row... There is no rotations... So your example isn't quite adequate for this kind of nesting, and I don't quite know how to program it for your case, but if it makes you more happy, change height of main rectangle so that last 2 parts jump in... You will then see that there is larger gap on the right side from which you can shrink bounding rectangle... The result should be almost the same looking in wasted material areas...Thanks Marko it is a good start. :-) But why not start from rectangles with largest heigth?
HTH, M.R.
Your pictures very much remind me on TETRIS, but I don't want to dive into rotation functionality... If someone else is willing he/she is welcomed to jump in, I am satisfied with my version by now...Why don't code something to play on TETRIS instead ? :-D
(defun c:tt ( / get-rectangle-pts sort-XY count-ysame-ptr count-ysame-ptl *adoc* a aaa b base bbb1 bpts h i l0 lst lstt rts s ss sss sss1 w x y )
(defun get-rectangle-pts ( en / pts )
(setq pts
(mapcar 'cdr
(vl-remove-if-not
(function
(lambda ( x )
(= (car x) 10)
)
) (entget en)
)
)
)
(setq pts (sort-XY pts '(2 < <)) )
(list (abs (- (caar pts) (caadr pts))) (abs (- (cadar pts) (cadr (cadddr pts)))) en pts)
)
(defun sort-XY ( lst fun / des des2 a )
(defun des ( e1 e2 )
((eval (cadr fun)) (car e1) (car e2))
)
(defun des2 ( e1 e2 )
((eval (caddr fun)) (cadr e1) (cadr e2))
)
(cond
((= (car fun) 0) (vl-sort lst 'des))
((= (car fun) 1) (vl-sort lst 'des2))
((= (car fun) 2) (setq a (vl-sort lst 'des)) (vl-sort a 'des2))
((= (car fun) 3) (setq a (vl-sort lst 'des2)) (vl-sort a 'des))
)
)
(defun count-ysame-ptr ( l / l1 l2 lst x )
(while l
(setq x (car l)
l (cdr l)
l1 (list x)
)
(foreach a l
(if (equal (cadr x) (cadr a) 1e-3)
(setq l1 (cons a l1))
(setq l2 (cons a l2))
)
)
(setq lst (cons l1 lst) l l2 l2 nil)
)
(setq lst
(mapcar (function (lambda ( e )
(car
(vl-sort e (function (lambda ( e1 e2 )
(> (car e1) (car e2))
)))
)
)) lst
)
)
(vl-sort lst (function (lambda ( e1 e2 ) (< (cadr e1) (cadr e2)))))
)
(defun count-ysame-ptl ( l bb / l1 l2 lst lst2 x )
(while l
(setq x (car l)
l (cdr l)
l1 (list x)
)
(foreach a l
(if (equal (cadr x) (cadr a) 1e-3)
(setq l1 (cons a l1))
(setq l2 (cons a l2))
)
)
(setq lst (cons l1 lst) l l2 l2 nil)
)
(setq lst
(mapcar (function (lambda ( e )
(car
(vl-sort e (function (lambda ( e1 e2 )
(< (car e1) (car e2))
)))
)
)) lst
)
)
(setq lst2 nil)
(foreach a (vl-sort lst (function (lambda ( e1 e2 ) (> (cadr e1) (cadr e2)))))
(if (> (cadr a) bb)
(setq lst2 (cons a lst2))
)
)
lst2
)
(vl-load-com)
(vla-startundomark (setq *adoc* (vla-get-activedocument (vlax-get-acad-object))))
(prompt "\nSelect nesting 2D entities...")
(setq ss (ssget (list '(0 . "LWPOLYLINE") '(90 . 4) '(-4 . "<or") '(70 . 1) '(70 . 129) '(-4 . "or>") '(-4 . "<not") '(-4 . "<>") '(42 . 0.0) '(-4 . "not>"))))
(prompt "\nPick boundary rectangle to nest to...")
(setq s (ssget "_+.:E:S" (list '(0 . "LWPOLYLINE") '(90 . 4) '(-4 . "<or") '(70 . 1) '(70 . 129) '(-4 . "or>") '(-4 . "<not") '(-4 . "<>") '(42 . 0.0) '(-4 . "not>"))))
(if ss (setq lst (mapcar (function (lambda ( x ) (get-rectangle-pts x))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))))
(if s (setq l0 (get-rectangle-pts (ssname s 0)) w (car l0) h (cadr l0) bpts (list (car (last l0)))))
(setq lst (vl-sort lst (function (lambda ( a b ) (if (equal (cadr a) (cadr b) 1e-3) (> (car a) (car b)) (> (cadr a) (cadr b)))))))
(setq i 0 lstt nil base (cadar (last l0)))
(while lst
(setq aaa
(mapcar (function (lambda ( y )
(mapcar (function (lambda ( x )
(if (cdr bpts)
(if
(and
(>= (- w (- (car y) (caar (last l0))) (car x)) 0)
(>= (- (cadadr bpts) (cadr y) (cadr x)) 0)
)
x
)
(if
(and
(>= (- w (- (car y) (caar (last l0))) (car x)) 0)
(>= (- h (cadr y) (cadr x)) 0)
)
x
)
))) lst
)
)) bpts
)
)
(if (apply 'or (apply 'append aaa))
(progn
(setq bbb1
(car
(setq sss1
(vl-remove nil
(setq sss
(mapcar (function (lambda ( x y )
(if (vl-remove nil x)
(list (vl-remove nil x) y)
)
)) aaa bpts
)
)
)
)
)
)
(setq aaa (caar bbb1))
(vla-move (vlax-ename->vla-object (caddr aaa)) (vlax-3d-point (car (last aaa))) (vlax-3d-point (cadr bbb1)))
(setq bpts
(count-ysame-ptr
(append
(list (mapcar '+ (car bpts) (list (car aaa) 0)))
bpts
)
)
)
(setq lstt (cons (caddr aaa) lstt))
(setq lst
(vl-remove-if (function (lambda ( b )
(equal aaa b))) lst
)
)
(setq base
(cadar
(last
(get-rectangle-pts (caddr aaa))
)
)
)
); then progn
(progn
(setq rts
(count-ysame-ptl
(apply 'append
(mapcar 'last
(mapcar (function (lambda ( x )
(get-rectangle-pts x))) lstt
)
)
) base
)
)
(setq bpts
(reverse
(cons
(list (caar (last l0)) (cadr (last rts)))
(cdr (reverse rts))
)
)
)
); else progn
); if
(setq i (1+ i))
); while
(vla-endundomark *adoc*)
(princ)
)
TOO BIG EXCUSE ME!!!! (PURGE)Luciano, puoi editare il tuo messaggio precedente e togliere l'allegato (mi pare che si possa fare) così non appesantisce il server. Ciao.
...
(<
(cond
( (null x) (setq x 0.0 y 0.0) x )
( (> (+ x (cadar el)) w)
(setq x 0.0)
(foreach e elll
(setq ell (vl-remove e ell))
)
(setq elll ell)
(setq y (+ (cadr (car (reverse ell))) (caddr (caddr (car (reverse ell))))))
(vl-some
'(lambda ( e )
(if (< (cadar el) (+ (car e) 1e-3))
(setq yn (+ (cadr e) (caddr (caddr e))))
)
)
(reverse ell)
)
(if (> yn y)
(setq y yn)
)
x
)
( t
(if
(not
(vl-some
'(lambda ( e )
(if (< (+ x (cadar el)) (+ (car e) 1e-3))
(setq yn (+ (cadr e) (caddr (caddr e))))
)
)
(reverse ell)
)
)
(vl-some
'(lambda ( e )
(if (or (< (+ x (cadar el)) (car e)) (< (+ x 1e-3) (car e)))
(setq yn (+ (cadr e) (caddr (caddr e))))
)
)
(vl-sort ell '(lambda ( a b ) (> (car a) (car b))))
)
)
(if (> yn y)
(setq y yn)
)
x
)
)
w
)
...
Ooops, I've changed my revision...This is the result, but in my sample I do not need to rotate the rectangles, they are in the rigth rotation, grazie ancora.
This is what my nesting is doing... Red rectangle is modified one, and green one is yours Marc'Antonio...Ok, thanks I will try to see if I can understand how it works. :-)
Ooops, I've changed my revision...
Ooops, I've changed my revision...
Why don't you try it out from the big to the small
Just to ease the cad-vars.. here's the working list for "Nest":I've tried to educate this poster a few times on localizing variables but it fell on deaf ears. :roll:
( / 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 added error handler, calculation of UNDO steps after finish and changed order of generating "l" list of (bp dx dy) so that when first pass of (main) function finishes it checks from lower left corner of main boundary for "bp"s again and not as it was from upper right to lower left... That's one thing in main routine "nesting.lsp" and I tried to make additional "nesting-new.lsp" with (process2rec) function that would try to implement checking of relation of 2 rectangles in processing nesting - all I could think of is that with this checking it's sometimes different choice of processing order of entities from list "el"... Marc's example with bigger main boundary is solvable by "nesting-new.lsp" and first DWG is somewhat better with original "nesting.lsp"... If someone has something new based on "nesting.lsp" it would be good to try to improve it, or post an opinion of what could be better and (or) relevant to this topic... Thanks for attention...
Reply to animated gif... Not 100% sure, but this is my simple version... Should work with imaginary rectangular bounding boxes like posted gif, but my version is using one single rectangle for entity where nesting is expected...Code - Auto/Visual Lisp: [Select]
Regards, M.R.
Reply to animated gif... Not 100% sure, but this is my simple version... Should work with imaginary rectangular bounding boxes like posted gif, but my version is using one single rectangle for entity where nesting is expected...Code - Auto/Visual Lisp: [Select]
Regards, M.R.