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

RibbonTab in all Workspaces

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
mnav
2991 Views, 7 Replies

RibbonTab in all Workspaces

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

7 REPLIES 7
Message 2 of 8
Irvin
in reply to: mnav

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.

Message 3 of 8
mnav
in reply to: Irvin

Thanks a lot.... you the MAN.......

Message 4 of 8
Irvin
in reply to: mnav

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

Message 5 of 8
mamj
in reply to: Irvin

Hi Irvin

 

This works Great when you chenge the workspace but not when you change something in the CUI menu.

 

br Magnus

Message 6 of 8
chase.hochstrasser
in reply to: Irvin

Can you convert this to VB.NET instead?
Message 7 of 8
R.Gerritsen4967
in reply to: mnav

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

 

Message 8 of 8

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.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost