Jump to content

random selection


flopo

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

Hi:)

I have not figured out how to operate the lisp.:oops:

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...