.NET

Reply
Valued Contributor
58 Posts
0 Kudos
Registered: ‎12-15-2009
Post 1 of 8
Accepted Solution

RibbonTab in all Workspaces

1194 Views, 7 Replies
12-15-2010 01:35 AM

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

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.

Distinguished Contributor
112 Posts
10 Kudos
Registered: ‎04-22-2009
Post 2 of 8

Re: RibbonTab in all Workspaces

12-15-2010 02:33 AM 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.

Valued Contributor
58 Posts
0 Kudos
Registered: ‎12-15-2009
Post 3 of 8

Re: RibbonTab in all Workspaces

12-15-2010 03:03 AM in reply to: Irvin

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

Distinguished Contributor
112 Posts
10 Kudos
Registered: ‎04-22-2009
Post 4 of 8

Re: RibbonTab in all Workspaces

12-15-2010 07:14 AM 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

Active Contributor
36 Posts
0 Kudos
Registered: ‎05-31-2007
Post 5 of 8

Re: RibbonTab in all Workspaces

05-18-2011 12:35 AM 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

Active Contributor
42 Posts
1 Kudo
Registered: ‎07-17-2013
Post 6 of 8

Re: RibbonTab in all Workspaces

08-19-2013 02:06 PM in reply to: Irvin
Can you convert this to VB.NET instead?
Active Contributor
47 Posts
4 Kudos
Registered: ‎07-31-2009
Post 7 of 8

Re: RibbonTab in all Workspaces

08-20-2013 12:30 AM 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

 

Active Contributor
42 Posts
1 Kudo
Registered: ‎07-17-2013
Post 8 of 8

Re: RibbonTab in all Workspaces

08-20-2013 09:50 AM in reply to: R.Gerritsen4967

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!