.NET

Reply
Valued Contributor
deathman20
Posts: 55
Registered: ‎11-08-2010
Message 1 of 8 (1,482 Views)
Accepted Solution

Total n00b trying to use .net to create ribbon bar addins

1482 Views, 7 Replies
01-13-2011 09:52 AM

Ok im totally lost here with this.  Figured this after at least getting over the hurdle of trying to set up the project and all would be much easier to use and deploy (maybe even faster in AutoCAD) than what im trying to do right now using CUI files which can take 30-45 seconds to load each ribbon bar. 

 

Trying to create extra ribbon tabs and pannels each with multiple items in drop down windows and such.  Basically im trying to get rid of the tool pallet function and replace it with this item.  So far I've done this just using the CUI editor in autocad but its time consuming (not easy to switch between macro's) and takes long to load on the first launch of it.

 

I really don't know much about VB or .net or anything.  Though I have been learning more recently, with a little bit in excel trying to make customized documents for my department.  I have AutoCAD 2010, and have Visual Studio 2010 Professional.  Any help would be apperciated, expecially if there is some templates that I could load easily, currently not having any luck with the files from the website ObjectARX 2010 or a AutoCAD2010VBNetTemplateSetup.zip I got from another site.

Valued Contributor
deathman20
Posts: 55
Registered: ‎11-08-2010
Message 2 of 8 (1,469 Views)

Re: Total n00b trying to use .net to create ribbon bar addins

01-13-2011 02:09 PM in reply to: deathman20

Well at least I got a template up and runnig at least to debug mode now.

 

Another question I have is that is it possible to have a .dll (weather the one the main project one or a seperate file) load images into them?

 

Looking at loading some 2500 images maybe more.  Got about 500 to add right away and others to add over time.

 

greenshot_2011-01-13_16-07-19.jpg

 

Thats a small sample of what im doing.  Under each pull down there can be another 5-20 options.  Probably 10-12 tabs, each with 20 or so panels.  Any help pointing me into the right direction would be great!

 

All that was done in the autocad CUI, though its buggy and if it can be transfered between AutoCAD revs easier later on it would be great, and probably easier to edit for future updates.

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

Re: Total n00b trying to use .net to create ribbon bar addins

01-14-2011 06:00 AM in reply to: deathman20

Hi there please look at te following post:

 

http://forums.autodesk.com/t5/NET/Create-custom-ribbon-tab-and-buttons-for-Autocad-mechanical-2011/t...

 

I'll think it will help you getting started.

 

Kind regards,

 

Irvin

Valued Contributor
deathman20
Posts: 55
Registered: ‎11-08-2010
Message 4 of 8 (1,393 Views)

Re: Total n00b trying to use .net to create ribbon bar addins

01-19-2011 02:33 PM in reply to: Irvin

Alright im getting somewhere now.

 

Attached is my project file as is.  Finally was able to find a tutorial done from AU back in 2009

http://images.dcheetahimages.com/au.autodesk.com/ama/images/media/AU09_SpeakerHandout_CP208-2.pdf

 

So started going through it finally got a tab to be created, though now running in issues trying to get the panel to load with buttons.  I've copied it exactly though not sure what im doing wrong with this.

 

Below is the code so far (as can be seen also attached)

 

Though my one spot im having issues with is the AdskCommandHandler Class.  Specifically

 SendStringToExecute(_ 
ribBtn.CommandParameter, True, False, True)

 

 

Imports System
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.Windows

Public Class Testing
    Implements IExtensionApplication

    Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
        createRibbon()
    End Sub

    Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate

    End Sub
    Private Sub CreateRibbon()
        'declare a ribboncontrol object
        Dim ribCntrl As RibbonControl = ComponentManager.Ribbon
        'create a ribbontab
        Dim ribTab As New RibbonTab()
        'set a few properties
        ribTab.Title = "AU2009"
        ribTab.Id = "AU2009"
        'add the tab to the ribbon
        ribCntrl.Tabs.Add(ribTab)
        'set as active tab
        ribTab.IsActive = True

    End Sub

    Private Sub addContent(ByVal ribTab As RibbonTab)
        'create the panel source
        Dim ribSourcePanel As RibbonPanelSource = New RibbonPanelSource()
        ribSourcePanel.Title = "Dev Tools"
        'now the panel
        Dim ribPanel As New RibbonPanel()
        ribPanel.Source = ribSourcePanel
        ribTab.Panels.Add(ribPanel)
        'create a button
        Dim ribButton1 As RibbonButton = New RibbonButton()
        ribButton1.Text = "Net Load"
        ribButton1.CommandParameter = "NETLOAD "
        ribButton1.ShowText = True
        ribButton1.CommandHandler = New AdskCommandHandler()
        'add the button
        ribSourcePanel.Items.Add(ribButton1)
    End Sub


