Create customization (CUI) file with C# and load it

Hello,

I'm trying to create a new toolbar with few icons and append it next to existing Bricscad toolbars when user calls a command.
AcadToolbarItems are hold by AcadToolbar container, which is hold by AcadMenuGroup. The only way to insert a new menu group in AcadMenuGroups collection is by Load method, which, by its side, needs an existing CUI file path.
How I can create an instance of AcadMenuGroupClass or how to create cui file with c#?
Searched the forum profoundly and didn't find anything that may help :) .

Best regards, Angel!

.net, C#, CUI, Customization

Comments

  • If you not want to create a new menu/cui file, then you can add your toolbar into an existign menu group -
    at least, the BricsCAD group is always present ...
    but this could result in the fact, that your toolbar is written into standard cui file then ... which is updated when
    BricsCAD is closed.

    Hence, you will need to monitor shutdown, and remove your toolbar again, before exit operation starts :-)
    hope this helps ?

  • Thank you, for your fast response!

    Generally, I want to create a new cui file and load it on every BricsCAD startup. On shutdown it will be unloaded. Let me to explain why this is necessary :).
    I am migrating existing AutoCAD plugins for BricsCAD. I manage to migrate a several new commands each day. A new command is completely migrated when it work properly in BricsCAD and when there is a corresponding toolbar icon. So, lets say, I create cui file once. I have to add manually each new command every day. Instead, I have a helper class, that scans my plugins assembly on startup, finds all command methods and corresponding icons by convention, generates and saves cui file(overrides existing one) and loads it in Bricscad. 
    When I am done with all commands, I will change the strategy, because cui file will be the same every time.

    I would like to point me out an example (be so kind, please), where a new cui file is created with .net api :) Meanwhile, I will continue to search the forum and reflector!

    Best regards, Angel!

  • Dear Angel,

    not sure whether it is possible to create a .cui file with .NET (I'm not expert here ...);

    The way I mentioned before should be able to do that approach - only the .cui file should exist, and have its own MenuGroup.
    Then you can create new Toolbars via COM/NET, add to the toolbars collection of your own menu/cui (via MenuGroup name),
    and it should be written into that menu/cui file on shutdown ...

    Personally, I would do your approach in different way :-)
    You can use the old-style .mnu/mns file - that is plain ASCII file with simple structure - your parser can check for **TOOLBARS
    section, and simple write all toolbar specifications then ...

    On start, you can use _menuload with name.mns, and the .cui is recreated again (maybe deleting that existing .cui before) ...
    In the final end, you will need very few manual post-processing, to get the resulting .cui polished ...

    maybe an idea ...
    many greetings !
  • Thank you, very much!

    I would try the first thing that you suggest - load an empty cui file and create new Toolbars. In fact, I started to do that before Christmas vacation and it will be ready soon.

    Thank you, for dedicated time and for your suggestions. I wish you a successful new Year!
  • Dear Angel,

    nothing to thank for :-)
    It is our pleasure to assist as best as possible ... and we also learn from all the topics here in forum :-)

    All the best wishes for you as well.
  • Please consider following scenario: 

    - I have an empty CUI file with single MenuGroup inside;
    [code] <?xml version="1.0" encoding="UTF-8" standalone="no" ?>

     

    [/code]

    - Using .net code I'm loading this file and add some toolbars and buttons;
    [code]
    myMenu = Application.AcadApplication.MenuGroups.Load("MyPartialCuiFile.cui")
    toolbar1 = myMenu.Toolbars.Add("Toolbar1")
    toolbar1.AddToolbarButton(-1,"name","help string","command")
    [/code]

    - All toolbars and buttons appear in BricsCAD;

    - Close BricsCAD;

    - Open it again and none of my toolbars are displayed and further more, none of them are defined, when I check customization window;

    Here is my understanding:
    I found that BricsCAD saves information about interface items into default.cui file in "AppData\Roaming\Bricsys\BricsCAD\V16x64\en_US\Support" folder.
    BricsCAD saves this file several times - when call CUI command, when load a new cui file (no mater manually or with .net code) and when exit BricsCAD.
    In this file BricsCAD saves the path of the partial cui files that it has to load and the schema of the menu.
    Newly created toolbars and buttons are saved into partial cui file.
    But when I generate menu items with c#, they are NOT saved into partial file. They are not saved anywhere. I'm calling 
    [code]
    myMenu.Save(AcMenuFileType.acMenuFileSource)
    [/code]
    in order to save partial cui file but it stays untouched.

    Could you point me out, what I am doing wrong or what is my misunderstanding?
  • Dear Angel,

    personally, I would assume that BricsCAD should save the cui file at least at exit/shutdown, as it was modified via API ...
    I would treat this as a defect;
    if saving does not happen in your scenario, please send us a support request, we should fix the behaviour.
    (besides, your code seems all fine so far from your description ?)

    many greetings !
  • Hello hello,
    A simple test project is attached :)

    SavePartialCustomizationFile(2).zip

This discussion has been closed.