SW API AddContextMenu

Guys, please!! anyone! dying here…

Trying to make a simple ContextMenu in a part.

SW API AddContextMenu

cannot get it done. googled any combination. spent hours trying diff approaches. NOTHING!!
Im sure i’m missing a very small details here. but i cannot get which one (((

please adivce:
the code is pretty simple (for a test)

internal static SldWorks SwApp;
internal static int cookie; 
public bool ConnectToSW(object ThisSW, int Cookie)
{
 SwApp = (SldWorks)ThisSW;
 cookie = Cookie;

 ICommandManager icmd = SwApp.GetCommandManager(cookie);
 ICommandGroup cmdGroup;    
 
 var a = icmd.AddContextMenu(1, "Test");
 a.SelectType = (int)swSelectType_e.swSelEVERYTHING; //tried other options too
 a.AddCommandItem2("Test2", -1, "hint", "tool tip", 1, "Booom", "", 1, (int)(swCommandItemType_e.swMenuItem));
 a.ShowInDocumentType = (int)swDocumentTypes_e.swDocPART;
 a.HasMenu = true;
 //a.Activate(); //cannot be set on conntextmenu object. only on CommanndGroup.
 //cmdGroup.AddCommandGroup2(); // working. Im able to add both menu and toolbar (but not contextmenu)

 return true;
}

Thanks!!!

If i'm already asking, how do I add ca callback to contextMenu? thanks agian

use SolidDNA to build SOLIDWORKS add-ins https://github.com/cad-booster/solidworks-api

Hey, thanks, but I dont want to use a framework. Checked both SW frameworks and didnt find an answer to my question.

2 Answers

2

Have you tried AddMenuPopupItem4?

Yep, same thing. But it's not I need anyway. Cannot get the reason why ContextMenu not working (

I made it work, but its in the feature manager (window), i need it on a main view. thanks anyway

I am trying to add a personalized item to the context menu of the Feature Manager pane. Could you please suggest how I can achieve this? I understand that you have done it before. Thank you in advance for your help!

See the examples provided in the SDK. It shows you everything you need to do.

No man. If it would show me and if it did work i wouldn't ask. Did you open the api page anyway?? It was no examples.

I don't think the SDK is in the API help. You can get it from the SOLIDWORKS installer.