End Class

Public Class AdskCommandHandler

    Implements System.Windows.Input.ICommand

    Public Function CanExecute(ByVal parameter As Object) As Boolean _
        Implements System.Windows.Input.ICommand.CanExecute
        Return True
    End Function

    Public Event CanExecuteChanged As EventHandler Implements _
        System.Windows.Input.ICommand.CanExecuteChanged

    Public Sub Execute(ByVal parameter As Object) Implements _
        System.Windows.Input.ICommand.Execute
        Dim ribBtn As RibbonButton = TryCast(parameter, RibbonButton)
        If ribBtn IsNot Nothing Then
            Autodesk.AutoCAD.ApplicationServices.Application.
                DocumentManager.MdiActiveDocument.
                SendStringToExecute(_ 
                    ribBtn.CommandParameter, True, False, True)
        End If
    End Sub

End Class

 

 

Any help apperciated.

 

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

Re: Total n00b trying to use .net to create ribbon bar addins

01-20-2011 03:38 AM in reply to: deathman20

Hi Deathman,

 

I modifyed your code and in now displays a ribbon a tab buttons and fixed your command handler and add functions to remove the ribbon and use vb.net resourceimages. In the solution explorer click the project richt click propperties choose resources and then Add Resource.

 

Here's the code and revised project attached.

 

Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Windows.Media.Imaging

Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.Windows

Public Class Testing
    Implements IExtensionApplication

    Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
        createRibbon()
    End Sub

    Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate

    End Sub

    Public Sub createRibbon()
        Dim ribCntrl As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon
        If ComponentManager.Ribbon Is Nothing Then
            Return
        End If

        For i As Integer = 0 To ribCntrl.Tabs.Count - 1
            If ribCntrl.Tabs(i).Id.Equals("My_Rib_ID") Then
                Return
            End If
        Next

        'add the tab
        Dim ribTab As New RibbonTab()
        ribTab.Title = "ACME RIBBON"
        ribTab.Id = "My_Rib_ID"
        ribCntrl.Tabs.Add(ribTab)

        'create and add the panels
        addPanel1(ribTab)

        'set as active tab
        ribTab.IsActive = True
    End Sub

    Private Sub removeRibbon()
        Dim ribCntrl As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon
        'find the custom tab using the Id
        For i As Integer = 0 To ribCntrl.Tabs.Count - 1
            If ribCntrl.Tabs(i).Id.Equals("My_Rib_ID") Then
                ribCntrl.Tabs.Remove(ribCntrl.Tabs(i))
                Return
            End If
        Next
    End Sub


    Private Sub addPanel1(ByVal ribTab As RibbonTab)
        'create the panel source
        Dim ribSourcePanel As New RibbonPanelSource()
        ribSourcePanel.Title = "PanelName"
        'now the panel
        Dim ribPanel As New RibbonPanel()
        ribPanel.Source = ribSourcePanel
        ribTab.Panels.Add(ribPanel)

        Dim ribbonbutton1 As New RibbonButton()
        ribbonbutton1.Text = "Net Load"
        ribbonbutton1.CommandParameter = "NETLOAD "
        ribbonbutton1.ShowText = True
        ribbonbutton1.ShowImage = True
        ribbonbutton1.Image = getBitmap(My.Resources.Rib_16)
        ribbonbutton1.LargeImage = getBitmap(My.Resources.Rib_32)
        ribbonbutton1.Orientation = System.Windows.Controls.Orientation.Vertical
        ribbonbutton1.Size = RibbonItemSize.Large
        ribbonbutton1.CommandHandler = New AdskCommandHandler()

        Dim ribbonbutton2 As New RibbonButton()
        ribbonbutton2.Text = "LINE"
        ribbonbutton2.CommandParameter = "LINE "
        ribbonbutton2.ShowText = True
        ribbonbutton2.ShowImage = True
        ribbonbutton2.CommandHandler = New AdskCommandHandler()

        Dim ribbonbutton3 As New RibbonButton()
        ribbonbutton3.Text = "Polyline"
        ribbonbutton3.CommandParameter = "PLINE"
        ribbonbutton3.ShowText = True
        ribbonbutton3.ShowImage = True
        ribbonbutton3.CommandHandler = New AdskCommandHandler()

        Dim ribbonbutton4 As New RibbonButton()
        ribbonbutton4.Text = "Circle"
        ribbonbutton4.ShowText = False
        ribbonbutton4.CommandParameter = "CIRCLE "
        ribbonbutton4.ShowImage = True
        ribbonbutton4.CommandHandler = New AdskCommandHandler()

        Dim ribbonbutton5 As New RibbonButton()
        ribbonbutton5.Text = "DialogLauncher"
        ribbonbutton5.CommandParameter = "properties "
        ribbonbutton5.ShowText = True
        ribbonbutton5.ShowImage = True
        ribbonbutton5.CommandHandler = New AdskCommandHandler()


        Dim rowpanel As New RibbonRowPanel()
        rowpanel.Items.Add(ribbonbutton2)
        rowpanel.Items.Add(New RibbonRowBreak())
        rowpanel.Items.Add(ribbonbutton3)
        rowpanel.Items.Add(New RibbonRowBreak())
        rowpanel.Items.Add(ribbonbutton4)

        'and add it to source
        ribSourcePanel.DialogLauncher = ribbonbutton5
        ribSourcePanel.Items.Add(ribbonbutton1)
        ribSourcePanel.Items.Add(New RibbonSeparator())
        ribSourcePanel.Items.Add(rowpanel)
    End Sub

    Public Function getBitmap(ByVal image As Bitmap) As BitmapImage
        Dim stream As New MemoryStream()
        image.Save(stream, ImageFormat.Png)
        Dim bmp As New BitmapImage()
        bmp.BeginInit()
        bmp.StreamSource = stream
        bmp.EndInit()

        Return bmp
    End Function

