ScriptSpot

Forum topic · General Scripting

How to extrude polygons by a random amount?

By Scathe · 2010-07-09

Description

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 (8)

Thanks a LOT!

nikobus · 2019-03-08

Works awesome THANK YOU!!

Thank you very much

matof · 2013-02-07

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

Anubis · 2013-02-08

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

Great! but i'm too dumb

matof · 2013-02-08

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

Ok :)

Anubis · 2013-02-08

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

stenionet · 2010-11-09

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

Nice script. Thanks.

Scathe · 2010-07-12

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

le1setreter · 2010-07-09

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