Delete modifier by name?



Which way I can delete modifier by name?

I have a check button that applies Displace modifier:

addmodifier n (Displace () ) 
	validmodifier n Displace
	n.modifiers[#Displace].name = "BrickDisplace"

So by unchecking the checkbutton I would like to delete this modifier.
All I could find was:

deletemodifier n (Displace()) 

So is it possible to use exact modifier name (in this case it’s “BrickDisplace”) to delete it?


 	--	create object
 	t = teapot()
 	addModifier t (Bend())
 	addModifier t (Cloth())
 	addModifier t (Edit_poly())
 	addModifier t (Edit_Mesh())
 	addModifier t (Turbosmooth())
 	addModifier t (MeshSelect())
 	select t
 	curObj = selection[1]
 	modToDel = "Edit_Mesh"
 	--	print the names of all modifiers
 	for m in curObj.modifiers do print
 	--	delete Edit_Mesh modifier
 	for m in curObj.modifiers where == "Edit Mesh" do deleteModifier curObj m

The script will delete all Edit Mesh modifiers(if there are more than one)


You can get the modifier by its name:

     local o = sphere()
     addmodifier o (Displace () ) 
     validmodifier o Displace
     o.modifiers[#Displace].name = "BrickDisplace"
     deleteModifier o (o.modifiers[#BrickDisplace])

hOpe this helps,


Thank you all guys, both ways are nice:

  deleteModifier o (o.modifiers[#BrickDisplace])

Perfect one! I knew it should work this way, but didn’t manage to guess the format.

The second one with finding the modifier is should be more stable in case if Modifier doesn’t
exist.Other way it will give an error.

However something like that should do the same job:

try deleteModifier n (n.modifiers[#BrickDisplace])

Thanks a lot.



 --assumes 'obj' == valid object
 for modify in obj.modifiers where == "MyName" do deletemodifier obj modify

If you want to only delete the first instance;

 --assumes obj is selected and modify panel active
 for modify in obj.modifiers where == "MyName" do (deletemodifier obj modify;exit)

If you want to only delete the active version;

 --assumes obj is selected and modify panel active
 for modify in obj.modifiers where ( == "MyName") and [b][b](modPanel[/b][/b].[b][b]getCurrentObject[/b][/b]() == modify) do (deletemodifier obj modify;exit)

You could also switch == string for classof modify == Edit_Poly / UnwrapUVW etc.

Also useful:
modPanel.setCurrentObject < modifier | node | node_baseobject > [node:<node>] [ui:<boolean>]

modPanel.getModifierIndex <node> <modifier>

modPanel.validModifier (< modifier > | < modifier_class >). --This one might be useful in scenarios where the modifier doesn’t like being deleted


if modify mode is not current or selection is empty the modpanel.getcurrentobject() returns undefined.
so the code might be:

if iskindof (m = modpanel.getcurrentobject()) Modifier and == myname do deletemodifier selection m


I had never seen isKindof before. Thanks for that.

With your line, you would still need to define m.

I like to keep my lines neat and my extraneous or uneccessary variables to a minimum. I think that’s just a little bit of paranioa on my behalf though. I’m not sure why undefined == modify in my example would be a problem though.


there is no problem in your code. it works. but i’m an old school… if i use multiple condition in an expression i check the most probable condition the first.
let’s extend your code for multiple selection:

 for obj in selection do for modify in obj.modifiers where ( == "MyName") and (modPanel.getCurrentObject() == modify) do (deletemodifier obj modify;exit)

do you get my point now?


Sorry for barging in but I was searching for something like this.

Its helpful but it didn’t work if I rename the modifiers.

Like I want to delete all “MeshSmooth” modifiers with arbitrary names like “mySmooth” or something else.

Without knowing the name, can we delete a particular type of modifier.


Make the if-test based on the class of the modifier rather than the name then:

Using DenisT’s code:

if iskindof (m = modpanel.getcurrentobject()) Modifier and (classof m == meshsmooth) do deletemodifier selection m


This is my Code, it doesn’t require object to be selected.

tarObj = $* as array 
objwithMS = for i in tarObj collect if (superclassof i == GeometryClass and classof i != Targetobject and classof i != BoneGeometry and classof i != Biped_Object and i.modifiers[#meshsmooth] != undefined) then i else dontcollect 
for i in objwithMS do (deletemodifier i i.modifiers[#MeshSmooth];exit)


Your code works fine, but it require object to be selected.

My code works fine, but it require exact naming.

If we can club these two then it will be real good.


If you want to just turn all instances of MeshSmooth off use this:

(getClassInstances meshsmooth).enabled = false

This is my way of deleting all meshSmooth from the scene:

for obj in objects do for mod in obj.modifiers do if (classOf mod == meshsmooth) then deleteModifier obj mod

we could create a filtered array like coolankur49 did but it will still have to go through all objects in the scene so I skipped that.

for the OP this is how I would do it:

if n.modifiers["BrickDisplace"] != undefined then deleteModifier n n.modifiers["BrickDisplace"]["BrickDisplace"]


PePeTD, the code above has a mistake.
you have a chance to fix it yourself :wink:


the code leaves the loop after first meeting of any MeshSmooth… if it’s correct there was no reason to collect all nodes with MeshSmooth. otherwise the exit has to be removed.


Looking into it Denis!


Is it the fact that mod is a system variable?


nope… try again. attempt #1. :wink:


Gonna waste attempt #2 probably.

for obj in objects do for mods in obj.modifiers where (classOf mods == meshsmooth) do deleteModifier obj mods

have one last guess after this one.


nope… wanna see the answer?