Best practice: loading a cuix vs generating the ribbon from code

Best practice: loading a cuix vs generating the ribbon from code

stefanome
Collaborator Collaborator
1,009 Views
8 Replies
Message 1 of 9

Best practice: loading a cuix vs generating the ribbon from code

stefanome
Collaborator
Collaborator

Is it better to manually create a cuix and then have the addin load it, or have the addin generating its own UI from code?

 

What are the pros and cons for each of the two approaches?

0 Likes
Accepted solutions (1)
1,010 Views
8 Replies
Replies (8)
Message 2 of 9

Jeff_M
Consultant
Consultant

I prefer the code route, that way I don't need to maintain a separate cuix file.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 9

stefanome
Collaborator
Collaborator

Thanks,

 

Generating the UI from code you don't need to maintain a separate file, but what about the bitmaps? Do I need to deploy a folder with all the bitmaps together with the dll?

If yes, do you find it easier than managing the cuix file?

If no, how are the bitmaps included in the dll?

 

(In the past I created an addin for Revit where I used a json file with all the information required to generate the UI elements. It was working, I liked that approach, but that project has been cancelled and was never deployed, so I never crossed the deployment bridge. But this is AutoCAD anyway and things are different.)

 

I tried to go the code direction, but I was not able to find an example that shows how to do it.

 

I tried with some examples from the documentation, but no luck. The first line on this page for example doesn't even compile:

// the documentation shows:
RibbonButton button1 = new RibbonButton;

// it should be:
RibbonButton button1 = new RibbonButton(<missing parent>);

 

Can you point me to a working documentation page or to a working example?

0 Likes
Message 4 of 9

Jeff_M
Consultant
Consultant
Accepted solution

The images (I use PNG's, converted in code to the icon bitmap...this code has been posted before by others, will repost if you can't locate it) for the bitmaps are included in the Project's resources so get compiled into the DLL. Here is a short example of creating a ribbon tab and panel in code:

using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;

namespace AutoCADRibbonTesting
{
    public class Class1
    {
        [CommandMethod("testmyRibbon")]
        public void Testme()
        {
            RibbonControl ribbon = ComponentManager.Ribbon;
            if (ribbon != null)
            {
                RibbonTab rtab = ribbon.FindTab("TESTME");
                if (rtab != null)
                {
                    ribbon.Tabs.Remove(rtab);
                }
                rtab = new RibbonTab();
                rtab.Title = "TEST  ME";
                rtab.Id = "Testing";
                //Add the Tab
                ribbon.Tabs.Add(rtab);
                addContent(rtab);

            }
        }

        static void addContent(RibbonTab rtab)
        {
            rtab.Panels.Add(AddOnePanel());
        }

        static RibbonPanel AddOnePanel()
        {
            RibbonButton rb;
            RibbonRowBreak rbrk;
            RibbonPanelSource rps = new RibbonPanelSource();
            rps.Title = "Test One";
            RibbonPanel rp = new RibbonPanel();
            rp.Source = rps;

            rb = new RibbonButton();
            rb.Name = "Test Button 1";
            rb.ShowText = true;
            rb.Text = "Test Button 1";
            //Add the Button to the Tab
            rps.Items.Add(rb);

            rbrk = new RibbonRowBreak();
            rps.Items.Add(rbrk);

            rb = new RibbonButton();
            rb.Name = "Test Button 2";
            rb.ShowText = true;
            rb.Text = "Test Button 2";
            //Add the Button to the Tab
            rps.Items.Add(rb);

            rbrk = new RibbonRowBreak();
            rps.Items.Add(rbrk);
            rb = new RibbonButton();
            rb.Name = "Test Button 3";
            rb.ShowText = true;
            rb.Text = "Test Button 3";
            //Add the Button to the Tab
            rps.Items.Add(rb);

            rbrk = new RibbonRowBreak();
            rps.Items.Add(rbrk);
            rb = new RibbonButton();
            rb.Name = "Test Button 4";
            rb.ShowText = true;
            rb.Text = "Test Button 4";
            //Add the Button to the Tab
            rps.Items.Add(rb);

            return rp;
        }
    }
}
Jeff_M, also a frequent Swamper
EESignature
Message 5 of 9

hippe013
Advisor
Advisor

@Jeff_M 

 

Rather minor, but your code as it stands creates duplicate tabs.

 

RibbonTab rtab = ribbon.FindTab("TESTME");

 

Should be

 

RibbonTab rtab = ribbon.FindTab("Testing");

 

0 Likes
Message 6 of 9

Jeff_M
Consultant
Consultant

@hippe013 I put that in there to see if anyone was actually checking it out . 😆 Funny no one has caught that the few other times I've posted the code. Thanks for catching it!

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 9

karl.sch1983
Advocate
Advocate

Hi @Jeff_M@hippe013. I have started a post here and here. I was wondering if either of you can confirm that ribbon runtime API route does not allow for icons to be displayed next to command name in command line. Seems like @Jeff_M has chosen the code route and I was wondering if you could shed some light. Thank you all.

0 Likes
Message 8 of 9

Jeff_M
Consultant
Consultant

@karl.sch1983 to be perfectly honest, I don't recall even noticing that there is an icon displayed in the command line...I had to go look, used the Line command and Hah! sure enough, a line icon. Therefor I've never looked into whether we can add them in code. A quick look at the docs and I didn't find anything. The closest I came is THIS blog post, but it creates a CUIX file.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 9 of 9

karl.sch1983
Advocate
Advocate

Thanks @Jeff_M. That is what I suspected from all the posts I could find. I will see if there is any method exposed in ObjectARX. Thanks again for your time.

0 Likes