.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copying ACAD ribbon panel to custom ribbon tab

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
elliottpd11
1297 Views, 4 Replies

Copying ACAD ribbon panel to custom ribbon tab

I have custom ribbon tabs created using Autodesk.Windows.RibbonTab.  I would like to copy AutoCAD's Windows panel from the standard View tab to my custom tab.  The wrinkle is that the ACAD.cuix is loaded as partial to our custom Enterprise menu, and the View tab is not loaded in the workspace.  I think this is possible, but haven't been able to assemble the right API calls to do it.  I would greatly appreciate assistance with some sample code.

Best Regards,

Pete Elliott

4 REPLIES 4
Message 2 of 5

Hi Pete,

 

Here is some code that illustrates how to load a Tab in the current workspace from a partial, you should be able to enhance it a little to add a WSRibbonTabSourceReference to a pscific tab instead:

 

[CommandMethod("AddTabFromPartial")]
public void AddTabFromPartial()
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

    string mainCuiFile = (string)Application.GetSystemVariable("MENUNAME");

    CustomizationSection cs = new CustomizationSection(mainCuiFile + ".cuix");

    string strWrkSpaceName = "Acme Workspace";

    int idx = cs.Workspaces.IndexOfWorkspaceName(strWrkSpaceName);

    if (idx == -1)
    {
        ed.WriteMessage("\n" + strWrkSpaceName + " doesn't exist...");
        return;
    }

    string partialPath = @"C:\Temp\partial.cuix";

    CustomizationSection partial = new CustomizationSection(partialPath);

    if (!cs.PartialCuiFiles.Contains(partialPath)) 
        cs.PartialCuiFiles.Add(partialPath);

    string strTabElementId = "ADN_TAB_ID";  

    WSRibbonTabSourceReference wsRibTabSrcRef = createWSRibbonTabSrcReference(
        strTabElementId, 
        partial);

    if (wsRibTabSrcRef == null)
    {
        ed.WriteMessage("Failed to create WSRibbonTabSourceReference\n");
        return;
    }

    Autodesk.AutoCAD.Customization.Workspace ws = cs.Workspaces[idx];

    wsRibTabSrcRef.SetParent(ws.WorkspaceRibbonRoot);

    ws.WorkspaceRibbonRoot.WorkspaceTabs.Add(wsRibTabSrcRef);

    if (cs.IsModified) 
        cs.Save();

    if (partial.IsModified) 
        partial.Save();

    // Here we unload and reload the main CUI file 
    // so the changes to the CUI file could take effect immediately.
    var doc = Application.DocumentManager.MdiActiveDocument;

    doc.SendStringToExecute("FILEDIA 0 ", false, false, false);
doc.SendStringToExecute(
"cuiunload " + cs.CUIFileBaseName + " ", false, false, false);
doc.SendStringToExecute(
"cuiload " + cs.CUIFileBaseName + " ", false, false, false); doc.SendStringToExecute("FILEDIA 1 ", false, false, false); doc.SendStringToExecute("WSCURRENT " + strWrkSpaceName + "\n", false, false, true); doc.SendStringToExecute("RIBBON ", false, false, true); } WSRibbonTabSourceReference createWSRibbonTabSrcReference( String tabId, CustomizationSection cs) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; try { RibbonRoot ribbonRoot = cs.MenuGroup.RibbonRoot; if (ribbonRoot == null) { ed.WriteMessage("RibbonRoot Not found\n"); return null; } RibbonTabSource ribTabsrc=ribbonRoot.FindTab(tabId); if (ribTabsrc== null) { ed.WriteMessage("Ribbon Tab \"" + tabId + "\" Not found\n"); return null; } //Create the WSRibbonTabSourceReference using the RibbonTabSource return WSRibbonTabSourceReference.Create(ribTabSrc); } catch (System.Exception ex) { ed.WriteMessage(ex.ToString()); return null; } }

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 5

Thanks, Philippe, for a potential solution.  But what I was hoping to do is to copy the Windows panel of the View tab to a Autodesk.Windows.RibbonTab using code.  The SendStringToExecute calls will be too slow for us.  Perhaps there is no interoperabilty between Autodesk.AutoCAD.Customization and Autodesk.Windows, making that impossible?

Best Regards,

Pete Elliott

Message 4 of 5

There is no hope for that ... if the ribbon items you are looking for, in that case the panels from the View tab, are not loaded, you cannot rely on the runtime API, you need to load them using the CUI API, hence relying on sending CUIUNLOAD/CUILOAD to the command line.

 

You may want to try P/Invoking acedCommandS instead of SendStringToExecute but I doubt it will be faster.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 5 of 5

It is work!thanks a lot!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost