[Closed] Delete modifier by name?
Hi,
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?
Thanks
(
-- 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 m.name
-- delete Edit_Mesh modifier
for m in curObj.modifiers where m.name == "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,
o
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.
Stable
--assumes 'obj' == valid object
for modify in obj.modifiers where modify.name == "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 modify.name == "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 (modify.name == "MyName") and [b][b](modPanel[/b][/b].[b][b]getCurrentObject[/b][/b]() == modify) do (deletemodifier obj modify;exit)
You could also switch modify.name == 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 m.name == 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 (modify.name == "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)