iLogicMini Toolbar Combo Box List Item Icon from Browser Node

iLogicMini Toolbar Combo Box List Item Icon from Browser Node

pmartick
Advocate Advocate
1,011 Views
7 Replies
Message 1 of 8

iLogicMini Toolbar Combo Box List Item Icon from Browser Node

pmartick
Advocate
Advocate

Inventor 2021, latest version:

 

I have a sample of a rule I'm making that uses a Mini Toolbar to allow the user to select component occurrences in an assembly and see them in a combo box.  I see in the API Guide that there's an option to have an icon next to each combo box item.  I'm trying to find the way to grab the icon from the browser node of the selected occurrence (icons for Part, Assembly, Weldment, Sheet Metal, etc.) and use that as the icon in the combo box.

 

When adding the combo box item, it accepts IPictureDisp as an icon input.  I think I found the API to grab the icon from the selected occurrence which results as an IPictureDisp:

ThisDoc.Document.BrowserPanes.GetNativeBrowserNodeDefinition(oEntity).Icon

 

However, when I try to use this to contain the icon in an object I get an error:

Error : Reference required to assembly 'stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the type 'stdole.IPictureDisp'. Add one to your project.

 

I'm not sure how to properly set up "stdole.IPictureDisp" as a reference in iLogic or if it's even possible.

 

Here's my rule sample, the area where the icon needs to be grabbed and used is in subroutine evSelectEvents_OnSelect:

 

