Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
Orest_iy
2272 Views, 16 Replies

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

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

16 REPLIES 16
Message 2 of 17
djreesing
in reply to: Orest_iy

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

Message 3 of 17
Orest_iy
in reply to: djreesing

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

Message 4 of 17
djreesing
in reply to: Orest_iy

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

Message 5 of 17
pball
in reply to: djreesing

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.

Message 6 of 17
Orest_iy
in reply to: pball

Here is pic attached

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

Orest

Message 7 of 17
djreesing
in reply to: pball

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.

 

 

 

 

Message 8 of 17
djreesing
in reply to: Orest_iy

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.

Message 9 of 17
pball
in reply to: djreesing

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.
Message 10 of 17
djreesing
in reply to: pball

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

Message 11 of 17
pball
in reply to: djreesing

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.
Message 12 of 17
djreesing
in reply to: pball

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

 

 

Message 13 of 17
djreesing
in reply to: pball

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

Message 14 of 17
Orest_iy
in reply to: djreesing

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

Message 15 of 17
Orest_iy
in reply to: djreesing

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

 

Message 16 of 17
djreesing
in reply to: Orest_iy

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
in reply to: djreesing

Thank you

Everything is working now

Best regards,

Orest

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report