Hi
i have successfully created the ribbon tab in Autocad2010 and its load on startup of Autocad. When i change my workspace my ribbon tab disapear is there any way i can make my tab available in all workspaces.
i am not using CUI Customization.
Thanks
Solved! Go to Solution.
When you change workspace your ribbon wilI be unloaded. Listen to the SystemVariableChanged event and watch the WSCURRENT setting. This system variable will be changed when a new workspace become current. If this is changed you can run your code to add your ribbon tab.
Here is an example
public void Initialize()
{
if (Autodesk.Windows.ComponentManager.Ribbon == null)
{
//load the custom Ribbon on startup, but at this point
//the Ribbon control is not available, so register for
//an event and wait
Autodesk.Windows.ComponentManager.ItemInitialized +=
new EventHandler(ComponentManager_ItemInitialized);
//not in published sample
Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged += new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(Application_SystemVariableChanged);
}
else
{
//the assembly was loaded using NETLOAD, so the ribbon
//is available and we just create the ribbon
Your command for creating your ribbon 'createRibbon();'
Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged +=
new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(Application_SystemVariableChanged);
}
}
void Application_SystemVariableChanged(object sender,
Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
//Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
//ed.WriteMessage("\n-Sys Var Changed: " + e.Name);
if (e.Name.ToLower() == "wscurrent")
{
createRibbon();
}
}
Sorry about te bad code format but i think this will help.
I need to make a comment. Your code could crash is you change to a classic autocad workspace. The ribbon is disable here and calling it might chrash autocad. So make shure that you check if the ribbon is active. if not don't create your ribbon.
Irvin
Hi Irvin
This works Great when you chenge the workspace but not when you change something in the CUI menu.
br Magnus
I always use this website to translate C# code to vb.net code.
After translating, the code usually only needs some minor changes to work...
In this case I got a few errors, but I was able to get around them:
Public Sub Initialize() If Autodesk.Windows.ComponentManager.Ribbon Is Nothing Then 'load the custom Ribbon on startup, but at this point 'the Ribbon control is not available, so register for an event and wait Autodesk.Windows.ComponentManager.ItemInitialized += New EventHandler(ComponentManager_ItemInitialized) 'not in published sample Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged += New Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(AddressOf Application_SystemVariableChanged) Else 'the assembly was loaded using NETLOAD, so the ribbon is available and we just create the ribbon 'Your command for creating your ribbon 'createRibbon();' Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged += New Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(AddressOf Application_SystemVariableChanged) End If End Sub Private Sub Application_SystemVariableChanged(sender As Object, e As Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs) 'Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; 'ed.WriteMessage("\n-Sys Var Changed: " + e.Name); If e.Name.ToLower() = "wscurrent" Then createRibbon() End If End Sub
The way I got it to work was by doing it this way in VB.NET
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
'' Create a hook on the "Idle" event of the application class
AddHandler Application.Idle, AddressOf Applicatioin_Idle
'' Create a hook on the "System Varaible Change" event of the application class
AddHandler Application.SystemVariableChanged, AddressOf Application_SystemVariableChanged
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
End Sub
Public Sub Applicatioin_Idle(ByVal sender As Object, ByVal e As EventArgs)
RemoveHandler Application.Idle, AddressOf Applicatioin_Idle
Dim curWorkspace As String = Application.GetSystemVariable("WSCURRENT")
If curWorkspace.ToLower = "map classic workspace" Then
'' Add ToolBar
Else
CreateRibbon()
End If
End Sub
Public Sub Application_SystemVariableChanged(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs)
If e.Name.ToLower = "wscurrent" Then
Dim curWorkspace As String = Application.GetSystemVariable(e.Name)
If curWorkspace.ToLower = "map classic workspace" Then
'' Add ToolBar
Else
CreateRibbon()
End If
End If
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.