Notifications
Clear all

[Closed] [MXS] Adding custom item to "Convert To:" quad menu

Hi,
I’m trying to figure out how to add custom MacroScript item to the right-click quad menu under the “Convert To:” submenu, for example “Convert to MyOwnClass object”. I’ve read the docs, but I’m not really sure how to use the menu manager properly.

9 Replies

this will get the menu unless other things have been added after the “convert to”


fn GetConvertToMenu =
(    
    qm = menuMan.findQuadMenu "Default Viewport Quad";
    if qm != undefined then
    (
        mnu = qm.getMenu 1; -- bottom right    
        if mnu != undefined then
        (
            converttoitem = mnu.getitem (mnu.numItems())
            if     converttoitem != undefined then
                return     converttoitem.getSubMenu();
        )
    )
    undefined;
)   

the menu needs an accompanying “context”macroscript to work correctly for example the edit mesh context script


MacroScript Convert_to_Mesh 
enabledIn:#("max", "viz", "vizr") --pfb: 2003.12.12 added product switch
    ButtonText:"Convert to Editable Mesh" 
    Category:"Modifier Stack" 
    internalCategory:"Modifier Stack" 
    Tooltip:"Convert to Editable Mesh" 
    Icon:#("Max_edit_modifiers",1)
(    

    On isEnabled return (Try(Selection.count != 0 and CanConvertTo Selection[1] Mesh)Catch())
    On isVisible return (Try(Selection.count != 0 and CanConvertTo Selection[1] Mesh)Catch()) 
    On Execute Do    
    (
        SuspendEditing()
        for obj in selection do
        (
            Try(ConvertToMesh obj)Catch() 
        )
        ResumeEditing()
        Max modify mode
    )
)  

then you can register (add the new item with something like (untested)


   if menuMan.registerMenuContext 0x36690115 then
(
    converttomenu = GetConvertToMenu();

    if converttomenu  != undefined then
    (    
        local convertItem = menuMan.createActionItem "Convert_to_Mesh" "Convert to EditableMesh" -- this will be your type
        converttomenu.addItem convertItem  -1
    )
)     
1 Reply
(@tamyl)
Joined: 10 months ago

Posts: 0

Okay, and what if there was something added? Is there a way to handle it and get the correct “Convert To” item?

you can test against the menu item title for all items in the menu but that has the same issues if the user has added his own menu with the same title or renamed the one your looking for!

Yes, that’s exactly what I just did and it works fine. I think the probability of adding another “Convert To:” item by the user is much lower than adding any item, so parsing the strings is much safer way In my case I’m always getting “Corona Converter” item by getting the mnu.getitem (mnu.numItems()).Thanks for help!

i have a recommendation… DON’T use try/catch in macro handlers (isEnabled, isChecked)
there are a lot of events that cause them fire. In your case instead of using try(convertto …) catch() use canconvertto , it’s much faster. see the difference:


(
   t = timestamp()
   h = heapfree
   for k=1 to 1000 do
   (
      try(convertto $ editable_mesh) catch()
      --canconvertto $ editable_mesh
   )
   format "time:% heap:%
" (timestamp() - t) (h - heapfree)
)
/* results *****
time:332 heap:128L
-- time:1 heap:128L
*/

I was interested to see how this would be done via the sdk, I’m still none the wiser, no examples and rubbish reference and an array of convoluted abstract classes

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

are you asking about adding menus via sdk?

i found what I was looking for

good… it’s all in imenuman.h