Notifications
Clear all

[Closed] dynamic Context menu – select by modifier


(
	local form = dotnetobject "MaxCustomControls.Maxform"
	form.ShowInTaskbar = off
	form.FormBorderStyle = form.FormBorderStyle.None
	form.AllowTransparency = on
	form.Opacity = 0
	 --form.TransparencyKey = form.Backcolor

	form.StartPosition = form.StartPosition.Manual
	form.Size = Form.MinimumSize

	cursor = dotnetclass "System.Windows.Forms.Cursor"
	p = cursor.Position	

	form.Location =  dotnetobject "System.Drawing.Point" p.x (p.y+5) --500 300

	cm = dotNetObject "ContextMenu"
	
	form.ContextMenu = cm	
		
	items = for i in selection[1].modifiers collect i.name	
	
	fn selObject sender arg=
	(
		theSelection=#()

		for j in objects do
		(
			for k in j.modifiers do
			(
				If ((classof k) as string) == arg do appendIfUnique theSelection j
			)
		)
		print theSelection
	)

		
	for i in items do
	(
		item = cm.menuitems.add i
		item.name = i
		dotnet.addEventHandler item "Click" selObject  
	)


......


I want to select modifier by the name of context menu title I click, but when I try to execute the script…at the name of context menu …the result always display “false”…please someone give me input how to make it work…

thanks many and best regard

fajar

4 Replies

something like this:


try(form.close()) catch()
(
	global form = dotnetobject "MaxCustomControls.Maxform"
	form.ShowInTaskbar = form.MinimizeBox = form.MaximizeBox = off
	form.StartPosition = form.StartPosition.Manual
	form.Bounds = dotnetobject "System.Drawing.Rectangle" 800 200 100 60

	cm = dotNetObject "ContextMenu"
	
	fn onPopup s e = 
	(
		fn onClick s e = undo "Delete" on deletemodifier s.parent.tag.value s.tag.value
		for n in selection do
		(
			item = dotnetobject "MenuItem" n.name
			item.tag = dotnetmxsvalue n
			item.enabled = (n.modifiers.count > 0)
			
			for m in n.modifiers do
			(
				i = dotnetobject "MenuItem" m.name
				i.tag = dotnetmxsvalue m
				dotnet.addEventHandler i "Click" onClick
				item.menuitems.add i
			)
			s.menuitems.add item
		)
	)
	fn onCollapse s e = s.menuitems.Clear()
	
	dotnet.addEventHandler cm "Popup" onPopup
	dotnet.addEventHandler cm "Collapse" onCollapse
	
	form.ContextMenu = cm	
	form.showmodeless()
)		

(
	delete objects 
	for k=1 to 8 do
	(
		n = #(box, sphere, cylinder, cone)[random 1 4] pos:(random -[50,50,50] [50,50,50]) wirecolor:(random red green)
		for i=1 to (random 0 5) do addmodifier n (#(UVWmap, Unwrap_UVW, Edit_Poly, Edit_Normals, XForm)[random 1 5]())  
	)
	redrawviews()
)

Thank denis…i got the big idea…but something is bugging me …what do you mean by …

onPopup s e … what s …what e…sorry new dotnet learner…

also I just want to show the rc menu (right click only ) without empty dialog …is that posible ?

thanks for input …

best regard

fajar

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

if i answer all your questions providing a sample code i will completely write your script for you

you have to read about dotnet event system, what the sender is, and the event argument it. the mxs help is a good start. there are many samples on this forum…

so its the same sender and arg …hmm…