Author Topic: object insertion automatically x and y direction (nesting layout)  (Read 1944 times)

0 Members and 1 Guest are viewing this topic.

kaan

  • Guest
Hi everyone,
I need a lisp. I want to insert automatically on a certain size (length,width,thickness) strip. That is, I want to add object one by one according to following rules:

if X ≥ C                                    if Y ≥ D

insert object                           insert object

else                                        else

finish                                      finish





t = specified thickness of the material
B = 1.25t when C and D is less than 63.5mm
B = 1.5t when C and D is 63.5 mm or longer
C and D = L+B
W = H+2B





Let me explain with an example:


I'm giving the dimensions


Strip dimensions :
length: 9 mm
width: 6.8 mm
thickness 0.16 mm


Part dimensions :
L= 2 mm
H= 2 mm
B= 1.25x0.16= 0.2 mm
C= L+B= 2+0.2= 2.2 mm


If the length of x-axis is greater than C= L+B I want to insert one part automatically
I want to do it in the same way as the y-axis.





I draw the first part into the strip after calculate for the example above.


9-2.2=6.8 ≥ 2.2 insert one part


after the second part


6.8-2.2=4.6 ≥ 2.2 insert one part


after the third part


4.6-2.2=2.4 ≥ 2.2 insert one part


after the fourth part


2.4-2.2=0.2 < 2.2 finish



Thanks in advance.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: object insertion automatically x and y direction (nesting layout)
« Reply #1 on: October 28, 2013, 07:26:33 PM »
There is a Dynamic Array lisp around that would array on x & y based on cursor movement.
Not sure if you entered the spacing or the offset amount.
Can't locate it at this moment but maybe someone will remember it.

Welcome to the Swamp.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

kaan

  • Guest
Re: object insertion automatically x and y direction (nesting layout)
« Reply #2 on: October 29, 2013, 07:41:00 AM »
Thanks for your reply and suggestion CAB

I looked at the lisp (dynamic array) you are talking about but I want to be equal to the distances between them like nesting operation.

Is it possible to do this in the form of the loop with lisp?

Bhull1985

  • Guest
