addbuttondef always fails

addbuttondef always fails

Anonymous
Not applicable
715 Views
16 Replies
Message 1 of 17

addbuttondef always fails

Anonymous
Not applicable
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
0 Likes
716 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable
Oh yeah, one other thing. The docs leave a bit to be desired on this function. It impies that you must
include the CLSID in the call for VB apps (not so with vba). But how the heck do you do that???
If I cant get a CLSID for the app until I reg it, but by then its compiled so I cant go back and
put it in the code...what the heck??
Sorta like the old Chicken vs. egg argument. whats up with that??
0 Likes
Message 3 of 17

Anonymous
Not applicable
The call to AddButtonDefinition fails in the debug mode due to the icon
arguments. IPictureDisp objects cannot be marshalled across processes. So,
when debugging, you should not pass in those arguments.

Sanjay-

"perry" wrote in message
news:4922480@discussion.autodesk.com...
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
0 Likes
Message 4 of 17

Anonymous
Not applicable
Why is it that you can't modify the code once it is compiled and registered?
I would think this is a must for going back and fixing things in your
add-in.

Sanjay-


"perry" wrote in message
news:4922519@discussion.autodesk.com...
Oh yeah, one other thing. The docs leave a bit to be desired on this
function. It impies that you must
include the CLSID in the call for VB apps (not so with vba). But how the
heck do you do that???
If I cant get a CLSID for the app until I reg it, but by then its compiled
so I cant go back and
put it in the code...what the heck??
Sorta like the old Chicken vs. egg argument. whats up with that??
0 Likes
Message 5 of 17

Anonymous
Not applicable
Also, I forgot to mention that you don't really need to hardcode the CLSID
by looking it up. This string is provided by the API (by the
ApplicationAddIn.ClassIdString property). You can simply use this property
value as the input to various methods.

Sanjay-


"Sanjay Ramaswamy (Autodesk)" wrote in
message news:4922529@discussion.autodesk.com...
Why is it that you can't modify the code once it is compiled and registered?
I would think this is a must for going back and fixing things in your
add-in.

Sanjay-


"perry" wrote in message
news:4922519@discussion.autodesk.com...
Oh yeah, one other thing. The docs leave a bit to be desired on this
function. It impies that you must
include the CLSID in the call for VB apps (not so with vba). But how the
heck do you do that???
If I cant get a CLSID for the app until I reg it, but by then its compiled
so I cant go back and
put it in the code...what the heck??
Sorta like the old Chicken vs. egg argument. whats up with that??
0 Likes
Message 6 of 17

Anonymous
Not applicable
Sanjay Ramaswamy (Autodesk) wrote:
> Why is it that you can't modify the code once it is compiled and registered?
> I would think this is a must for going back and fixing things in your
> add-in.
>
> Sanjay-
What I meant by that is, to get the CLSID I have to reg the dll, but if I do that
and go back into the code to put in the newly generated CLSID, then I have to recompile and re-reg
and I will surely end up with a differenct CLSID being generated on the last compile
which will not match the CLSID I just put in the code. Clear as mud?
Perry
0 Likes
Message 7 of 17

Anonymous
Not applicable
Sanjay Ramaswamy (Autodesk) wrote:
> The call to AddButtonDefinition fails in the debug mode due to the icon
> arguments. IPictureDisp objects cannot be marshalled across processes. So,
> when debugging, you should not pass in those arguments.
>
> Sanjay-
So should I pass in NULL or leave them out altogether?
Thanks Sanjay
0 Likes
Message 8 of 17

Anonymous
Not applicable
Sanjay Ramaswamy (Autodesk) wrote:
> Also, I forgot to mention that you don't really need to hardcode the CLSID
> by looking it up. This string is provided by the API (by the
> ApplicationAddIn.ClassIdString property). You can simply use this property
> value as the input to various methods.
>
> Sanjay-
Ah, that is helpful, thanks Sanjay
0 Likes
Message 9 of 17

Anonymous
Not applicable
You should leave them out altogether.

Sanjay-

"perry" wrote in message
news:4922559@discussion.autodesk.com...
Sanjay Ramaswamy (Autodesk) wrote:
> The call to AddButtonDefinition fails in the debug mode due to the icon
> arguments. IPictureDisp objects cannot be marshalled across processes. So,
> when debugging, you should not pass in those arguments.
>
> Sanjay-
So should I pass in NULL or leave them out altogether?
Thanks Sanjay
0 Likes
Message 10 of 17

Anonymous
Not applicable
Perry,

Once you've created and registered the AddIn, the CLSID of the AddIn will
remain the same after recompiles unless you explicitly change the CLSID.

Sanjay-

