你好
我有一堆方块,代表风景物体(如树木、灌木丛等)。我正在尝试建立一个例程,重新插入选定的块,在指定最小/最大比例和最小/最大旋转后,重新插入的块应处于随机比例和旋转。到现在为止,我手动完成(复制块,然后逐个选择,更改比例和旋转)。
我不太擅长lisp,以下是我的尝试:
- (defun c:test ( / att blk sel blksc blkrot )
- (if (setq sel (ssget "_+.:E:S" '((0 . "INSERT"))))
- (progn
- (setq blk (LM:al-effectivename (ssname sel 0))
- (setq blksc (LM:randrange-Scale))
- (setq blkrot (LM:randrange-Rotation))
- att (getvar 'attreq)
- )
- (setvar 'attreq 0)
- (while (vl-cmdf "_.-insert" blk
- "_S" blksc
- "_R" blkrot
- "\" ""))
- (setvar 'attreq att)
- )
- )
- (princ)
- )
- ;; Random in Range - Lee Mac
- ;; Returns a pseudo-random integral number in a given range (inclusive)
- ;I did some modifications here:
- (defun LM:randrange-Scale ( scmin scmax )
- (setq scmin (getreal "\nSpecify min scale:")
- (setq scmax (getreal "\nspecify max scale:")
- (fix (+ scmin (* (LM:rand) (- scmax scmin -1))))
- )
- (defun LM:randrange-Rotation ( rotmin rotmax )
- (setq rotmin (getint "\nspecify min rotation:")
- (setq rotmax (getint "\nspecify max rotation:")
- (fix (+ rotmin (* (LM:rand) (- rotmax rotmin -1))))
- )
- ;; Rand - Lee Mac
- ;; PRNG implementing a linear congruential generator with
- ;; parameters derived from the book 'Numerical Recipes'
- (defun LM:rand ( / a c m )
- (setq m 4294967296.0
- a 1664525.0
- c 1013904223.0
- $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
- )
- (/ $xn m)
- )
- ;; Effective Block Name - Lee Mac
- ;; ent - [ent] Block Reference entity
- (defun LM:al-effectivename ( ent / blk rep )
- (if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**")
- (if
- (and
- (setq rep
- (cdadr
- (assoc -3
- (entget
- (cdr
- (assoc 330
- (entget
- (tblobjname "block" blk)
- )
- )
- )
- '("AcDbBlockRepBTag")
- )
- )
- )
- )
- (setq rep (handent (cdr (assoc 1005 rep))))
- )
- (setq blk (cdr (assoc 2 (entget rep))))
- )
- )
- blk
- )
|