.NET

Reply
Valued Contributor
mnav
Posts: 57
Registered: ‎12-15-2009
Message 1 of 8 (1,112 Views)
Accepted Solution

RibbonTab in all Workspaces

1112 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

Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 2 of 8 (1,102 Views)

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
mnav
Posts: 57
Registered: ‎12-15-2009
Message 3 of 8 (1,097 Views)

Re: RibbonTab in all Workspaces

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

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

Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 4 of 8 (1,080 Views)

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
mamj
Posts: 36
Registered: ‎05-31-2007
Message 5 of 8 (706 Views)

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
chase.hochstrasser
Posts: 42
Registered: ‎07-17-2013
Message 6 of 8 (237 Views)

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
R.Gerritsen4967
Posts: 46
Registered: ‎07-31-2009
Message 7 of 8 (218 Views)

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
chase.hochstrasser
Posts: 42
Registered: ‎07-17-2013
Message 8 of 8 (198 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community