0

Working on an addin. Solidwokrs api documentation is very very bad made. Saw almost every video on youtube on the matter.

Simple thing is not working for me, cannot get why. Trying to add a menu to the bar.

    public bool ConnectToSW(object ThisSW, int Cookie)
    {
        SwApp = (SldWorks)ThisSW;
        var a = SwApp.AddMenu((int)swDocumentTypes_e.swDocPART, "MyMenu", 0);
        var b = SwApp.AddMenuItem5((int)swDocumentTypes_e.swDocPART, cook, "MyMenu@Tools", 1, "MyMenuCallback", "MyMenuEnableMethod", "My menu item", null);
        return true;
    }

Menu is not showing. I do get the access to the other functions.

CommandGroup is working thro, but I need only a menu.

        ICommandManager icmd = SwApp.GetCommandManager(cook);
        ICommandGroup cmdGroup;
        cmdGroup = icmd.CreateCommandGroup(1, "test", "tool test", "bla la", 0);
        icmd.AddContextMenu(0, "new");
        int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);
        cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", 0, menuToolbarOption);
        cmdGroup.HasToolbar = true;
        cmdGroup.HasMenu = true;
        cmdGroup.Activate();

Please advice. Thanks

(Found in the world wide web a post that "AddMenuItem5" probably has a bug, and "AddMenuItem4" does work. is this really a bug, or I'm missing something?)

1 Answer 1

2
public bool ConnectToSW(object ThisSW, int cookie)
{
    iSwApp = (ISldWorks)ThisSW;
    addinID = cookie;
         
    //Set up callbacks
    iSwApp.SetAddinCallbackInfo2(0, this, addinID);
         
    string[] c=new string[1];
    var a = SwApp.AddMenu((int)swDocumentTypes_e.swDocPART, "MyMenu", 0);
    var b = SwApp.AddMenuItem5((int)swDocumentTypes_e.swDocPART, cook, "Tools@MyMenu", 1, "MyMenuCallback", "MyMenuEnableMethod", "My menu item", c);
    return true;        
}

Use the & symbol to include an accelerator key, e.g., MyItem@, adds MyItem to the File menu with an accelerator key. To display the accelerator key, press the Alt key. The accelerator key is underlined.

For the last argument, you need to pass in an array of strings.

Here is the api: AddMenuItem5

1
  • No way!!! first - thanks! second its weird, compiler sees no error. it must be string array, null not accepted. i used null since i found couple demos with it. read api couple times and didnt catch it.
    – aleXela
    Commented Nov 12, 2024 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.