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
Solved! Go to Solution.
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
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
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
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.
Here is pic attached
I wish the Part Prority/Custom priority as well as Highlight would show the curent state somehow
Orest
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.
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.
It's not really rocket science . Just changing the 'LargeIcon' and/or 'StandardIcon' property of the button definition. Apparently there is no problem doing this during runtime.
Daniël
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
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
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
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
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
Can't find what you're looking for? Ask the community or share your knowledge.