How to extrude polygons by a random amount?

Hi there!

I got an editable poly here and some polygons selected. Now I want to extrude each polygon by some random amount. The problem is I don't konw how to have a loop iterating over each polygon. I also don't know how to get each polygon into an array in order to iterate over each variable of the array.
All that I am currently capable of is to extrude ALL polygons by a random amount which is not what i want.
Is there any existing script for that, or how can i solve my problem?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nikobus's picture

Thanks a LOT!

Works awesome THANK YOU!!

matof's picture

Thank you very much

How can I set the randomize extrusion step? Such as extrusion from 0 to 500 in increments of 50?

Anubis's picture

...

eSteps = for i = 0 to 500 step 50 collect i
$.extrudeFaces eSteps[random 1 eSteps.count]

my recent MAXScripts RSS (archive here)

matof's picture

Great! but i'm too dumb

I'm sorry, but I'm stupid to max script. Tell me, please, where in the script, inserts this new part of script?

Anubis's picture

Ok :)

Here is my try, but keep in mind that I edit the script but without testing ;)

if classOf faceExtr == RolloutClass do destroyDialog faceExtr
rollout faceExtr "Face Extrude"
(
	local eSteps = for i = 0 to 500 step 50 collect i
	local sCount = eSteps.count
 
	fn filtSel = (
		if selection.count != 1 then false else (
			local obj = selection[1]
			classOf obj.baseObject == Editable_Poly \
			and obj.modifiers.count == 0
		)
	)
 
	fn doExtrusions = (
		local obj = selection[1] -- backup current selection
		obj.faces[#cursel] = obj.selectedFaces
		obj.selectedFaces = #{} -- deselect
 
		with undo on (
			for f in obj.faces[#cursel] do (
				polyop.setFaceSelection obj #{f.index}
				obj.extrudeFaces eSteps[random 1 sCount]
			)
		)
		obj.SetSelection #Face obj.faces[#cursel]
	)
 
	button extr "Random Extrude FaceSelection" tooltip:"Do Extrusion!" width:160
	button extrUndo "Undo last step" tooltip:"Undo" width:160
 
	on extr pressed do (
		if filtSel() then doExtrusions() else
		messageBox "Select one Editable Poly" title:"Face Extrude"
	)
 
	on extrUndo pressed do ( max undo )
)	
 
CreateDialog faceExtr width:230

my recent MAXScripts RSS (archive here)

stenionet's picture

I had to put the

I had to put the "createDialog faceExtr" in the beginning of the script to make it work.

Nice script. Thanks.

Scathe's picture

Thank you VERY much, exactly

Thank you VERY much, exactly what i needed!
Works perfectly! =)

le1setreter's picture

had similar needs some time

had similar needs some time ago. here a quick (and dirty) solution. works with collapsed editable poly object only :( ...

rollout faceExtr "Face Extrude" width:230 (
 
	local extrMin = 0.0
	local extrMax = 100.0
 
 
	fn doExtrusions = (
 
		sfBit = #{}
		sf = for i in $.selectedFaces collect i.index
 
		undo on (
 
			for m in sf do (
 
				polyop.setFaceSelection $ #{m}
				$.extrudeFaces (random extrMin extrMax)
 
				append sfBit m
 
			) -- end for
 
			$.SetSelection #Face sfBit
		) --end undo
 
	) -- end fn
 
 
	spinner minExtr "minimal extrusion:"  align:#right width:150 range:[-2000,2000,0] type:#float
	spinner maxExtr "maximal extrusion:"  align:#right width:150 range:[-2000,2000,0] type:#float
 
	button extr "Random Extrude Faceselection" tooltip:"Do Extrusion!" width:160
	button extrUndo "Undo last step" tooltip:"Undo" width:160
 
 
 
	on minExtr changed val do(
			extrMin = val
	)
 
	on maxExtr changed val do(
			extrMax = val
	)
 
 
	on extr pressed do (
		doExtrusions()
	)
 
	on extrUndo pressed do (
		max undo
	)
 
 
)	
 
createDialog faceExtr

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.