Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting Events Macro to Add-In

10 REPLIES 10
Reply
Message 1 of 11
ericp-theelf
785 Views, 10 Replies

Converting Events Macro to Add-In

I have obtained a very useful macro from another discussion thread, http://discussion.autodesk.com/thread.jspa?forumID=78&threadID=655950. It automatically names the frame members inserted by Frame Generator. I have modified the macro for our internal naming conventions, but the basic functionality is the same. I would like it to load automatically whenever I am in Inventor and believe an Add-In is the way to go. I have followed Brian Ekins "Taking the Step from VBA to Inventor Add-Ins" paper, but I think I am missing huge chunks on how Add-ins handle events and have been unsuccessful in finding any help topics. Basically, I need help. Please point me in the direction as to how to handle events in an add-in. Concepts and/or examples will be greatly appreciated.

Thanks in advance!!
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: ericp-theelf

Connecting to events is really quite simple. Within your add-in class
you'll need to declare a variable as the object that will be firing the
event. For example, if you want to listent to the ApplicationEvents you
would declare an object to be of that type. It also needs to be declared
using the WithEvents keyword. It's declared as a member variable of the
class. This is at the top of the class and the same place where you declare
the variable to store the Application reference.

Private WithEvents m_appEvents As ApplicationEvents

All this does is declare the variable but you still need to assign something
to it. Typically you'll connect up the events during the activation of your
add-in. It's just a simple assignment like shown in the second line below.
You should already have the first line.

m_inventorApplication = addInSiteObject.Application
m_appEvents = m_InventorApplication.ApplicationEvents

The next step is to create a handler for the event(s) you want to listen to.
At the top of the editor window in VB there are two combo boxes. If you
click on the combo box on the left you should see the name of the variable
you created for this event set. Select it in the combo box. The box on the
right will now list all of the events that the selected object supports.
Select any of the events from the list. VB will now insert the event
handler code into your project. Now whenever that action happens, Inventor
will fire the event to notify your add-in. Read the documentation carefully
for the events you want to use.

Good luck.
--
Brian Ekins
Autodesk Inventor API
Message 3 of 11
ericp-theelf
in reply to: ericp-theelf

Thanks Brian. Your replay was amazingly quick.

I have looked further into things and I am not sure the 'events' I am trying to access are really events. They are actually coming from the CommandManager. The pertenant piece of code can be seen below:

*******Begin Code*************
Public Class FG_AutonamerClass

Private WithEvents oInsertCmdInputEvents As ControlDefinitionEvents
Private WithEvents oChangeCmdInputEvetns As ControlDefinitionEvents
Private WithEvents oDemoteCmdInputEvetns As ControlDefinitionEvents
Private m_invtrApp As Inventor.Application


Public Sub Initialize(ByRef m_inventorApplication As Inventor.Application)

m_invtrApp = m_inventorApplication

oInsertCmdInputEvents = m_inventorApplication.CommandManager.ControlDefinitions.Item("AFG_CMD_InsertProfile").ControlDefinitionEvents
oChangeCmdInputEvetns = m_inventorApplication.CommandManager.ControlDefinitions.Item("AFG_CMD_ChangeProfile").ControlDefinitionEvents

If m_inventorApplication.SoftwareVersion.Major > 11 Then
oDemoteCmdInputEvetns = m_inventorApplication.CommandManager.ControlDefinitions.Item("AFG_CMD_Demote").ControlDefinitionEvents
End If

End Sub

Private Sub oInsertCmdInputEvents_OnCommandInputs(ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, ByVal Inputs As NameValueMap, ByVal HandlingCode As HandlingCodeEnum)
Call HandleCmdInputEvents(BeforeOrAfter, Context, Inputs, HandlingCode)
End Sub

Private Sub oChangeCmdInputEvetns_OnCommandInputs(ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, ByVal Inputs As NameValueMap, ByVal HandlingCode As HandlingCodeEnum)
Call HandleCmdInputEvents(BeforeOrAfter, Context, Inputs, HandlingCode)
End Sub

Private Sub oDemoteCmdInputEvetns_OnCommandInputs(ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, ByVal Inputs As NameValueMap, ByVal HandlingCode As HandlingCodeEnum)
Call HandleCmdInputEvents(BeforeOrAfter, Context, Inputs, HandlingCode)
End Sub

*******End Code*************
Again, macro seems to run just fine, but these are not geting caught and the Add-In is not functioning. Anyone have any ideas?

Thanks.
Message 4 of 11
Anonymous
in reply to: ericp-theelf

You are correctly hooking up to events but the problem is that the events
you're hooking up to aren't officially supported. This particular event is
implemented for only a couple of commands and not for any Frame Generator
commands. If support for this is extended to other commands in the future
it might be made public.

What is it that your trying to accomplish? There might be another approach.
--
Brian Ekins
Autodesk Inventor API
Message 5 of 11
ericp-theelf
in reply to: ericp-theelf

We have a fairly simple, yet rigid naming convention wherein we name all subcomponents of assemblies by the assembly name plus an alpha or numeric appendage. We also use Vault, which enforces unique filenames for all parts and assemblies. Frame Generator is extremely problematic in it's automatic naming conventions. The macro I am trying to get to work as an Add-In intercepts the FG automatically generated filename and extracts the numeric part from it, then appends that on the name of the assembly. It is all done automatically. It has dramatically sped up work when using FG. If I have to, we will just continue to run the macro - deployment is just a pain. The macro is a pain in another way in that if you forget to run it, it doesn't work - doh. However, it does run beautifully in VBA. Maybe, if everyone is set up with the macro and I could write an add-in that simply loads the VBA macro, that could work. It is just frustrating that Frame Generator is such a marvelous tool on the surface, but has so little capacity to be modified or parameterized that in a custom type environment - it almost ceases to be a help and becomes more of a hinderment.

Please any suggestions will be appreciated and welcomed!!
Message 6 of 11
Josh_Petitt
in reply to: ericp-theelf

>we will just continue to run the macro - deployment is just a pain.

how are you deploying?

we have an .ivb on our network that every CAD user uses. This makes it easy to "deploy" (not really deploying but anyway) cause everyone is using the master .ivb. The only drawback is that the first person to use the .ivb gets the editing rights. So if you are doing some additions, you have to have everyone shut off IV, then you start it up to get the editing rights, then everyone can go back to work. It is a pretty simplistic system but it works okay for us.
Message 7 of 11
noontz
in reply to: Anonymous

It would be nice if this was mentioned in the documentation..

I was struggeling with a specific ControlDefinition.ControlDefinitionEvents.OnCommandInputs, wondering over the lack of documentation and why it didn´t trigger until I stumbled into this post.

 

These properties are indeed public & the post is 5 years old...

Message 8 of 11
adam.nagy
in reply to: noontz

Thank you.

 

I've forwarded this comment to the appropriate person.



Adam Nagy
Autodesk Platform Services
Message 9 of 11
Rene_Gerlach
in reply to: adam.nagy

Next two years and nothing changed 😞

 

Cheers

 

René

Message 10 of 11
adam.nagy
in reply to: Rene_Gerlach

The ControlDefinitionEvents is hidden now, which should show that it is not supported.



Adam Nagy
Autodesk Platform Services
Message 11 of 11
Rene_Gerlach
in reply to: adam.nagy

Hi Adam,

 

I think its the wrong way :-(.

Instead of make the API working, just hide....

 

Cheers

 

René

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report