Inventor Toolbar Add-in?

Inventor Toolbar Add-in?

Anonymous
Not applicable
875 Views
12 Replies
Message 1 of 13

Inventor Toolbar Add-in?

Anonymous
Not applicable
I created a toolbar with a few custom macros in VBA. The macros work fine on my computer. I then learned that to get the macros to load on other computers, I needed to create an add-in. I got a seat in VB, created the add-in, loaded the add-in, and it loaded! There it is! However, the buttons don't work anymore. They're there on the screen, but when they are clicked, nothing happens. I looked into the help files, and read this:

"Autodesk Inventor API Limitation: The ButtonDefinition object is currently not available publicly through the API. Currently, it can only be obtained from its associated ButtonDefinitionHandler, which is only available to the Add-In that created it. As a result, you cannot place Inventor or other Add-In commands on toolbars using the API."

Wh-wh-what?!!!
Does this mean that I cannot create custom commands in a toolbar with add-ins? What's up? Please help me!
0 Likes
876 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
Look in your Inventor install folder/SDK/Samples/VB/SimpleAddIn and open the addinsample project. It outlines how to add a button. I believe it uses external icons, but most people put the icons in a resource file. -- Kent Keller Autodesk Discussion Forum Facilitator "mattis" wrote in message > > Wh-wh-what?!!! > Does this mean that I cannot create custom commands in a toolbar with add-ins? What's up? Please help me!
0 Likes
Message 3 of 13

Anonymous
Not applicable
I did that. I used that code as a base for my code. The icons show up just fine. It's just that when I click on them, nothing happens. When I read that message in the help file, I thought that my button battle was futile. Are there any other examples of custom toolbars that are added via an add-in?

I want a custom toolbar that is always there. The sample add-in puts the buttons in the sketch environment only. I want this to be a global toolbar for all environments. On second thought, maybe I should make it environment specific. Naaahh!

The real reason that I want it global is bacause my guys are coming from MDT. They are used to seeing the same ol buttons in certain areas of their screens.
0 Likes
Message 4 of 13

Anonymous
Not applicable
This is the class module of one of my addins. It make a toolbar called KWiKTools and adds the button handler to it. I don't remember ... it probably doesn't start out visible, and you have to go into customization and use the "Show" button on it. There is probably a way to make it show from the API, but this is the only toolbutton currently that I don't add to one of the existing ones so I haven't really looked into it. Option Explicit Implements ApplicationAddInServer Private oCmd As Command Private oCmd1 As Command Private WithEvents oButtonHandler1 As ButtonDefinitionHandler 'Set next line true to be in Debug mode. Private Const InDebug As Boolean = False Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean) ' Save a reference to the Application object. Set oApp = AddInSiteObject.Application ' Create the two button handlers. Dim oIcon1 As IPictureDisp Set oIcon1 = LoadResPicture(101, vbResBitmap) '****** Switch out the next calls / use first for debug and second for release If InDebug Then Set oButtonHandler1 = AddInSiteObject.CreateButtonDefinitionHandler("KWiKKillAddin", _ kFileOperationsCmdType, "KWiKKillAddin", "Stop Addin in Debug", "KWiKKillAddin") Else On Error Resume Next Set oButtonHandler1 = AddInSiteObject.CreateButtonDefinitionHandler("KWiKKillAddin", _ kFileOperationsCmdType, "KWiKKillAddin", "Stop Addin in Debug", "KWiKKillAddin", oIcon1) If Err.Number = -2147418113 Then Set oButtonHandler1 = Nothing Set oButtonHandler1 = AddInSiteObject.CreateButtonDefinitionHandler("KWiKKillAddin", _ kFileOperationsCmdType, "KWiKKillAddin", "Stop Addin in Debug", "KWiKKillAddin") Err.Clear On Error GoTo 0 End If End If ' Set a reference to the environment base collection. Dim oEnvBaseColl As EnvironmentBaseCollection Set oEnvBaseColl = oApp.EnvironmentBaseCollection ' Create a new command bar Dim oCommandBar As CommandBarBase Set oCommandBar = oEnvBaseColl.CommandBarBaseCollection.Add("KWiKTools") ' Add a control to the command bar Call oCommandBar.Controls.Add(kBarControlButton, _ oButtonHandler1.ControlDefinition) Set oCmd1 = AddInSiteObject.CreateCommand("Select Addin", 1, True) End Sub Private Property Get ApplicationAddInServer_Automation() As Object Set ApplicationAddInServer_Automation = Nothing End Property Private Sub ApplicationAddInServer_Deactivate() Set oButtonHandler1 = Nothing 'Set oCmd = Nothing Set oApp = Nothing End Sub Private Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long) ' no longer used frmKWiKKillAddin.Show End Sub Private Sub oButtonHandler1_OnClick() modKWiKKillAddin.ToggleAddin End Sub -- Kent Keller Autodesk Discussion Forum Facilitator "mattis" wrote in message news:11917330.1087934082807.JavaMail.jive@jiveforum2.autodesk.com... > I did that. I used that code as a base for my code. The icons show up just fine. It's just that when I click on them, nothing happens. When I read that message in the help file, I thought that my button battle was futile. Are there any other examples of custom toolbars that are added via an add-in?
0 Likes
Message 5 of 13

