flopo Posted September 29, 2010 Posted September 29, 2010 Hello everybody, Is it possible to make a random selection? let's say i have a drawing with all entities possible to be in a 2d drawing, and i want to select 10% from all entity, but randomly? Maybe to have an option to give the percentage of a random selection? Thanks! Quote
David Bethel Posted September 29, 2010 Posted September 29, 2010 I'd try something like this: (defun c:randset (/ ss sl i en el ep pct qty); rs) ;;;SMadsen Random Number (defun randnum (/ modulus multiplier increment random) (if (not seed) (setq seed (getvar "DATE"))) (setq modulus 65536 multiplier 25173 increment 13849 seed (rem (+ (* multiplier seed) increment) modulus) random (/ seed modulus))) (cond ((setq ss (ssget "X")) (setq sl (sslength ss) i -1) (while (setq en (ssname ss (setq i (1+ i)))) (setq el (cons en el)))) (T (alert "\nNo Entities Found") (exit))) (initget 7) (setq pct (getreal "\nPercentage To Randomly Choose: ")) (setq qty (fix (* sl pct 0.01))) (setq rs (ssadd)) (while (> qty (sslength rs)) (setq ep (fix (* sl (randnum))) en (nth ep el)) (if (not (ssmemb en rs)) (ssadd en rs))) (eval rs)) ;Return Set RS -David Quote
David Bethel Posted October 1, 2010 Posted October 1, 2010 You're welcome. I'd suggest that you not 'Troll' various forums with the same request. A lot of us participate in multiple groups and it doesn't bode all that well. -David Quote
marmo Posted October 13, 2010 Posted October 13, 2010 Hi:) I have not figured out how to operate the lisp. I think that creates a selection set, but how do I select a set of objects? For example i need to select randomly 20 blocks in a drawing where there are 100. This lisp provides the name of the selection set, but how do I select them? Thanks, Marco Quote
Lee Mac Posted October 13, 2010 Posted October 13, 2010 Hi Marco, Look into the sssetfirst function Quote
marmo Posted October 13, 2010 Posted October 13, 2010 Hi Lee! The name of the set is this: What is the correct syntax to select it with "sssetfirst"? Thanks, Marco Quote
Lee Mac Posted October 13, 2010 Posted October 13, 2010 I would suggest that you read the VLIDE Help Files on sssetfirst, as these will answer all your questions, but: (sssetfirst nil (c:randset)) Should work. Quote
David Bethel Posted October 13, 2010 Posted October 13, 2010 Or if you are using the command line Command: _.Select SELECT Select objects: !rs <Selection set: 2> 20 found Select objects: After you have ran randset. -David Quote
marmo Posted October 13, 2010 Posted October 13, 2010 Thanks David! It also works this way! Thanks so much for the lisp! Marco 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.