Jump to content

Recommended Posts

Posted

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!

Posted

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

Posted

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

  • 2 weeks later...
Posted

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

Posted

Hi Lee!:)

 

The name of the set is this:

What is the correct syntax to select it with "sssetfirst"?

Thanks,

Marco

Posted

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.

Posted

Yes!

 

Works!

 

Perfect!

 

Thanks Lee!

 

Marco

Posted

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

Posted

Thanks David!:)

It also works this way!:thumbsup:

Thanks so much for the lisp!:)

Marco

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...