Notifications
Clear all

[Closed] random poly selection

Hey,

Couple of days back I saw a script of selecting 50 random polygons from an editable poly. I don’t quite remember where it is in the forum now. Would someone be kind enough to post it again?

Thanks,

Vikram

13 Replies

Hi,

You can select SOs randomly using Pola X.

Light

I just quickly made this script it selects a “percentage” of faces of the selected editable poly, I hope it helps.

Percentage = 90
  subObjectLevel = 0
  NumFaces = polyOp.getNumFaces $
  FaceList = #()
  for cx = 1 to Ceil(Numfaces*(Percentage/100.0)) do (
  	Aleatorio = random 1 NumFaces
  	Append FaceList Aleatorio
  	)
  PolyOp.SetFaceSelection $ FaceList
  subObjectLevel = 4

P.S. You just have to modify the Percentage variable with the amount of faces you want to be selected. ( it’s no perfect though, the loop doesn’t check if the face it’s been selected already ).
If you want a to select 50 faces instead a percentage substitute the “Ceil(Numfaces*(Percentage/100.0))” for “50”

Fabman, unfortunately your script won’t account for faces being selected twice or more.

A more accurate script would probably go like:

(
 local obj = selection[1].baseobject -- Get the base object of the first object in the selection
 local numFaces = polyop.getNumFaces() -- Get the number of faces
 local faces = #{} -- initialize the face bitarray
 local percent = 80.0 -- set the required percentage
 local cutoff = ceil (numfaces * percent / 100.0) -- precalculate the cutoff and round up
 
 -- while the number of bits set in the face array is smaller than the cutoff find new random faces
 while (faces.numberSet < cutoff) do append faces (random 1 numFaces)
 
 -- set the poly object's faces to the new selection
 polyop.setFaceSelection obj faces

-- Force redraw to ensure the selection is visible and set the subobject to poly in case.
completeRedraw()
subObjectLevel 4
 )
 

Not 100% if this code will work, can’t test it at the moment cos it’s midnight here and after 6 and a half hours continuous of LOST I’m in need my bed But the theory is sound, since a bit array can’t have one bit set more than once. So it should give you an accurate result, and it should be faster since the cutoff isn’t being calculated on each iteration.

Fabman, unfortunately your script won’t account for faces being selected twice or more.

Hi Wahooney I already warned floyd1510 about that in the first post, as I said it was a quick and dirty Script to make the work done. it was even better the “Pola X” that Light pointed out, but you had to pay for that one.
Thanks for the improvement though.

Cheers.

You can also use Pola X bundled with v2, which is free.

Light

   Wooops!, thank's to point that out Light, I didn't see you could get that with v2. :D

No probs. Although that version is far from the latest one, it still has alot of useful features.

Light

fabman: Sorry about that, I didn’t read through your whole post.

1 Reply
(@fabman)
Joined: 10 months ago

Posts: 0

No worries!, as I said, nice and optimal method of adding random faces you show in your script.

Cheers

Hey thanks guys for the help.

Wahoonrey, your script has a syntax error; i havent checked what, but i got what ur trying to get to; not repeating selection. Thanks Fabman, I shall be using your script for noe. Thanks a lot guys,

Vikram.

Page 1 / 2