[Closed] Random Face Selection
Hello, if anyone could help me tweak this script to not delete faces and leave me with selected faces only, I would be indebted to you. Thanks so much
Originally found at http://emrahgunduz.com/2009/10/19/maxscript-random-face-selection/
The script:
sel = selection as array
count = 1
undo on
(
if sel.count > 0 then
(
while count <= sel.count do
(
select sel[count]
count += 1
facenumber = polyop.getNumFaces $
randomset = #()
[b]for[/b] i=1 to facenumber [b]do[/b]
(
rand = random 0 100
[b]if[/b] rand < 50 [b]do[/b] append randomset i
)
polyop.deleteFaces $ randomset delIsoVerts:[b]true[/b]
)
)
)
select sel[left]
Read more: http://emrahgunduz.com/2009/10/19/maxscript-random-face-selection/#ixzz0XmtOdHCO
[/left]
Change
polyop.deleteFaces $ randomset delIsoVerts:[b]true
[/b]to
polyop.setFaceSelection $ randomset
(there are other things that could be improved in this code, but that should be a good start).
Huge thanks for the help! it’s proof that me and the maxscript help doc need to spend some quality time together asap. I owe you one Bobo.
for n in (selection as array) where iskindof n Editable_Poly or iskindof n Editable_Mesh do
(
selfaces = #{}
for f in n.faces as bitarray where random 0 1 == 1 do append selfaces f
n.selectedfaces = selfaces
)
DenisT, I am still a noob with coding/maxscript, think I could bother you to show me how to paste that fragment into the whole piece of code?
if it lets me run a random face selection script on an object’s Edit Poly modifier, I will be 3ds max heaven!
to change sub selection of Edit_Poly you have to have the modifier opened in modifier panel.
so the code is:
(
if iskindof (epoly = modpanel.getCurrentObject()) Edit_Poly do
(
selfaces = #{}
for f=1 to epoly.getnumfaces() where random 0 1 == 1 do append selfaces f
epoly.setSelection #face selfaces
)
)
The only way to vary the number of faces selected is to increase the numbers together in the part of it written:
1 == 1
Is that right? I really like how this lets you run the script on an editable poly modifier also. Would be interested in seeing if there’s a way to write it to exclude contiguous face selections.
Thnx
I would have thought you would sort of think of it as:
‘If 2 selected faces share the same edge then deselect one face”
I am unsure if this can be done before they are put in the array, or whether this needs another for loop to go through each face in the ‘selfaces’ array and to delete one of the faces that share the same edge.
Again how to find a edge that 2 selected faces are sharing in Max I am unsure at this time (I am new too) but am guessing the logic behind it would be similar to what I have said?