Message 1 of 17
addbuttondef always fails

Not applicable
08-08-2005
09:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok, I been spending the last year trying to get up to speed with ARX so Im pretty rusty with VB (wasnt a
guru in the first place) so I hope this question isnt too lame. Here it is...
I have an addin that Im working on and I want to add some menu items, but when I try to use
a button def, it always fails, I dont get runtime errors when I actually run it in IV,
but I get run time errors in the debugger. Can someone tell me what I did wrong here?
Thanks
Perry
-------relevant code chunk ------------------------------------------------
Option Explicit
Implements ApplicationAddInServer
Private WithEvents oDocEvents As DocumentEvents
Private WithEvents oAppEvents As ApplicationEvents
Private oCmd1 As Command
Private oCmd2 As Command
Private WithEvents oPropertyMenu As ButtonDefinition
Private oIcon As IPictureDisp
Dim bEnabled As Boolean
Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean)
'MsgBox "Event handler installed for CustomProp"
' Save a reference to the Application object.
bEnabled = ("Yes" = GetSetting("CustomProperty", "Setting", "Enabled", "Yes"))
Set oInventorApp = AddInSiteObject.Application
Set oAppEvents = oInventorApp.ApplicationEvents
'Set oCmd1 = AddInSiteObject.CreateCommand("Enable", 1, True)
'Set oCmd2 = AddInSiteObject.CreateCommand("Disable", 1, False)
If Not bEnabled Then
Exit Sub
End If
Set oIcon = LoadResPicture(101, vbResIcon)
'The next line always fails with a runtime error----------------------------------------------------------
Set oPropertyMenu = oInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition _
("Settings", "prl_Propsettings", kQueryOnlyCmdType, "", _
"Settings for Custom Property", "Settings", oIcon, oIcon)
' Find the command bar of the "Tools" pop-up menu.
Dim oUIManager As UserInterfaceManager
Set oUIManager = oInventorApp.UserInterfaceManager
' Create a command bar of a pop-up type for a flyout.
Dim oFlyOutCmdBar As CommandBar
Set oFlyOutCmdBar = oUIManager.CommandBars.Add("Custom Property", "FlyoutCmdBar", kPopUpCommandBar, "")
' Add 1 button to the fly-out command bar.
Call oFlyOutCmdBar.Controls.AddButton(oPropertyMenu)
Dim oMenuPopupCmdBar As CommandBar
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AppToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AssemblyToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("DrawingMangerToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("NotebookToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartFeatureToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PresentationToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
End Sub
guru in the first place) so I hope this question isnt too lame. Here it is...
I have an addin that Im working on and I want to add some menu items, but when I try to use
a button def, it always fails, I dont get runtime errors when I actually run it in IV,
but I get run time errors in the debugger. Can someone tell me what I did wrong here?
Thanks
Perry
-------relevant code chunk ------------------------------------------------
Option Explicit
Implements ApplicationAddInServer
Private WithEvents oDocEvents As DocumentEvents
Private WithEvents oAppEvents As ApplicationEvents
Private oCmd1 As Command
Private oCmd2 As Command
Private WithEvents oPropertyMenu As ButtonDefinition
Private oIcon As IPictureDisp
Dim bEnabled As Boolean
Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean)
'MsgBox "Event handler installed for CustomProp"
' Save a reference to the Application object.
bEnabled = ("Yes" = GetSetting("CustomProperty", "Setting", "Enabled", "Yes"))
Set oInventorApp = AddInSiteObject.Application
Set oAppEvents = oInventorApp.ApplicationEvents
'Set oCmd1 = AddInSiteObject.CreateCommand("Enable", 1, True)
'Set oCmd2 = AddInSiteObject.CreateCommand("Disable", 1, False)
If Not bEnabled Then
Exit Sub
End If
Set oIcon = LoadResPicture(101, vbResIcon)
'The next line always fails with a runtime error----------------------------------------------------------
Set oPropertyMenu = oInventorApp.CommandManager.ControlDefinitions.AddButtonDefinition _
("Settings", "prl_Propsettings", kQueryOnlyCmdType, "", _
"Settings for Custom Property", "Settings", oIcon, oIcon)
' Find the command bar of the "Tools" pop-up menu.
Dim oUIManager As UserInterfaceManager
Set oUIManager = oInventorApp.UserInterfaceManager
' Create a command bar of a pop-up type for a flyout.
Dim oFlyOutCmdBar As CommandBar
Set oFlyOutCmdBar = oUIManager.CommandBars.Add("Custom Property", "FlyoutCmdBar", kPopUpCommandBar, "")
' Add 1 button to the fly-out command bar.
Call oFlyOutCmdBar.Controls.AddButton(oPropertyMenu)
Dim oMenuPopupCmdBar As CommandBar
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AppToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("AssemblyToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("DrawingMangerToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("NotebookToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartFeatureToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PartToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
Set oMenuPopupCmdBar = oUIManager.CommandBars.Item("PresentationToolsMenu")
' Add the fly-out to the menu pop-up.
Call oMenuPopupCmdBar.Controls.AddPopup(oFlyOutCmdBar)
End Sub