Notifications
Clear all

[Closed] Delete modifier by name?

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

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.

1 Reply
(@coolankur49)
Joined: 11 months ago

Posts: 0

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.

Looking into it Denis!

Is it the fact that mod is a system variable?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

nope… try again. attempt #1.

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.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

nope… wanna see the answer?

Sure, blow my mind

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.

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

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

Page 2 / 3