Grrr Posted November 19, 2015 Posted November 19, 2015 Hello, I've got a bunch of blocks, representing landscape objects (such as trees, bushes, etc..). I'm trying to build up a routine that reinserts selected block and after specifying min/max scale and min/max rotation the reinserted blocks should be at random scales and rotations. By now I do it manually (copying blocks, and then selecting each one by one, changing scale and rotation). I'm not that good with lisp, Here's my try on this: (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 ) Quote
BIGAL Posted November 20, 2015 Posted November 20, 2015 Maybe rethink the method insert a block copy as many as required , then when you do the ssget you pick the block this returns block name and using (0 . "Insert")(2 . blkname) and it will go through all of them and randomise in one go if not happy do again. I posted re random circles within a circle and was going to redo it so it was true random but no 2 circles touch, the obvious addition is to fill a boundary. Now the post was ??? Quote
Grrr Posted November 20, 2015 Author Posted November 20, 2015 The method you suggest sounds good. I just don't know if I'm using Lee's functions right on this (since I need user input for min and max scale variable). I don't think that your random circles routine will work for me, since I don't fill the whole boundary, and I have overlapping blocks also (see the picture). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.