Hello all,
I'm trying to writing some routines to control the visibility of my own toolbars.
Dim cs As CustomizationSection = New CustomizationSection(my_CuiFile, my_CuiName)
Dim tb As Autodesk.AutoCAD.Customization.Toolbar = cs.MenuGroup.Toolbars.FindToolbarWithName(my_ToolbarName)
tb.ToolbarVisible = ToolbarVisible.hide
After the last instruction the toolbar still stay visible.
Some suggestions are very appreciated.
Thankyou
Luigi
Hi Luigi,
Sorry for the delay.
Since your code is changing the cui, it will need to be saved and cuix reloaded for the visibility to get updated.
You can try doing that as in this code snippet.
[DllImport("accore.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedCmd")] private static extern int acedCmd(System.IntPtr vlist); [DllImport("accore.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ads_queueexpr")] extern static int ads_queueexpr(byte[] command); public void saveCui() { // Save all Changes made to the CUI file in this session. // If changes were made to the Main CUI file - save it // If changes were made to teh Partial CUI files need to save them too if (cs.IsModified) cs.Save(); for (int i = 0; i < numPartialFiles; i++) { if (partials[i].IsModified) partials[i].Save(); } // Here we unload and reload the main CUI file so the changes to the CUI file could take effect immediately. // To do this we P/Invoke into acedCmd() in order to synchronously call the CUIUNLOAD / CUILOAD command, disarming and // rearming the file dialog during the process. ResultBuffer rb = new ResultBuffer(); // RTSTR = 5005 rb.Add(new TypedValue(5005, "FILEDIA")); rb.Add(new TypedValue(5005, "0")); // start the insert command acedCmd(rb.UnmanagedObject); string cuiFileName = cs.CUIFileBaseName; //CUIUNLOAD rb = new ResultBuffer(); rb.Add(new TypedValue(5005, "_CUIUNLOAD")); rb.Add(new TypedValue(5005, cuiFileName)); acedCmd(rb.UnmanagedObject); //CUILOAD rb = new ResultBuffer(); rb.Add(new TypedValue(5005, "_CUILOAD")); rb.Add(new TypedValue(5005, cuiFileName)); acedCmd(rb.UnmanagedObject); //FILEDIA rb = new ResultBuffer(); rb.Add(new TypedValue(5005, "FILEDIA")); rb.Add(new TypedValue(5005, "1")); acedCmd(rb.UnmanagedObject); }
But I think it would be much simpler to show/hide toolbars simply by sending the commands as in these Lisp statements :
(command "toolbar" "Draw" "show") (command "toolbar" "Draw" "hide")
Regards,
Balaji
Thankyou Balaji, I will try the suggestion and send a feedback as soon as possible.
Ok Balaji
as per your suggestion I tried the lisp strings.
Briefly my need is to automatic load my custom cuix file and switching my toolbars depending what workspace is selected, the toolbars are to be displayed only in "AutoCAD Classic" display mode, so:
Namespace ManagedApplication
Public Class Initialization
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
Const cuiname As String = "MY_CUINAME"
Dim cuifile As String = "C:\[...]\MY_CUIFILE.cuix"
Dim mGroup As AcadMenuGroup
Try 'Testing the presence of the cuix
mGroup = Autodesk.AutoCAD.ApplicationServices.Application.MenuGroups.Item(cuiname)
Catch ex As System.Exception 'If not, the cuix is loaded
Autodesk.AutoCAD.ApplicationServices.Application.LoadPartialMenu(cuifile)
End Try
So, for toggle ON/OFF the toolbar by switching from one workspace to another there are the two following routines:
Sub CmdEnded(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Select Case e.GlobalCommandName
Case "RIBBONCLOSE"
doc.SendStringToExecute("(command" & " ""_toolbar"" " & " ""my_ToolbarName"" " & " ""_hide"") ", False, False, True)
Case "RIBBON"
doc.SendStringToExecute("(command" & " ""_toolbar"" " & " ""my_ToolbarName"" " & " ""_hide"") ", False, False, True)
End Select
End Sub
Sub Application_SystemVariableChanged(ByVal sender As Object, ByVal e As _ Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs)
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Select Case e.Name
Case "WSCURRENT"
Select Case Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("RIBBONSTATE")
Case 0
doc.SendStringToExecute("(command" & " ""_toolbar"" " & " ""my_ToolbarName"" " & " ""_show"") ", False, False, True)
Case 1
doc.SendStringToExecute("(command" & " ""_toolbar"" " & " ""my_ToolbarName"" " & " ""_hide"") ", False, False, True)
End Select
Case "RIBBONCLOSE"
doc.SendStringToExecute("(command" & " ""_toolbar"" " & " ""my_ToolbarName"" " & " ""_hide"") ", False, False, True)
Case "RIBBON"
doc.SendStringToExecute("(command" & " ""_toolbar"" " & " ""my_ToolbarName"" " & " ""_hide"") ", False, False, True)
End Select
End Sub
End Class
End Namespace
I tested the routine and seems to work fine.
It's a good way to proceed, or there is another better one, or more elegant?
Thank you for help
Luigi