TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: kaan on October 28, 2013, 04:20:21 PM
-
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
(http://i42.tinypic.com/2sam8sg.png)
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
(http://i42.tinypic.com/34t7bkz.jpg)
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.
(http://i40.tinypic.com/2meoc2f.png)
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.
-
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.
-
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?
-
Dynamic array program that allows usage of osnaps
(courtesy of alanjt)
(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
(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
-
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.
-
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
-
What about using a dynamic block??
-
I have a lisp for nesting circular layout
(* pi (/ a 180.0))
)
(setq width
(* 2 hwidth
)) (setq angp90
(+ pangle
(dtr
90))) ; Path angle + 90 deg (setq angm90
(- pangle
(dtr
90))) ; Path angle - 90 deg )
(polar p
(+ pangle
(dtr
180)) plength
) "close"
))
(polar plhole angp90
(+ tspac trad trad
)))) (setq plhole
(polar pchole angm90
(+ tspac trad trad
))) (polar plhole angm90
(+ tspac trad trad
))))) (setq pdist
(+ trad tspac
)) (while (<= pdist
(- plength trad
)) (drow pdist off)
(+ pdist
(* (+ tspac trad trad
) (sin (dtr
60))))) (setq off
(* (+ tspac trad trad
) (cos (dtr
60)))) (gpuser)
(drawout)
(drawholes)
)
(http://i41.tinypic.com/2mnlwdf.png)
I wonder if this method can be applied in irregular shapes?
(http://i41.tinypic.com/iokuc6.png)
(http://i40.tinypic.com/3148av6.png)