Delete modifier by name?


#21

Sure, blow my mind :smiley:

The only thing I can think of is that using (for obj in objects is wrong) or that querying meshsmooth class by only using meshsmooth is wrong.


#22

the clue is “What if a node has more than one MeshSmooth modifier applied?”


#23

I guess its my fault for not considering that!

for obj in objects do 
(
	disableSceneRedraw()
	theMods = #()
	for mods in obj.modifiers where (classOf mods == meshsmooth) do append theMods mods
	for mods in theMods do deleteModifier obj mods
	enableSceneRedraw()
)

this seem to work for me pretty well although I think it would get really slow, so I am sure you already see a much better way of doing it :slight_smile:


#24

there is semi-pro way:


for node in objects as array where (mods = join #() node.modifiers).count  > 0 do for m in mods where iskindof m MeshSmooth do deletemodifier node m

and there is a pro way:


for t in (getclassinstances MeshSmooth astrackviewpick:on) do for node in (refs.dependentnodes t.client) do deletemodifier node t.anim

:slight_smile:

PS. more PRO sometimes doesn’t mean BETTER (or faster)


#25

Interesting, did not know you could use getClassInstances that way, but I never tried it. Very cool, I like the semi-pro way better then the pro just because its easier to read.

quick question: My method it works, but what are the redundancies in it?


#26

there is nothing bad… but of course disable/enable view redraw has to be moved out the node loop… as:

with redraw off for node in nodes ... 

it’s better to replace do append with collect


  mods = for m in node.modifier where ... collect m
  for m in mods do deletemodifier node m
  

and… there is a trick. you can delete modifiers in backward order:


  for k=node.modifiers.count to 1 by -1 where iskindof (m = node.modifiers[k]) ... do deletemodifier node m 
  

last (backward loop) solution saves some memory. which is not bad sometimes.


#27

Yes :smiley: I noticed that after I submitted the post! thx man!


#28

Correct, the exit has to be removed. Also, if there are multiple meshsmooth modifiers applied to any obj then the code will work on first(top) one.

PePeTD’s

(getClassInstances meshsmooth).enabled = false

works fine.


#29

Pro tip!

(getclassinstances MeshSmooth astrackviewpick:on)

Thanks for that Denis!


#30

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.