disable item in RC menu and in dropdownList menu

I have a RCmenu and It's working fine, but I don't know how to disable item in some circumstances

fn createMenu =
(
	rcMenu rcTest
	(
		menuItem miItem1 "name1"
		menuItem miItem2 "name2"
		menuItem miItem3 "name3"
		seperator menuSep01
		menuItem miItem4 "name4"
	)
        if a==0 then
           miItem1.enabled = false  --<<<<<< ??????????????????? >>>>>
        on miItem1 picked do  
	   print "1"
        ...
 
)

and a dropdownList menu where I want to disable items:

 dropdownList FilterSelect pos:[427,21] width:110 height:200
items:#("001", "002", "003", "004")
if a == 0 then item "002".enabled = false

Comments

Comment viewing options

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

srry

it's my fault! I wanted to call delete item in another function but inside yours it's working!!

artrender.info's picture

i've tried

deleteItem BitmapLister.FilterSelect.items[9]
and 
deleteItem BitmapLister.FilterSelect.items(finditem BitmapLister.FilterSelect.items "Map Intances")

and first gives error, the second does not delete!

barigazy's picture

when you use deleteItem

when you use deleteItem method then you need:

deleteItem array index

barigazy

artrender.info's picture

Barigazy

I get error for deleteitem

>> MAXScript Rollout Handler Exception:
-- No "deleteItem" function for "Map Intances" <<

artrender.info's picture

this is what I've came up with

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
		fn onClick s e = print "haha"
 
		for n in selection do
		(
			item = dotnetobject "MenuItem" n.name
			item.tag = dotnetmxsvalue n
			item.enabled = true--(n.modifiers.count > 0)
			s.menuitems.add item
			dotnet.addEventHandler item "Click" onClick
		)
	)
	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()
)

But how to use this menu in maxscript with rollout? How to add separator, how to detect which item was picked like in standard rcmenu?

artrender.info's picture

Oh, yeeeeeeeeeeeeeees!!!

this is a HUGE HELP, BARIGAZY!

THANK YOUUUUUUUUUUU!

artrender.info's picture

Barigazyyyyyyyyyyyyy! Thank you soooo much!

Help me please to disable items in RCMenu or to add them at a certain level (for example between item 2 and 3)

barigazy's picture

...

In second example you can see how to disable items.
Select some yellow object and press rightclick on form

barigazy

barigazy's picture

...

I told you I not use RCMenu
Better way

fn defDDListItems ddlist choise: itm: =
(
	ddlist.items = case choise of
	(
		(0): deleteItem ddlist.items (finditem ddlist.items itm)
		(1): deleteItem ddlist.items (finditem ddlist.items itm)
		(2): 
		(   
			 local arr = ddlist.items
			 appendIfUnique arr itm ; sort arr
		)
		default:#("001", "002", "003", "004") -- if not used 0,1,2 or any other choise
	)
)
 
 
dropdownList FilterSelect pos:[427,21] width:110 height:200 items:#("001", "002", "003", "004")
 
defDDListItems testroll.FilterSelect choise:0 itm:"002"
defDDListItems testroll.FilterSelect choise:1 itm:"004"
defDDListItems testroll.FilterSelect choise:2 itm:"006"
defDDListItems testroll.FilterSelect choise:#default itm:

barigazy

barigazy's picture

:)

This is very cool and much better then RCmenue
#1 examples by DenisT

 global form
  try(form.close()) catch()
  (
  	 form = dotnetobject "MaxCustomControls.Maxform"
  	form.ShowIcon = form.ShowInTaskbar = form.MaximizeBox = form.MinimizeBox = off
  	form.StartPosition = form.StartPosition.Manual
  	form.Text = "Owner Draw Menu Item"
  	form.Bounds = dotnetobject "System.Drawing.Rectangle" 500 300 200 100
 
  	fn onDrawItem s e = 
  	(
  		g = e.Graphics
  		g.PixelOffsetMode = g.PixelOffsetMode.HighQuality
  		g.SmoothingMode = g.SmoothingMode.HighQuality
 
  		case of
  		(
  			(dotnet.compareEnums e.State e.State.Selected):
  			(
  				back = (dotnetclass "System.Drawing.Brushes").LightSalmon
  				fore = (dotnetclass "System.Drawing.Brushes").Black
  			)
  			default:
  			(
  				back = (dotnetclass "System.Drawing.Brushes").Salmon
  				fore = (dotnetclass "System.Drawing.Brushes").Black
  			)
  		)
  		g.FillRectangle back e.Bounds
  		g.DrawString s.Text (dotnetobject "System.Drawing.Font" e.Font e.Font.Style.Bold) fore 16 10
  	)
  	fn onMeasureItem s e = 
  	(
  		e.ItemHeight = 40
  		e.ItemWidth = 100
  	)
 
  	cm = dotNetObject "ContextMenu"
 
  	item = cm.menuitems.Add "Geometry"
  	item.OwnerDraw = on
  	item.Enabled = off
  	dotnet.addeventhandler item "DrawItem" onDrawItem
  	dotnet.addeventhandler item "MeasureItem" onMeasureItem		
 
  	fn onItemClick s e = (format "click: %\n" s.Text)
 
  	item = cm.menuitems.Add "Sphere"
  	dotnet.addeventhandler item "Click" onItemClick		
  	item = cm.menuitems.Add "Cone"		
  	dotnet.addeventhandler item "Click" onItemClick	
 
  	form.ContextMenu = cm
  	form.Showmodeless() 
  )

barigazy

Comment viewing options

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