two small scripted modifiers wanted

hello
could anyone script one simple modifier and improve existing one?

1. InvertSelection modifier - work with mesh objects and inverts its sub-object selection.
2. add "straighten corners" option (same as in Shell) to Push modifier.

i hope it will be useful for many people here

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
harumscarum's picture

thank you

here I correct your script a little according to my needs (push inside), but i'm not smart in maxscript and couple issues remains:
- how to assign DeleteMesh and others modifiers as soon as Push applied (without touching spinner)?
- need "flip normals" checkbox checked in Normal modifier

plugin modifier PushIn
name:"Push In"
classID:#(0x133032167, 0x5104374)
extends:shell
replaceUI:true version:1
(
	parameters main rollout:params
	(
		push_amount type:#float animatable:true ui:push_amount default:0.5
		on push_amount set val do 
		(	
			delegate.innerAmount = val
			if $.modifiers["deleteMesh"] == undefined and $.modifiers["PushIn"] != undefined do 
			(
				modPanel.addModToSelection (DeleteMesh ()) ui:off
				modPanel.addModToSelection (MeshSelect ()) ui:off
				modPanel.addModToSelection (Normalmodifier ()) ui:on
				enableShowEndRes = true
				modPanel.setCurrentObject $.modifiers["PushIn"] ui:on
			)
		)
		straightenCorners type:#boolean animatable:false ui:straightenCorners default:true
		on straightenCorners set val do delegate.straightenCorners = val
	)
	rollout params "Parameters"
	(
		spinner push_amount "Push: " range:[0.0,1e9,0.0]
		checkbox straightenCorners "Straighten Corners" checked:true
	)
 
	on create do 
	(
		delegate.outerAmount = 0
		delegate.selectEdgeFaces = true
		delegate.selectOuterFaces = true
	)
)

thank you once again for your assistance

LittleLordPotala's picture

Script corrected

I updated the script as you like, according to your needs.

Best regards.

AttachmentSize
pushin.ms 1.15 KB
Anubis's picture

interesting topic

maybe puting this actions in separate callback w'd be more safety?

callbacks.removeScripts id:#ModPushInAdded
global cbfn_ModPushInAdded
 
fn cbfn_ModPushInAdded = (
	cbntf = callbacks.notificationParam()
	modPanel.setCurrentObject cbntf[2] node:cbntf[1] ui:on
	modPanel.addModToSelection (DeleteMesh ()) ui:off
	modPanel.addModToSelection (MeshSelect ()) ui:off
	modPanel.addModToSelection (Normalmodifier flip:on) ui:on
	enableShowEndRes = true
	modPanel.setCurrentObject cbntf[2] node:cbntf[1] ui:on
)
 
callbacks.addScript #postModifierAdded \
"cbfn_ModPushInAdded()" id:#ModPushInAdded

my recent MAXScripts RSS (archive here)

harumscarum's picture

interesting

but it crash max as soon as any modifier is applied
2012*64

Anubis's picture

weird...

am still on max2009 so someone else s'd verify this for max2012, but for sure find an mistake from my side... forget to check the class of the modifier (PushIn). here is edited version:

callbacks.removeScripts id:#ModPushInAdded
global cbfn_ModPushInAdded
 
fn cbfn_ModPushInAdded = (
	cbntf = callbacks.notificationParam()
	if classOf cbntf[2] == PushIn do -- check the modifier class
	(
		modPanel.setCurrentObject cbntf[2] node:cbntf[1] ui:on
		modPanel.addModToSelection (DeleteMesh ()) ui:off
		modPanel.addModToSelection (MeshSelect ()) ui:off
		modPanel.addModToSelection (Normalmodifier flip:on) ui:on
		enableShowEndRes = true
		modPanel.setCurrentObject cbntf[2] node:cbntf[1] ui:on
	)
)
 
callbacks.addScript #postModifierAdded \
"cbfn_ModPushInAdded()" id:#ModPushInAdded

P.S. - ah, and be sure you removed all "on push_amount set val do" handler as this will duplicate that behaviour and of'cuz will yield confusion.
the callback code you can store inside the plugin definision but looks more flexible to kept it outside.

my recent MAXScripts RSS (archive here)

LittleLordPotala's picture

About callbacks mechanism

The callbacks are not "more safety".
It takes a lot more internal resources, memory and codes protection.
It often creates conflicts with unexpected user operations.
I suggest you to also add the "removeScripts" at the end of the function
and to launch the callback in a local event of the script.

As the callbacks are global events, if any bug occurs, Max crashes.
On the other hand, the internal events of a scripted plug-in are local events,
so if any bug occurs, you have more chance to keep Max working.

---------------------------------------------------------------

I debugged the script with callback in Max 2012 but the selection in modify panel does not refresh correctly when "modPanel.setCurrentObject" is called inside the callback function. Otherwise it works but I like better the older version...

AttachmentSize
pushin2.ms 1.41 KB
Anubis's picture

well... yes and no

I see your args, personaly I prefer to avoid callbacks in any case then possible.
In this case adding external modifiers on the stack is just "stay alone automation" task, something out of the purpose of the modifier plugin itself. So my point is just logical.
In other words, even "callbacks.addScript/removeScripts" I'll keep out of the modifier plugin.
As alternative (w/o callback), you can use the plugins "on attachedToNode" handler, but ain't 100% sure that all this is safety (bug free).
Just my opinion ;) well done!

P.S. Keep in mind that i never tested (during my posts here) either of both version, and has some doubt on how the modifier w'd work then is apllied to multiple objects as instance. But now i tested both versions, so if by safety mean less crashes then that's true, as the second version crash Max in the described case (multiple objects selected), while the first version just fail to apply the modifier, return error and thats all.

my recent MAXScripts RSS (archive here)

harumscarum's picture

Thank you Lord!

is it possible to combine 5 modifiers into new one? here i attach illustration how simple sequence of actions produce straighten cornered push

AttachmentSize
push.png 19.96 KB
LittleLordPotala's picture

About Combo-modifiers

Maxscript doesn't allow to combine multiple modifiers.
But, anyway, you don't need 5 modifiers to do what you want but only two :
Shell + DeleteMesh. Look at the attached screenshot.

I also updated the small script "push2" that will automatically add the deleteMesh
modifier when you change, the first time, the spinner value.

AttachmentSize
push2a.ms 980 bytes
push.jpg 52.85 KB
LittleLordPotala's picture

Hi!To invert a sub-object

Hi!
To invert a sub-object selection, there is already two modifiers that can do that very easily : "Turn to Mesh" and "Turn to poly".
You just have to check the radio button "invert" and choose the selection level.
Anyway, you can also try my script "invertsel.ms", his name in modifier list is "Invert selection".

For the push modifier, it's impossible to add "straighten corners" option,
but I wrote a small scripted plug-in that modify the Shell modifier.
I called it "Push 2". So after you apply it, you just need to convert your object into editable_mesh or editable_poly, then delete the selected inner faces.
Of course, you can directly use the Shell modifier but with the script, it's easier. (See the attached file.)

I hope it helps !

Best regards.

AttachmentSize
push2.ms 744 bytes
invertsel.ms 202 bytes

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.