"perry" wrote in message
news:4922558@discussion.autodesk.com...
Sanjay Ramaswamy (Autodesk) wrote:
> Why is it that you can't modify the code once it is compiled and
> registered?
> I would think this is a must for going back and fixing things in your
> add-in.
>
> Sanjay-
What I meant by that is, to get the CLSID I have to reg the dll, but if I do
that
and go back into the code to put in the newly generated CLSID, then I have
to recompile and re-reg
and I will surely end up with a differenct CLSID being generated on the last
compile
which will not match the CLSID I just put in the code. Clear as mud?
Perry
0 Likes
Message 11 of 17

Anonymous
Not applicable
To keep the CLSID from changing on each recompile, go to the properties for
your VB project. On the Component tab, under Version Compatibility, check
Project Compatibility or Binary Compatibility (Project Compatibility is
sufficient for most add-ins).

Neil

"Sanjay Ramaswamy (Autodesk)" wrote in
message news:4922570@discussion.autodesk.com...
Perry,

Once you've created and registered the AddIn, the CLSID of the AddIn will
remain the same after recompiles unless you explicitly change the CLSID.

Sanjay-

"perry" wrote in message
news:4922558@discussion.autodesk.com...
Sanjay Ramaswamy (Autodesk) wrote:
> Why is it that you can't modify the code once it is compiled and
> registered?
> I would think this is a must for going back and fixing things in your
> add-in.
>
> Sanjay-
What I meant by that is, to get the CLSID I have to reg the dll, but if I do
that
and go back into the code to put in the newly generated CLSID, then I have
to recompile and re-reg
and I will surely end up with a differenct CLSID being generated on the last
compile
which will not match the CLSID I just put in the code. Clear as mud?
Perry
0 Likes
Message 12 of 17

Anonymous
Not applicable
Sanjay Ramaswamy (Autodesk) wrote:
> You should leave them out altogether.
>
> Sanjay-
Yep, just found that out
thanks Sanjay
0 Likes
Message 13 of 17

Anonymous
Not applicable
Neil Munro wrote:
> To keep the CLSID from changing on each recompile, go to the properties for
> your VB project. On the Component tab, under Version Compatibility, check
> Project Compatibility or Binary Compatibility (Project Compatibility is
> sufficient for most add-ins).
>
> Neil
Thanks Neil, thats good to know
I guess that means I dont have to run the .reg file on every recompile, but
should run regsvr32?
0 Likes
Message 14 of 17

Anonymous
Not applicable
No, you still need to run the reg file after each compile (and after
starting the app in VB for debugging). You just don't need to change the
class ID each time in the reg file. If you enforce project or binary
compatibility the CLSID is retained. Drag a shortcut to the ref file onto
your desktop for quick access.

Neil

"perry" wrote in message
news:4922821@discussion.autodesk.com...
Neil Munro wrote:
> To keep the CLSID from changing on each recompile, go to the properties
> for
> your VB project. On the Component tab, under Version Compatibility, check
> Project Compatibility or Binary Compatibility (Project Compatibility is
> sufficient for most add-ins).
>
> Neil
Thanks Neil, thats good to know
I guess that means I dont have to run the .reg file on every recompile, but
should run regsvr32?
0 Likes
Message 15 of 17

Anonymous
Not applicable
Further, if you distribute the dll to other users (installation and
registration required), they can just copy the dll over top of the original
if you maintain project or binary compatibility.

Neil

"Neil Munro" wrote in message
news:4923213@discussion.autodesk.com...
No, you still need to run the reg file after each compile (and after
starting the app in VB for debugging). You just don't need to change the
class ID each time in the reg file. If you enforce project or binary
compatibility the CLSID is retained. Drag a shortcut to the ref file onto
your desktop for quick access.

Neil

"perry" wrote in message
news:4922821@discussion.autodesk.com...
Neil Munro wrote:
> To keep the CLSID from changing on each recompile, go to the properties
> for
> your VB project. On the Component tab, under Version Compatibility, check
> Project Compatibility or Binary Compatibility (Project Compatibility is
> sufficient for most add-ins).
>
> Neil
Thanks Neil, thats good to know
I guess that means I dont have to run the .reg file on every recompile, but
should run regsvr32?
0 Likes
Message 16 of 17

Anonymous
Not applicable
Check out this thread although I can't get it to work myself.

By the way, why is this icon problem during debugging not in the Inventor help section. I have been trying and searching forever until I came across these posts on this forum.
0 Likes
Message 17 of 17

Anonymous
Not applicable
Neil Munro wrote:
> Further, if you distribute the dll to other users (installation and
> registration required), they can just copy the dll over top of the original
> if you maintain project or binary compatibility.
>
> Neil
good stuff Neil, thanks
0 Likes