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.
ossosso's picture

Thank you very much! It

Thank you very much!
It works, and I have also understood it :) thanks to you.
"Switch on" I mean the little bulb next to the modifier name that you can use to Enable/Disable it.
By default mu "custom modifier" is applied with the bulb off, so it doesn't affect the geometry. I have to manually "swicth on" the bulb/enable it.
The code:
&.modifiers[#MODIFER].enabled=true
seems not to do that inside your code

barigazy's picture

...

;)

addModifier $ (CustMod enabled:on)

bga

ossosso's picture

Ehy man! Thank you very very

Ehy man! Thank you very very much for your really clear support!
Your script works :)

Just some info for better apply to my use:
-Could be this action applied to all visible object instead of layername? 'cause otherwise I should each time manually copy/past layername into the script. If not doens't matter.
-This should be the core of the action:
addModifier o (TurboSmooth iterations:2 isolineDisplay:on)
And as I can easily understand it adds the turbosmooth modifiers to all nodes with iterations of 2 and isoline on. I notice that if I change modifier name to add another kind of modifier I have to leave some other code after the modifier name, if I write:
addModifer o (MODIFIER)
I receive the errore message:
"Unable to convert: MODIFIER to type: Modifer"
It works if I write
addModifier i (MODIFIER iterations:2)
even if the MODIFIER hasn't "iteration" parameter, just to understand
-It's possible to add a second command after adding the modifier to Switch On it? 'Cause by default it's applied switch Off.

Thank you very very much anyway!

barigazy's picture

...

TurboSmooth in the code below is not name but modifier class.
To get modifier class of your custom modifier do next:
- assigne that mode to some object
- run this in listener

classof $.modifiers[1]

- let's say you get CustMod
- now to add this modifier try

addModifier $ (CustMod()) -- in my code "$" is "i"

- to see all properties of custom modifier run

show $.modifiers[1]

I don't understand your last question about "Switch on"

bga

barigazy's picture

...

With this fn you can assigne en modifier (TS in this case) to all objects which layer is not hidden. Unhidde some layers in layer manager and run this code

fn modifyObjsByLayer hidden: =
(
	local nodes = #()
	for l = 0 to layerManager.count-1 where (lay = layerManager.getLayer l).ishidden == hidden do
	(
		join nodes (refs.dependentNodes lay.layerAsRefTarg)
	)
	if nodes.count != 0 do
	(
		for o in nodes where filtObj o and not (filterObjByModifier o n:1 modyclass:TurboSmooth) do
		(
			addModifier o (TurboSmooth iterations:2 isolineDisplay:on)
		)
	) ; nodes
)
modifyObjsByLayer hidden:off

bga

ossosso's picture

Ok, well, here is a simple

Ok, well, here is a simple scene saved in max2013:

http://www.ossosso.com/scambio/test.max

What I'd like is that to the 3 spheres in layer "esp_nb1_lp" (which is the unhidden one) could be applied the Turbosmooth modifier in a consecutive way:
-select first sphere -->apply Turbosmooth
-select second sphere -->apply Turbosmooth
...

At the end each of them has a turbosmooth modifier, not instanced.

Then I will hide the first layer, unhide the second one and repeat the script.

I need that because I have to apply a commercial modifier on geometries (not installed within 3dsmax) which cannot be applied to multiple objects.

We can try with turbosmooth for now, it will be easy for me next to substitute your "turbosmooth code" with "other modifier code"

modPanel.addModToSelection (MODIFIER ()) ui:on

Tnank you very much!

barigazy's picture

...

Ok. I will explain you step-by-step what you need to do

bga

barigazy's picture

...

--Here is not important which layer is hidden or not because we will work on objects in specified Layer
--First of all let's define some filter function that U can use
--You can filter some objects by type, name, material,modifier etc.
fn filtObj obj = isKindOf obj GeometryClass and canConvertTo obj Editable_Mesh -- filter only geometry object
fn filterObjByName obj namePattern: = MatchPattern obj.name pattern:("*"+namePattern+"*") ignorecase:on -- filter  object by name
-- example : filterObjByName selection[1] namePattern:"sphere"
fn filterObjByMatClass obj matclass: = isKindOf obj.mat matclass -- filter  object by material
-- example : filterObjByName selection[1] matclass:Multimaterial
fn filterObjByModifier obj n: modyclass: = isKindOf obj.modifiers[n] modyclass -- filter  object by n-ty modifier
-- example : filterObjByModifier selection[1] n:1 modyclass:TurboSmooth
 
fn modifyObjsByLayer layername: = if isKindOf layername string do
(
	local nodes = #() -- predefine a array for objects of specified layer
	if (lay = LayerManager.getLayerFromName layername) != undefined do -- check if layer exists
	(
		nodes = refs.dependentNodes lay.layerAsRefTarg -- if exists store all objects in nodes array
	)
	if nodes.count != 0 do -- check if nodes array is not empty
	(
		for o in nodes where filtObj o and not (filterObjByModifier o n:1 modyclass:TurboSmooth) do -- filter all geometry objects which not have already turbosmooth modifier
		(
			addModifier o (TurboSmooth iterations:2 isolineDisplay:on)
		)
	) ; nodes
)
modifyObjsByLayer layername:"esp_nb1_lp"

bga

ossosso's picture

Thank you very very much

Thank you very very much barigazy for answering me.

Unfortunatly I'm not a max script user, I can sometime intuitively or with some copy/past obtein what I need.. but this is not the case :)

I don't know how to use your code.

Can you explain me please? Not all the script, but only how to make it work, I have an error once executed it.

Thanks again.

barigazy's picture

...

If U are not used maxscripts in this way then is very difficult to explain.
This is just example and U need to modify it for your needs.
So maybe is better to post here examle file and describe what exactly U want to achive. Then I will try to correct my code

bga

Comment viewing options

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