03-25-2022
09:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-25-2022
09:37 AM
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