Notifications
Clear all

[Closed] Delete Modifier by Name not working?

I’ve been trying to delete a modifier by name so I can re-apply it later in a different place. When I delete it via MAXScript the listener tells me it is deleted but when I go to the object the modifer is still there.

Specifically I do a soft selection on verts then add a noise modifier. Then I often need to delete the modifier and re-apply it after a new smaller/larger vertex selection is made.

Edit:
By the way delete by index works fine but I don’t want to delete the wrong modifier in someone’s stack by accident.

8 Replies

What delete modifier by name approach are you using? Why not do something like:

for obj in selection do (
	for mod in 1 to obj.modifiers.count do (
		if obj.modifiers[mod].name == "Name" do (
			deleteModifier obj mod
		)
	)
)

-Eric

 JHN

Maybe it requires you to be in:

“max modify mode”

or maybe

“modPanel.setCurrentObject <modifier>”

will help… I think it’s something along that line… maybe post a code snippet…

-Johan

Thanks. I wish I could post the offending code but I was so frustrated I deleted that line.

I did try max modify mode. I’ll try your solution PM and see if that works. I didn’t try an in o do. it was a

deletemodifier <node> <modifier>

single line, where I could delete the modifier only by index but not by name.

1 Reply
(@hblan)
Joined: 11 months ago

Posts: 0

i want help u if u can send ur scene to me . my mailbox : http://forums.cgsociety.org/haibo.lan@gmail.co m” data-bbcode=”true”>haibo.lan@gmail.com

BTW, deleteModifier <node> <modifier>, doesn’t accept Strings or Names for the modifier. You have to assign the modifier to a variable and then call it:

mod = obj.modifier[1]
 deleteModifiers obj mod

This will delete the referenced modifier that was assigned to index 1, even if you move the modifier in the stack after assigning it but before deleting it. Another way is to assign the modifier to a variable before applying it:

mod1 = (bend name:"mod1")
 addmodifier obj mod1
 deleteModifier obj mod1

This will delete the reference of mod1 from the modifier stack, no matter where it is located in the stack. So you need to assign a reference of the modifier to a variable and call that for the <modifier> or use the index.

-Eric

Excellent Eric!


[left]mod1 = (bend name:"mod1")
 addmodifier obj mod1
 deleteModifier obj mod1[/left]

Much appreciated. That’s exactly what I’ll do.

@ hblan
The script is not scene specific.

Again it doesn’t have to be done that way, but you need to assign the modifier to a variable and then you can access/delete that variable from the stack using the variable.

-Eric

Yep definately the way to go. Thanks for reminding me that if it doesn’t work on the object perform the operation on a variable referencing the object and it works. Somehting to do with the object vs. the object node as I recall. Didn’t realize the same issue applied to modifiers.