
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I have some code here and it works great but its not quite there to where I need it to be.
I think I can make it work but it I know it can be done a lot better.
What it does is nest all my panels on a sheet, where I am having troubles is getting the code to keep all my panels a 1/2" apart (for the tooling). I work with wood so the grain direction is a huge deal which means the panels can not be rotated.
Like I said, I could probable do it but I know there is a better way than to:
Offset all the objects to the outside 1/2"
Delete the source of the previous offset
Run the nesting code
Offset all the objects to the inside 1/2"
Delete the source of the previous offset
I just don't understand this code yet.
Can someone explain how to modify the spacing between objects in this code.
or even help me do this.
I would like to lean too thought 🙂
Thanks!
(defun c:nesting ( / *adoc* ss s bndr minp maxp w h i e eminp emaxp ew eh el x y bp ell elll ) (vl-load-com) (vla-startundomark (setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))) (prompt "\nSelect nesting 2D entities...") (setq ss (ssget "_:L")) (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>")))) (setq bndr (ssname s 0)) (vla-getboundingbox (vlax-ename->vla-object bndr) 'minp 'maxp) (mapcar 'set '(minp maxp) (mapcar 'safearray-value (list minp maxp))) (setq w (- (car maxp) (car minp))) (setq h (- (cadr maxp) (cadr minp))) (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (vla-getboundingbox (vlax-ename->vla-object e) 'eminp 'emaxp) (mapcar 'set '(eminp emaxp) (mapcar 'safearray-value (list eminp emaxp))) (setq ew (- (car emaxp) (car eminp))) (setq eh (- (cadr emaxp) (cadr eminp))) (setq el (cons (list eminp ew eh e) el)) ) (setq el (vl-sort el '(lambda ( a b ) (if (equal (caddr a) (caddr b) 1e-3) (< (cadr a) (cadr b)) (< (caddr a) (caddr b)))))) (while (and (car el) (< (cond ( (null x) (setq x 1 y 1) x ) ( (> (+ x (cadar el)) w) (setq x 1) (foreach e elll (setq ell (vl-remove e ell)) ) (setq elll ell) (vl-some '(lambda ( e ) (if (< (cadar el) (car e)) (setq y (+ (cadr e) (caddr (caddr e)))) ) ) (reverse ell) ) x ) ( t (if (not (vl-some '(lambda ( e ) (if (< (+ x (cadar el)) (car e)) (setq y (+ (cadr e) (caddr (caddr e)))) ) ) (reverse ell) ) ) (vl-some '(lambda ( e ) (if (or (< (+ x (cadar el)) (car e)) (< (+ x 1e-3) (car e))) (setq y (+ (cadr e) (caddr (caddr e)))) ) ) (vl-sort ell '(lambda ( a b ) (> (car a) (car b)))) ) ) x ) ) w ) (or (< (+ y (caddar el)) h) (equal (+ y (caddar el)) h 1e-3)) ) (if (= x 0.0) (setq bp (list (car minp) (+ y (cadr minp)) 0.0)) (setq bp (list (+ x (car minp)) (+ y (cadr minp)) 0.0)) ) (setq x (+ x (cadar el))) (vla-move (vlax-ename->vla-object (cadddr (car el))) (vlax-3d-point (caar el)) (vlax-3d-point bp)) (setq ell (cons (list x y (car el)) ell)) (setq el (cdr el)) ) (vla-endundomark *adoc*) (princ) )
Solved! Go to Solution.