End Class

Public Class AdskCommandHandler

    Implements System.Windows.Input.ICommand

    Public Function CanExecute(ByVal parameter As Object) As Boolean _
        Implements System.Windows.Input.ICommand.CanExecute
        Return True
    End Function

    Public Event CanExecuteChanged As EventHandler Implements _
        System.Windows.Input.ICommand.CanExecuteChanged

    Public Sub Execute(ByVal parameter As Object) Implements _
        System.Windows.Input.ICommand.Execute
        Dim ribBtn As RibbonButton = TryCast(parameter, RibbonButton)
        If ribBtn IsNot Nothing Then
            Autodesk.AutoCAD.ApplicationServices.Application.
                DocumentManager.MdiActiveDocument.
                SendStringToExecute(
                    ribBtn.CommandParameter, True, False, True)
        End If
    End Sub

End Class

 

Kind regards,

 

Irvin

 

 

Valued Contributor
deathman20
Posts: 55
Registered: ‎11-08-2010
Message 6 of 8 (1,353 Views)

Re: Total n00b trying to use .net to create ribbon bar addins

01-20-2011 11:18 AM in reply to: deathman20

Thanks Irvin.  Between yours and found the full file script from the AU2009 was able to get a start on it.

 

 

Valued Contributor
cnicholas
Posts: 55
Registered: ‎03-26-2007
Message 7 of 8 (1,163 Views)

Re: Total n00b trying to use .net to create ribbon bar addins

03-09-2011 06:48 AM in reply to: deathman20

Hi

Thanks to this thread I have got some code running in AutoCAD 2011.

 

Out of interest where is the RibbonButton.CommandParameter documentation?  It took me a while to realise I needed a sapce at the end of the command string.

 

Regards

 

 

Valued Contributor
deathman20
Posts: 55
Registered: ‎11-08-2010
Message 8 of 8 (934 Views)

Re: Total n00b trying to use .net to create ribbon bar addins

07-14-2011 08:11 AM in reply to: cnicholas

The RibbonButton.CommandParameter really doesn't have much documentation that I know of.  Really its a thirdparty command added in to Mock the command line.

 

As for the space, and the reason for it after the command, it acts like an enter key.  Just like if you type in "pl" and hit space or enter after it, it will start the polyline command in autocad.

 

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