Re: object insertion automatically x and y direction (nesting layout)
« Reply #3 on: October 29, 2013, 09:05:25 AM »
Dynamic array program that allows usage of osnaps
(courtesy of alanjt)
Code: [Select]
(defun c:ABP (/ _wtrans _utrans _num AT:DrawX AT:SS->List sslst bp ep sp same ang from n copylst
              templst seg dist
             )
  ;; Array Between Points
  ;; Alan J. Thompson, 03.14.11

  (vl-load-com)

  (defun _wtrans (p) (cond ((vl-consp p) (trans p 1 0))))

  (defun _utrans (p) (cond ((vl-consp p) (trans p 0 1))))

  (defun _num (/ n)
    (if (setq n (getint "\nSpecify array number (> 1): "))
      (cond ((>= n 2) (1- n))
            ((princ "\nValue must be greater than 1.") (_num))
      )
    )
  )

  (defun AT:DrawX (P C)
    ;; Draw and "X" vector at specified point
    ;; P - Placement point for "X"
    ;; C - Color of "X" (must be integer b/w 1 & 255)
    ;; Alan J. Thompson, 10.31.09
    (if (vl-consp P)
      ((lambda (d)
         (grvecs (cons C
                       (mapcar (function (lambda (n) (polar P (* n pi) d)))
                               '(0.25 1.25 0.75 1.75)
                       )
                 )
         )
         P
       )
        (* (getvar 'viewsize) 0.02)
      )
    )
  )

  (defun AT:SS->List (ss vla / i l)
    ;; Convert selection set to list of ename or vla objects
    ;; ss - SSGET selection set
    ;; vla - T for vla objects, nil for ename
    ;; Alan J. Thompson, 04.01.10
    (if (eq (type ss) 'PICKSET)
      (if vla
        (repeat (setq i (sslength ss))
          (setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l))
        )
        (repeat (setq i (sslength ss)) (setq l (cons (ssname ss (setq i (1- i))) l)))
      )
    )
  )

  (redraw)

  (princ "\nSelect object(s) to array: ")
  (if (and (setq sslst (AT:SS->List (ssget "_:L" '((0 . "~VIEWPORT"))) T))
           (setq bp (_wtrans (AT:DrawX (getpoint "\nSpecify base point: ") 1)))
           (setq sp (cond ((_wtrans (getpoint "\nSpecify array endpoint <base point>: ")))
                          ((setq same bp))
                    )
           )
           (setq ep (_wtrans (getpoint (_utrans sp) "\nSpecify array endpoint: ")))
           (not (grdraw (_utrans sp) (_utrans ep) 7))
           (setq bp   (vlax-3d-point bp)
                 from (vlax-3d-point sp)
                 ang  (angle sp ep)
           )
      )

    (while (setq n (_num))

      (setq copylst (foreach o (append copylst templst) (vla-delete o))
            seg     (/ (distance sp ep) n)
            dist    seg
      )

      (if (not same)
        (setq templst (mapcar (function (lambda (o) (vla-move (setq o (vla-copy o)) bp from) o))
                              sslst
                      )
        )
      )

      (repeat n
        (foreach o (cond (templst)
                         (sslst)
                   )
          (vla-move (car (setq copylst (cons (vla-copy o) copylst)))
                    from
                    (vlax-3d-point (polar sp ang dist))
          )
        )
        (setq dist (+ dist seg))
      )
    )
  )
  (redraw)
  (princ)
)

alternatively, a dynamic array that uses grread which means tracks user mouse input
by Lee Mac
Code: [Select]
(defun c:test ( / ss->list move-v a g0 g1 g2 l lst n o p pu pw )
  ;; Lee Mac 2011

  (defun ss->list ( ss / i l )
    (if ss
      (repeat (setq i (sslength ss))
        (setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l))
      )
    )
  )

  (defun move-v ( l p n v / i q a b d ) (setq i 1 q (vlax-3D-point '(0. 0. 0.)))   
    (foreach x l
      (vla-getBoundingBox (car x) 'a 'b)
      (setq d (vlax-3D-point (mapcar '- (mapcar '+ p (mapcar '* v (list i i i))) (vlax-safearray->list a))) i (1+ i))
      (foreach obj x (vla-move obj q d))
    )
  )

  (if
    (and
      (setq n 4 o (ss->list (ssget '((0 . "~VIEWPORT")))))
      (setq pu (getpoint "\nArray Base Point: "))
    )
    (progn
      (repeat n
        (foreach x o (setq l (cons (vla-copy x) l)))
        (setq lst (cons l lst) l nil)
      )
      (vla-getBoundingBox (last o) 'a 'b)
      (setq p (vlax-safearray->list a) pw (trans pu 1 0) msg (princ "\nArray EndPoint [-/+ Number] <Accept>: "))
     
      (while
        (progn (setq g0 (grread t 13 0) g1 (car g0) g2 (cadr g0))
          (cond
            ( (= 5 g1) (redraw)

              (move-v lst p n (mapcar '/ (mapcar '- (trans g2 1 0) pw) (list n n n)))
              (not (grdraw pu g2 3 1))
            )
            ( (= 2 g1)
             
              (cond
                ( (or (= 45 g2) (= 95 g2))

                  (if (= 1 n)
                    (princ (strcat "\n--> Minimum Array Reached." msg))
                    (progn
                      (mapcar 'vla-delete (car lst)) (setq lst (cdr lst) n (1- n))
                    )
                  )
                )
                ( (or (= 61 g2) (= 43 g2))
                 
                  (setq n (1+ n) l nil lst (cons (foreach ob o (setq l (cons (vla-copy ob) l))) lst))
                )
              )
            )
          )
        )
      )
    )
  )
  (redraw) (princ)
)

Just trying to simplify , let these be seen in case you can use them for your purposes

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: object insertion automatically x and y direction (nesting layout)
« Reply #4 on: October 29, 2013, 09:16:20 AM »
Neither one of those lisp are the one I remember. The lisp I was talking about is older and only arrayed in the x & y plane.
The graphic I remember is a rectangle being arrayed with 5 or so in the x direction & maybe three in the Y direction.
Moving the mouse up/down would affect the Y amount & sideways changes the x amount.

I may have time this afternoon to look for it.


I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12267
  • London, England
Re: object insertion automatically x and y direction (nesting layout)
« Reply #5 on: October 29, 2013, 09:33:02 AM »
Neither one of those lisp are the one I remember. The lisp I was talking about is older and only arrayed in the x & y plane.
The graphic I remember is a rectangle being arrayed with 5 or so in the x direction & maybe three in the Y direction.
Moving the mouse up/down would affect the Y amount & sideways changes the x amount.

Either of these CAB?

http://www.theswamp.org/index.php?topic=37459
http://www.theswamp.org/index.php?topic=26633

Matt__W

  • Seagull
  • Posts: 12954
  • I like my water diluted.
Re: object insertion automatically x and y direction (nesting layout)
« Reply #6 on: October 29, 2013, 09:47:50 AM »
What about using a dynamic block??
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

kaan

  • Guest
Re: object insertion automatically x and y direction (nesting layout)
« Reply #7 on: November 02, 2013, 10:46:34 AM »
I have a lisp for nesting circular layout

Code - Auto/Visual Lisp: [Select]
  1. (defun dtr (a)
  2.   (* pi (/ a 180.0))
  3.   )
  4. (defun gpuser ()
  5.   (setq sp (getpoint "\nStart point of path: "))
  6.   (setq ep (getpoint  "\nEnd point of path: "))
  7.   (setq hwidth (getdist "\nHalf width of path: " sp))
  8.   (setq trad (getdist "nRadius of tiles: " sp))
  9.   (setq tspac (getdist "\nSpacing between tiles: " sp))
  10.   (setq pangle (angle sp ep))
  11.   (setq plength (distance sp ep))
  12.   (setq width (* 2 hwidth))
  13.   (setq angp90 (+ pangle (dtr 90))) ; Path angle + 90 deg
  14.   (setq angm90 (- pangle (dtr 90))) ; Path angle - 90 deg
  15.   )
  16. (defun drawout ()
  17.     (Command "pline"
  18.              (setq p (polar sp angm90 hwidth))
  19.              (setq p (polar p pangle plength))
  20.              (setq p (polar p angp90 width))
  21.              (polar p (+ pangle (dtr 180)) plength)
  22.              "close"
  23.              ))
  24. (defun drow (pd offset)
  25.     (setq pfirst (polar sp pangle pd))
  26.     (setq pchole (polar pfirst angp90 offset))
  27.     (setq plhole pchole)
  28.     (while (< (distance pfirst plhole) (- hwidth trad))
  29.       (Command "circle" plhole trad)
  30.       (setq plhole
  31.              (polar plhole angp90 (+ tspac trad trad))))
  32.     (setq plhole (polar pchole angm90 (+ tspac trad trad)))
  33.     (while (< (distance pfirst plhole) (- hwidth trad))
  34.       (Command "circle" plhole trad)
  35.       (setq plhole
  36.              (polar plhole angm90 (+ tspac trad trad)))))
  37. (defun drawholes ()
  38.       (setq pdist (+ trad tspac))
  39.       (setq off 0.0)
  40.       (while (<= pdist (- plength trad))
  41.         (drow pdist off)
  42.         (setq pdist
  43.                (+ pdist (* (+ tspac trad trad) (sin (dtr 60)))))
  44.         (if (= off 0.0)
  45.           (setq off (* (+ tspac trad trad) (cos (dtr 60))))
  46.           (setq off 0.0))))
  47. (defun C:PATH ()
  48.       (gpuser)
  49.       (setq sblip (getvar "blipmode"))
  50.       (setq scmde (getvar "cmdecho"))
  51.       (setvar "blipmode" 0)
  52.       (setvar "cmdecho" 0)
  53.       (drawout)
  54.       (drawholes)
  55.       (setvar "blipmode" sblip)
  56.       (setvar "cmdecho" scmde)
  57.       (princ)
  58.       )




I wonder if this method can be applied in irregular shapes?