Anonymous
Not applicable
Kent,
I used your code, and still, nothing. The bar appears, the buttons with icons are there, but when I click on the buttons, nothing happens. Maybe its a problem with my subs. They worked fine in VBA.

I am using VB5 to create my dll. Do you think that is the problem?
0 Likes
Message 6 of 13

Anonymous
Not applicable
If you want, email me your whole project, and I will see if I can find anything. Since you are coming from VBA did you make sure you aren't still calling "thisapplication"? -- Kent Keller Autodesk Discussion Forum Facilitator "mattis" wrote in message news:28649179.1088099113335.JavaMail.jive@jiveforum2.autodesk.com... > Kent, > I used your code, and still, nothing. The bar appears, the buttons with icons are there, but when I click on the buttons, nothing happens. Maybe its a problem with my subs. They worked fine in VBA. > > I am using VB5 to create my dll. Do you think that is the problem?
0 Likes
Message 7 of 13

Anonymous
Not applicable
I replaced ThisApplication with oApp. Still nothing. Let me get the code back to where it isn't all screwed up (like now). I've been doing some serious experimentation to it all day. And, like a bad programmer, I haven't been backing it up. I'll send it sometime tomorrow.
0 Likes
Message 8 of 13

Anonymous
Not applicable
I got one of my add-in macros to work! It exports a sheetmetal part to AutoCAD R12 DXF. I made it part of the standard sheetmetal features panel bar. It opens it up in AutoCAD, turns off some layers and notifies the user that the file is ready to be sent to the vendor. Very cool! Heck, I'm kinda proud of myself!

Now, I want one of my other macros to automatically trigger upon saving a drawing (IDW) document. I've been round and round on this for days! I have attached my code so far. All I want it to do for now is flash up a message box saying something like, "It worked!". I'll take the rest from there.

Help me Obiwan Kentobi Keller, you're my only hope!
0 Likes
Message 9 of 13

Anonymous
Not applicable
Your last sub to handle the event should have this bit of code after it:

Handles oAppEvents.OnSaveDocument

Such as:

Private Sub oAppEvents_OnSaveDocument(ByVal DocumentObject As Inventor.document, _
ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, _
HandlingCode As Inventor.HandlingCodeEnum) Handles oAppEvent.OnSaveDocument

MsgBox "It worked!"

End Sub


I don't know if that is the only problem right now but hope it's that simple.
0 Likes
Message 10 of 13

Anonymous
Not applicable
I put that in, and my VB (VB5) doesn't recognize it. It says expected end of statement. Is there a different way to do it?
0 Likes
Message 11 of 13