Class ThisRule
	Dim bStop As Boolean = False
	Dim cOccs As Inventor.ComponentOccurrences
	Private WithEvents evMiniToolbar As Inventor.MiniToolbar
	Private WithEvents evInteractionEvents As Inventor.InteractionEvents
	Private WithEvents evSelectEvents As Inventor.SelectEvents
	Private WithEvents evKeyboardEvents As Inventor.KeyboardEvents
	Private WithEvents evComboBox As Inventor.MiniToolbarComboBox
	Sub Main
		oApp = ThisApplication
		oDoc = ThisDoc.Document
		If TypeOf oDoc Is AssemblyDocument And Right(oApp.UserInterfaceManager.ActiveEnvironment.DisplayName, 8) = "Assembly" Then
			cOccs = oDoc.ComponentDefinition.Occurrences
			oCommandManager = oApp.CommandManager
			evMiniToolbar = oCommandManager.CreateMiniToolbar
			evInteractionEvents = oCommandManager.CreateInteractionEvents
			evSelectEvents = evInteractionEvents.SelectEvents
			evSelectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter)
			evSelectEvents.WindowSelectEnabled = False
			evSelectEvents.Enabled = True
			evMiniToolbarControls = evMiniToolbar.Controls
			oView = oApp.ActiveView
			evMiniToolbar.Position = oApp.TransientGeometry.CreatePoint2d(oView.Left, oView.Top)
			evMiniToolbar.ShowOK = True
			evMiniToolbar.ShowOptionBox = False
			evMiniToolbarControls.AddLabel("MainLabel", "Select occurrences.", "Occurrences")
			evMiniToolbarControls.AddNewLine
			evMiniToolbarControls.AddLabel("Selection:", "Selection", "Select Occurrences.")
			evComboBox = evMiniToolbarControls.AddComboBox("Selection")
			evComboBox.AutoHide = False
			evMiniToolbar.Visible = True
			evInteractionEvents.Start
			Do
				oApp.UserInterfaceManager.DoEvents
			Loop Until bStop = True
			evInteractionEvents.Stop
			evMiniToolbar.Delete
		Else
			MessageBox.Show("This rule must be run in an Assembly Environment.")
		End If
	End Sub
	Sub evMiniToolbar_OnApply() Handles evMiniToolbar.OnApply
		evSelectEvents.ResetSelections
	End Sub
	Sub evMiniToolbar_OnOK() Handles evMiniToolbar.OnOK
		bStop = True
	End Sub
	Sub evMiniToolbar_OnCancel() Handles evMiniToolbar.OnCancel
		bStop = True
	End Sub
	Sub evKeyboardEvents_OnKeyPress(lKey As Long) Handles evKeyboardEvents.OnKeyPress
		If lKey = 27 Then evMiniToolbar_OnCancel
		If lKey = 10 Then evMiniToolbar_OnApply
	End Sub
	Sub evSelectEvents_OnPreSelect(ByRef PreSelectEntity As Object, ByRef DoHighlight As Boolean, ByRef MorePreSelectEntities As Inventor.ObjectCollection, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnPreSelect
		PreSelectEntity = PreSelectEntity.OccurrencePath.Item(1)
	End Sub
	Sub evSelectEvents_OnSelect(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnSelect
		oEntity = JustSelectedEntities.Item(1)
		sEntity = oEntity.Name
		evSelectEvents.AddToSelectedEntities(oEntity)
		oIcon = ThisDoc.Document.BrowserPanes.GetNativeBrowserNodeDefinition(oEntity).Icon
		evComboBox.AddItem(sEntity, "Occurrence", sEntity, True, oIcon)
	End Sub
	Sub evSelectEvents_OnUnSelect(ByVal UnSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnUnSelect
		evComboBox.RemoveItem(UnSelectedEntities.Item(1).Name)
	End Sub
	Sub evComboBox_OnItemRemove(ByVal oItem As Inventor.MiniToolbarListItem) Handles evComboBox.OnItemRemove
		evSelectEvents.RemoveFromSelectedEntities(cOccs.ItemByName(oItem.InternalName))
	End Sub
End Class

 

If this is something that's not possible in iLogic by either adding something in the Class or opening the Header and adding Imports or something else along those lines, then let me know and I'll add this to the Ideas forum.

 

Thank you for your help.

0 Likes
Accepted solutions (3)
1,012 Views
7 Replies
Replies (7)
Message 2 of 8

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Add in the header section of your rule just

 

AddReference "stdole"

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 8

WCrihfield
Mentor
Mentor
Accepted solution

Just put this into the 'Header' of the rule:

AddReference "stdole.dll"
Imports stdole

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 8

pmartick
Advocate
Advocate

Hopefully another easily answered question that's related.  How do I use other icons either found in Inventor or saved externally in the proper image format?

0 Likes
Message 5 of 8

WCrihfield
Mentor
Mentor

Hi @pmartick.  I believe that most (if not all) of the internal images within Inventor that we have access to from the Inventor API are in that same IPictureDisp format.  The document thumbnail is that format, and the ribbon tool buttons also use that same format for their large and small icons.  I used to use a VBA macro to extract the button icons from existing Inventor tool buttons, so that I could slightly alter them then reuse them as button icons for my own custom buttons, which ran some of my VBA macros.  I just used to save them out as .bmp files though.  It was much easier to do from VBA at the time than it was from iLogic.  However, I'm steering away from VBA as much as possible now though, due to the related security issues, which is why Inventor no longer installs the VBA Editor with Inventor.  You can also just create your own icon images from scratch though, if you are aware of the size restrictions, naming conventions, and file location requirements.  There are several other articles here in the forums, in users blogs, and else where about folks using various other software to generate tool button icon graphics. (Link1, Link2)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 8

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

The MiniToolbarComboBox.AddItem method needs an IPictureDisp for small (16x16px) and large (32x32px) Icon. If you display only small icons and the user had no possibility to switch to large icons, you do not need to add them.

Most parts of the conversion is "stolen" from the Autodesk Inventor Addin template for Visual Studio. There is for sure a cleaner, better and right way to do this, but I'm not experienced enough for it.

I have hard coded the path to the icon files. You'll need to change the path and add some checks if path exist, if there is an icon file and so on.

 

AddReference "System.Drawing"
AddReference "stdole"
AddReference "System.Windows.Forms"

Class ThisRule
	Dim bStop As Boolean = False
	Dim cOccs As Inventor.ComponentOccurrences
	Dim oImageLarge As System.Drawing.Image
	Dim oImageSmall As System.Drawing.Image
	Dim oIconLarge As System.Drawing.Icon
	Dim oIconSmall As System.Drawing.Icon
	Dim oIPicDispLarge As stdole.IPictureDisp
	Dim oIPicDispSmall As stdole.IPictureDisp
	Private WithEvents evMiniToolbar As Inventor.MiniToolbar
	Private WithEvents evInteractionEvents As Inventor.InteractionEvents
	Private WithEvents evSelectEvents As Inventor.SelectEvents
	Private WithEvents evKeyboardEvents As Inventor.KeyboardEvents
	Private WithEvents evComboBox As Inventor.MiniToolbarComboBox
	Sub Main
		oApp = ThisApplication
		oDoc = ThisDoc.Document
		
		oIconLarge = New System.Drawing.Icon("C:\Temp\ico_Large_32x32.ico")
		oIconSmall = New System.Drawing.Icon("C:\Temp\ico_Small_16x16.ico")
		
		oImageLarge = oIconLarge.ToBitmap
		oImageSmall = oIconSmall.ToBitmap

		Dim myPict As New AxHostConverter
		oIPicDispLarge = myPict.GetIPictureDispFromImage(oImageLarge)
		oIPicDispSmall = myPict.GetIPictureDispFromImage(oImageSmall)


		'this call must be created, but is never used
		Dim myCallback As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)

		If TypeOf oDoc Is AssemblyDocument And Right(oApp.UserInterfaceManager.ActiveEnvironment.DisplayName,  = "Assembly" Then
			cOccs = oDoc.ComponentDefinition.Occurrences
			oCommandManager = oApp.CommandManager
			evMiniToolbar = oCommandManager.CreateMiniToolbar
			evInteractionEvents = oCommandManager.CreateInteractionEvents
			evSelectEvents = evInteractionEvents.SelectEvents
			evSelectEvents.AddSelectionFilter(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter)
			evSelectEvents.WindowSelectEnabled = False
			evSelectEvents.Enabled = True
			evMiniToolbarControls = evMiniToolbar.Controls
			oView = oApp.ActiveView
			evMiniToolbar.Position = oApp.TransientGeometry.CreatePoint2d(oView.Left, oView.Top)
			evMiniToolbar.ShowOK = True
			evMiniToolbar.ShowOptionBox = False
			evMiniToolbarControls.AddLabel("MainLabel", "Select occurrences.", "Occurrences")
			evMiniToolbarControls.AddNewLine
			evMiniToolbarControls.AddLabel("Selection:", "Selection", "Select Occurrences.")
			evComboBox = evMiniToolbarControls.AddComboBox("Selection")
			evComboBox.AutoHide = False
			evMiniToolbar.Visible = True
			evInteractionEvents.Start
			Do
				oApp.UserInterfaceManager.DoEvents
			Loop Until bStop = True
			evInteractionEvents.Stop
			evMiniToolbar.Delete
		Else
			MessageBox.Show("This rule must be run in an Assembly Environment.")
		End If
	End Sub
	Sub evMiniToolbar_OnApply() Handles evMiniToolbar.OnApply
		evSelectEvents.ResetSelections
	End Sub
	Sub evMiniToolbar_OnOK() Handles evMiniToolbar.OnOK
		bStop = True
	End Sub
	Sub evMiniToolbar_OnCancel() Handles evMiniToolbar.OnCancel
		bStop = True
	End Sub
	Sub evKeyboardEvents_OnKeyPress(lKey As Long) Handles evKeyboardEvents.OnKeyPress
		If lKey = 27 Then evMiniToolbar_OnCancel
		If lKey = 10 Then evMiniToolbar_OnApply
	End Sub
	Sub evSelectEvents_OnPreSelect(ByRef PreSelectEntity As Object, ByRef DoHighlight As Boolean, ByRef MorePreSelectEntities As Inventor.ObjectCollection, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnPreSelect
		PreSelectEntity = PreSelectEntity.OccurrencePath.Item(1)
	End Sub
	Sub evSelectEvents_OnSelect(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnSelect
		oEntity = JustSelectedEntities.Item(1)
		sEntity = oEntity.Name
		evSelectEvents.AddToSelectedEntities(oEntity)
		'oIcon = ThisDoc.Document.BrowserPanes.GetNativeBrowserNodeDefinition(oEntity).Icon
		evComboBox.AddItem(sEntity, "Occurrence", sEntity, True, oIPicDispSmall,oIPicDispLarge)
	End Sub
	Sub evSelectEvents_OnUnSelect(ByVal UnSelectedEntities As Inventor.ObjectsEnumerator, ByVal SelectionDevice As Inventor.SelectionDeviceEnum, ByVal ModelPosition As Inventor.Point, ByVal ViewPosition As Inventor.Point2d, ByVal View As Inventor.View) Handles evSelectEvents.OnUnSelect
		evComboBox.RemoveItem(UnSelectedEntities.Item(1).Name)
	End Sub
	Sub evComboBox_OnItemRemove(ByVal oItem As Inventor.MiniToolbarListItem) Handles evComboBox.OnItemRemove
		evSelectEvents.RemoveFromSelectedEntities(cOccs.ItemByName(oItem.InternalName))
	End Sub


	Public Function ThumbnailCallback() As Boolean
		Return False
	End Function

End Class

Class AxHostConverter
Inherits System.Windows.Forms.AxHost

Public Sub New()
	MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
End Sub

Public Function GetImageFromIPictureDisp(ByVal pictureDisp As stdole.IPictureDisp) As System.Drawing.Image
	Return MyBase.GetPictureFromIPicture(pictureDisp)
End Function

Public Function GetIPictureDispFromImage(ByVal image As System.Drawing.Image) As stdole.IPictureDisp
	Return MyBase.GetIPictureDispFromPicture(image)
End Function
End Class

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 7 of 8

pmartick
Advocate
Advocate
That's exactly what I needed. Although it's hard to believe it needs that much stuff to just get an icon.
However, for this line:

'this call must be created, but is never used
Dim myCallback As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)

I don't get any errors when I comment out that line, is it just a sort of fault correction in case the .ico files can't be accessed?
0 Likes
Message 8 of 8

pmartick
Advocate
Advocate
I tried looking into code to automatically extract the built-in icons, but I figure it's much easier to just use BeCyIconGrabber and just save them as .ico files somewhere safely.
0 Likes