Entireweb

Free Search Engine Submission

Konga Deals

Monday 16 March 2015

How to create partial cuix that appends Panel to "Add-ins" tab.


Here is a sample code to create a partial cuix at runtime. It creates a ribbon panel with a command button. After the cuix is loaded in AutoCAD using cuiload, the panel should appear in the "Add-ins" tab.

 CustomizationSection csNew = new  CustomizationSection();
 csNew.MenuGroupName = "myMenuGroup" ;

 // Create a new menu macro
 MacroGroup myMacGroup =
     new  MacroGroup("myMacroGroup" ,
     csNew.MenuGroup);

 MenuMacro macroLine = myMacGroup.CreateMenuMacro(
         "TestLine" ,
         "^C^C_Line " ,
         "ID_MyLineCmd" ,
         "My Line help" ,
         MacroType.Any,
         "RCDATA_16_LINE" ,
         "RCDATA_32_LINE" ,
         "My Test Line" );

 RibbonRoot ribbonRoot = csNew.MenuGroup.RibbonRoot;

 // Create a panel
 RibbonPanelSource ribPanelSource
                 = new  RibbonPanelSource(ribbonRoot);
 ribPanelSource.Text = "MyPanel" ;

 // Create a ribbon row
 RibbonRow ribRow = new  RibbonRow();
 ribPanelSource.Items.Add((RibbonItem)ribRow);

 //Create a Ribbon Command Button
 RibbonCommandButton ribCommandButton
                    = new  RibbonCommandButton(ribRow);
 ribCommandButton.Text = "MyTestLineButton" ;
 ribCommandButton.MacroID = macroLine.ElementID;

 //Add the ribbon command button to the ribbon row
 ribRow.Items.Add((RibbonItem)ribCommandButton);

 //Get the panels from the RibbonRoot
 RibbonPanelSourceCollection panels
                 = ribbonRoot.RibbonPanelSources;

 // Add the Ribbon Panel Source to the Ribbon Panels
 panels.Add(ribPanelSource);

 RibbonTabSourceCollection tabs
                     = ribbonRoot.RibbonTabSources;

 // Create a new Ribbon Tab Source
 RibbonTabSource tabSrc
                 = new  RibbonTabSource(ribbonRoot);
 tabSrc.Name = "MyTab" ;
 tabSrc.Text = "MyTab" ;
 tabSrc.ElementID = "MyTabElementID" ;
 tabSrc.Aliases.Add("ID_ADDINSTAB" );
 tabSrc.WorkspaceBehavior
             = TabWorkspaceBehavior.MergeOrAddTab;
 tabs.Add(tabSrc);

 if  (tabSrc != null )
 {
     //Add the Panel to the Tab
     RibbonPanelSourceReference ribPanelSourceRef
             = new  RibbonPanelSourceReference(tabSrc);
     ribPanelSourceRef.PanelId
             = ribPanelSource.ElementID;
     ribPanelSourceRef.ElementID = "MyPanelID" ;
     tabSrc.Items.Add(ribPanelSourceRef);
 }

 csNew.SaveAs(strCuiFile);

No comments:

Post a Comment

Level 99 Denim

Level 99 Denim