Anonymous
Not applicable
I'm not a Jedi but this is from my post dated April 30, 2004 "Capture save event from an Add-In" This is how I usually do it. There are multiple approaches. First, create a new class module. In this example, I named it IVDocEventZ (IVDocEventZ.cls). Add this code to it...... ----IVDocEventZ.cls Option Explicit Private WithEvents MyAppEv As ApplicationEvents Private Sub Class_Terminate() Set MyAppEv = Nothing End Sub 'a method to initialize or turn-on the events in this class.... Public Sub EventClassInitialize(ByRef MyInvApp As Inventor.Application) Set MyAppEv = MyInvApp.ApplicationEvents End Sub 'a method to terminate or turn-off the events in this class.... Public Sub EventClassTerminate() Set MyAppEv = Nothing End Sub 'the ondocumentsave event... Private Sub MyAppEv_OnSaveDocument(ByVal DocumentObject As Document, _ ByVal BeforeOrAfter As EventTimingEnum, _ ByVal Context As NameValueMap, _ HandlingCode As HandlingCodeEnum) 'put your event code here.... End Sub ----end of IVDocEventZ.cls I usually create a Module that contains my global definitions. This is where I declare my global Inventor Application object along with other things. In this example I call it GlobalDeclares (GlobalDeclares.bas). Put these declarations in there... ---- GlobalDeclares.bas Option Explicit Public ivApp As Inventor.Application Public evAddInDocEvents As New IVDocEventZ ---- end of GlobalDeclares.bas Now, in your main class module, if you want the events to fire after the add-in is loaded you need to add the following call in the ApplicationAddInServer_Activate sub. I usually put it right after I get the application object... ---- 'get the inventor application object... Set ivApp = AddInSiteObject.Application 'initialize the event handler... evAddInDocEvents.EventClassInitialize ivApp ---- If you want the scope of the events to be limited or if you want to turn them "off", you can locate the call to EventClassInitialize somewhere else. To turn off the events... evAddInDocEvents.EventClassTerminate One warning about the save event. It can fire alot, especially in the assembly environment when multiple parts are saved. The event will fire twice for each document. Once before and once after. Check the value of "BeforeOrAfter" to determine which. -- Robert A. Williams http://www.leacar.com > > Now, I want one of my other macros to automatically trigger upon saving a drawing (IDW) document. I've been round and round on this for days! I have attached my code so far. All I want it to do for now is flash up a message box saying something like, "It worked!". I'll take the rest from there. > > Help me Obiwan Kentobi Keller, you're my only hope!
0 Likes
Message 12 of 13

Anonymous
Not applicable
I started to plug away at this, and got a little lost because I am a beginner at all this VB stuff. I did, however, get my code to work! I was missing this:
Set oAppEvents = oApp.ApplicationEvents

My code looks like this now:

Option Explicit
Implements ApplicationAddInServer
Private oApp As Inventor.Application
Private WithEvents oAppEvents As ApplicationEvents

Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean)
' Save a reference to the Application object.
Set oApp = AddInSiteObject.Application
Set oAppEvents = oApp.ApplicationEvents
End Sub

Private Property Get ApplicationAddInServer_Automation() As Object
Set ApplicationAddInServer_Automation = Nothing
End Property

Private Sub ApplicationAddInServer_Deactivate()
' Release all references.
Set oApp = Nothing
Set oAppEvents = Nothing
End Sub

Private Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long)
' No longer used.
End Sub

Private Sub oAppEvents_OnSaveDocument(ByVal DocumentObject As Inventor.Document, _ ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, _ HandlingCode As Inventor.HandlingCodeEnum)
MsgBox ("It Worked!")
End Sub

And it works! That's the beauty of it! Thanks for everyone's help on this! I'll hopefully become as good of a programmer as you other chipheads.
0 Likes
Message 13 of 13

Anonymous
Not applicable
Seems like I remember having this problem myself. The example code they provide you with in the help is correct but what they fail to tell you or at least I didn't understand) is that part of their sample code needs to go into a module seperate from the class module with the bulk of your code. My module has only the following.... Public g_oIvApp As Inventor.Application Public oApp As Inventor.Application Public Sub Plotting() Dim oDoc As Inventor.Document Set oDoc = oApp.ActiveDocument End Sub The class module has the other code....... "mattis" wrote in message news:11917330.1087934082807.JavaMail.jive@jiveforum2.autodesk.com... > I did that. I used that code as a base for my code. The icons show up just fine. It's just that when I click on them, nothing happens. When I read that message in the help file, I thought that my button battle was futile. Are there any other examples of custom toolbars that are added via an add-in? > > I want a custom toolbar that is always there. The sample add-in puts the buttons in the sketch environment only. I want this to be a global toolbar for all environments. On second thought, maybe I should make it environment specific. Naaahh! > > The real reason that I want it global is bacause my guys are coming from MDT. They are used to seeing the same ol buttons in certain areas of their screens.
0 Likes