Need a VB.net example to toggle the custom button image

Need a VB.net example to toggle the custom button image

Orest_iy
Collaborator Collaborator
3,085 Views
16 Replies
Message 1 of 17

Need a VB.net example to toggle the custom button image

Orest_iy
Collaborator
Collaborator

Hello

I have created some custom button in VB.net.I wish I can make those buttons toggling their image. For example my custom button toggles Part/Component priority or Highligt on/off and I would like the button image will change showing the current state. The background image color change will help too, or the some extra tiny mark on working sceen would help if it quite complicated to deal with ribbons. Generally I need to see the current state at glance. Please help Best regards, Orest Yavtushenko

0 Likes
Accepted solutions (1)
3,086 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable

Hi,

 

I guess in the button_onexecute event you can change the icon by setting the buttondefinition.LargeIcon (or StandardIcon) property to a different image.

I haven't tested this, so I'm not sure if it will work.

 

Best regards, Daniël

0 Likes
Message 3 of 17

Orest_iy
Collaborator
Collaborator

Hi

 

Once Inventor started it does not let to change a button picture. It executes the macro and required command is executed but did not change the image in the ribbon.

Regards,

Orest

0 Likes
Message 4 of 17

Anonymous
Not applicable

I've tried it and for me it seems to work as expected. Could you maybe post your code here so I can try to figure out the problem.

 

Daniël

0 Likes
Message 5 of 17

pball
Mentor
Mentor

djreesing I believe Orest_iy is talking about a button in the User Commands section of the ribbon bar and not a dialog which I guess you are talking about. Orest_iy if you could post a screen shot of the button you are refering to that would clear up any confusion there is.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 6 of 17

Orest_iy
Collaborator
Collaborator

Here is pic attached

I wish the Part Prority/Custom priority as well as Highlight would show the curent state somehow

Orest

0 Likes
Message 7 of 17

Anonymous
Not applicable

pball, I'm also talking about the ribbon toolbar. See attached images before and after clicking the button. I've used an icon of a cd-rom and dvd for this example.

 

Orest_iy, please post your code here so we can figure out whats wrong.

 

 

 

 

0 Likes
Message 8 of 17

Anonymous
Not applicable

By the way, I see you are using Inventor 2012. I've tested this with Inventor 2013, but I doubt that this functionality was added in the 2013 API.

0 Likes
Message 9 of 17

pball
Mentor
Mentor
Wow I've never run across this functionality before. I've only found a few articles on using icons period. It's nice to be wrong some times.
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 10 of 17

Anonymous
Not applicable

It's not really rocket science Smiley Wink. Just changing the 'LargeIcon' and/or 'StandardIcon' property of the button definition. Apparently there is no problem doing this during runtime.

 

Daniël

0 Likes
Message 11 of 17

pball
Mentor
Mentor
Could you share some code please. I don't have a use for this currently but it's piqued my interest and I don't have a clue where/how you are doing this.
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 12 of 17

Anonymous
Not applicable

First of all this is done in a VB.NET add-in (Visual Basic 2010 Express).

 

This is the code in the activate section of the add-in (where the button is declared and put in a ribbon).

 

            Dim oControlDefinitions As ControlDefinitions
            Dim oUIManager As UserInterfaceManager

            oControlDefinitions = m_inventorApplication.CommandManager.ControlDefinitions
            oUIManager = m_inventorApplication.UserInterfaceManager

            oTestButton = oControlDefinitions.AddButtonDefinition("Test Button", "oTestButton", CommandTypesEnum.kQueryOnlyCmdType, sClientID)

            oTestButton.LargeIcon = clsPictureDispConverter.ToIPictureDisp(New System.Drawing.Icon(My.Resources.Compact_Disk, 32, 32))

            If firstTime = True Then

                '===Ribbon section===
                Dim oRibbon As Ribbon
                Dim oTestRibbon As RibbonTab
                Dim oTestPanel As RibbonPanel

                For Each oRibbon In oUIManager.Ribbons

                    ' Create a new tab
                    oTestRibbon = oRibbon.RibbonTabs.Add("Test Ribbon", "oTestRibbon", sClientID)

                    ' Create a new panel within the tab
                    oTestPanel = oTestRibbon.RibbonPanels.Add("Test Panel", "oTestPanel", sClientID)

                    ' Create a control within the panel
                    Call oTestPanel.CommandControls.AddButton(oTestButton, True)

                Next oRibbon

            End If

 

This is the code in the oTestButton_OnExecute event.

 

oTestButton.LargeIcon = clsPictureDispConverter.ToIPictureDisp(New System.Drawing.Icon(My.Resources.DVD_Disk, 32, 32))

 

The clsPictureDispConverter is a custom class that contains a function for converting the icon to an IPictureDisp. See http://modthemachine.typepad.com/my_weblog/2012/02/bitmaps-without-vb6-icontoipicture.html for more information.

 

I hope you can understand how this works now.

 

Best regards,

Daniël

 

 

0 Likes
Message 13 of 17

Anonymous
Not applicable

In case you're not familiar with Add-ins, please read this: http://modthemachine.typepad.com/my_weblog/2010/01/how-to-write-an-inventor-add-in.html

0 Likes
Message 14 of 17

Orest_iy
Collaborator
Collaborator

Inventor 2013 gave me so much troubles with those appereances and crashes in attempt to change or create something custom so I stay the second year on 2012.

The idea of switching Large and Small icons probably could be the sollution.Did not tried it yet.

Thank you for advice.

I can test it on Monday, everything is on working machine.

Orest

0 Likes
Message 15 of 17

Orest_iy
Collaborator
Collaborator

Hello again,

Here is my code attached.

The whole project is zipped.

I wish my custom button would change the Large image to Standard image in the executable event.

Regards,

Orest

 

0 Likes
Message 16 of 17

Anonymous
Not applicable
Accepted solution

Hi,

 

In your case you should use the following command to set an icon or the buttondefinition.

 

mAsmButtonDef.LargeIcon = mIPictureDisp1

 

In your mAsmButtonDef_OnExecute event you don't need to set the buttondefintion again. You can simple change the icon by the above command.

 

Look to one of my last posts where I posted my my code. That should explain it.

 

Daniël

 

 

Message 17 of 17

Orest_iy
Collaborator
Collaborator

Thank you

Everything is working now

Best regards,

Orest

0 Likes