run script on selection

Hi
I am stuck on probably a simple part of my script.
I have the main body of it working perfectly, on a per object basis, but don't know the string to make it work on a selection.
e.g. When I select 1 object (a simple plane) and evaluate the script, it does as expected. But when I select more than one such object (all copies of the same plane) and try to evaluate it, it fails. How can I make it run on more than one object? Many thanks!
Here's the script:

macros.run "Modifiers" "EditPolyMod"
subobjectLevel = 2
$.modifiers[#Edit_Poly].SetSelection #Edge #{}
$.modifiers[#Edit_Poly].Select #Edge #{1, 3}
$.modifiers[#Edit_Poly].SetOperation #ConnectEdges
$.modifiers[#Edit_Poly].connectEdgeSegments = 2
$.modifiers[#Edit_Poly].connectEdgePinch = random 1 100
$.modifiers[#Edit_Poly].connectEdgeSlide = random -50 50
$.modifiers[#Edit_Poly].Commit ()
subobjectLevel = 4
$.modifiers[#Edit_Poly].SetSelection #Face #{}
$.modifiers[#Edit_Poly].Select #Face #{1}
actionMan.executeAction 0 "40020" -- Edit: Delete Objects
max delete
$.modifiers[#Edit_Poly].ButtonOp #DeleteFace
subobjectLevel = 0

Comments

Comment viewing options

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

Many thanks Swordslayer !

Many thanks Swordslayer !

Swordslayer's picture

 

for obj in getCurrentSelection() do
(
	local ePoly = Edit_Poly()
	addModifier obj ePoly
	setCommandPanelTaskMode #modify
	modPanel.setCurrentObject ePoly node:obj
 
	local edgeSel = #{1, 3}
	edgeSel.count = ePoly.getNumEdges()
 
	ePoly.setSelection #edge edgeSel
	ePoly.connectEdgeSegments = 2
	ePoly.connectEdgePinch = random 1 100
	ePoly.connectEdgeSlide = random -50 50
	ePoly.buttonOp #connectEdges
 
	local faceSel = #{1}
	faceSel.count = ePoly.getNumFaces()
 
	ePoly.setSelection #face faceSel
	ePoly.buttonOp #deleteFace
)

Comment viewing options

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