Select objects once at time and do an action once for each object

Hi!

I have some ojects in an unhidden layer and I'd like to select an object, do an action, select another, do the same action, and so on for all the objects inside the unhidden layer.

The action in my case is to apply a modifier (and change some parameter) that cannot be applied in the same time to all selected objects.

Thanks in advance.

Comments

Comment viewing options

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

...

Example how to collect all objects (geometry) of given layer and assign random predefined modifiers.

fn collectObjsByLayer layername =
(
	local nodes = #()
	if (lay = LayerManager.getLayerFromName layername) != null do
	(
		nodes = refs.dependentNodes lay.layerAsRefTarg
	)
	nodes
)
if (objs = collectObjsByLayer "0").count != 0 do
(
	local mods = #(Noise seed:1 scale:50 fractal:on strength:[10,20,30], Noise seed:5 scale:20 fractal:on strength:[20,40,10], Twist angle:90 bias:20, Bend angle:45)
	for o in objs where canconvertto o edit_mesh do
	(
		addModifier o mods[random 1 mods.count]
	)
)

bga

barigazy's picture

...

Also you can combine all of this in one fn

myModifiers = #(Noise seed:1 scale:50 fractal:on strength:[10,20,30], Noise seed:5 scale:20 fractal:on strength:[20,40,10], Twist angle:90 bias:20, Bend angle:45)
 
fn modifyObjsByLayer layername mods: =
(
	local nodes = #()
	if (lay = LayerManager.getLayerFromName layername) != null do
	(
		nodes = refs.dependentNodes lay.layerAsRefTarg
	)
	if nodes.count != 0 and mods != unsupplied do
	(
		for o in nodes where canconverto o editable_poly do
		(
			addModifier o mods[random 1 mods.count]
		)
	) ; nodes
)
modifyObjsByLayer "0" mods:myModifiers

bga

Comment viewing options

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