Grrr 发表于 2022-7-5 18:21:51

块中的变量

你好
我有一堆方块,代表风景物体(如树木、灌木丛等)。我正在尝试建立一个例程,重新插入选定的块,在指定最小/最大比例和最小/最大旋转后,重新插入的块应处于随机比例和旋转。到现在为止,我手动完成(复制块,然后逐个选择,更改比例和旋转)。
 
我不太擅长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 - 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
)

BIGAL 发表于 2022-7-5 19:13:27

可能会重新考虑该方法,根据需要插入一个块副本,然后当你执行ssget时,你选择该块,该块返回块名并使用(0。“insert”)(2.blkname),它将遍历所有块,如果不高兴,则一次随机执行。
 
我在一个圈内贴了一个重新随机的圈,并打算重做它,所以它是真正的随机,但没有两个圈接触,明显的增加是填补一个边界。现在帖子是???

Grrr 发表于 2022-7-5 19:35:41

你建议的方法听起来不错。我只是不知道我是否在这个问题上使用了李函数(因为我需要用户输入最小和最大比例变量)。
我不认为你的随机圈例程对我有效,因为我没有填充整个边界,而且我也有重叠块(见图)。
页: [1]
查看完整版本: 块中的变量