Events in Inventor BOM

Events in Inventor BOM

sundaram1087
Advocate Advocate
1,055 Views
12 Replies
Message 1 of 13

Events in Inventor BOM

sundaram1087
Advocate
Advocate

Hi

Is there is any way to raise the event when BOM Insert into the Inventor drawing through inventor Addin?

Regards

Shunmugasundaram

 

0 Likes
Accepted solutions (2)
1,056 Views
12 Replies
Replies (12)
Message 2 of 13

mjordan3
Advocate
Advocate

I just looked through Inventor's events in VS's object browser, it doesn't look like there is an event raised when a parts list is placed in a drawing.  There may be a way to create a custom event for that, but it's a bit above my skill level.  A hacky way would be to poll the parts lists collection periodically and raise an event when the count changes.  Personally I'm not a fan, just due to the extra overhead.

0 Likes
Message 3 of 13

bradeneuropeArthur
Mentor
Mentor

I think there is a possibility.

I am far from my desk right now.

I will take a look at it very soon.

You could use the on activate command event and then trigger the place Partlist.

Keep watching...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 13

JelteDeJong
Mentor
Mentor
Accepted solution

You could subscribe to the event "Inventor.ApplicationEvents.OnDocumentChange" something like this:

inventor = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
appEvents = Inventor.ApplicationEvents 
AddHandler appEvents.OnDocumentChange, AddressOf partListCreateEvent

and then the function "partListCreateEvent" should look like this:

Private Sub partListCreateEvent(
                                    DocumentObject As _Document,
                                    BeforeOrAfter As EventTimingEnum,
                                    ReasonsForChange As CommandTypesEnum,
                                    Context As NameValueMap,
                                    ByRef HandlingCode As HandlingCodeEnum)
    HandlingCode = HandlingCodeEnum.kEventNotHandled

    If (BeforeOrAfter = EventTimingEnum.kAfter And Context(1).Equals("CreatePartListLocalBOM")) Then
        MsgBox("a partlist has been created")
    End If
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 13

sundaram1087
Advocate
Advocate

Hi All

               Thanks for you Code. It works fine.

               it reduces my time lot

               Thanks for your help

 

Regards

Shunmugasundaram k

 

               

 

0 Likes
Message 6 of 13

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Hi,

 

Additional I would like to share the other possibility with you!

 

    Private WithEvents oUIEvents As Inventor.UserInputEvents

    Private Sub oUIEvents_OnStartCommand(CommandID As CommandIDEnum) Handles oUIEvents.OnStartCommand
        If CommandID = CommandIDEnum.kInsertPartsListCommand Then
            MsgBox("partslist has been added")
        End If
    End Sub
End Class

This would do the trick too.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 7 of 13

mjordan3
Advocate
Advocate

Guys, these are fantastic!   Gives me new avenues to explore. Thanks.

0 Likes
Message 8 of 13

paul.gutierrezZNHGQ
Explorer
Explorer
Sorry for necro posting this. I'm trying to use this as well, but I can't wrap my head around to make this work.

How do I trigger the ilogic to work? I would need to have it running all the time? I do several actions immediately after I place something in Inventor, figuring out how to make Inventor react to that would save a lot of time.

But first I would like to understand how to make the example on this thread to work, any additional pointers would be greatly welcomed.

Thank you in advance.
0 Likes
Message 9 of 13

WCrihfield
Mentor
Mentor

Hi @paul.gutierrezZNHGQ.  Working with Events using iLogic rules is generally not the best way, but it can be done in some situations.  Events are better monitored for using something like an Inventor ApplicationAddIn, so it is loaded when Inventor is started, and be running in the background for you, while you work with various other tools.  Although there are a few ways to do this using iLogic rules, you should know that once you start an event listener, it can be difficult to get rid of it again, if the code that created it is not set-up correctly.  It is also possible to have multiple of the same event listeners running in the background, eroding your performance.  To get rid of them, you may have to quit Inventor, then restart.  This link should also be helpful.

Here is the most basic version of an iLogic rule example using code similar to the above.

 

Sub Main
	oUIEvents = ThisApplication.CommandManager.UserInputEvents
End Sub

Dim WithEvents oUIEvents As Inventor.UserInputEvents

Sub oUIEvents_OnStartCommand(CommandID As CommandIDEnum) Handles oUIEvents.OnStartCommand
        If CommandID = CommandIDEnum.kInsertPartsListCommand Then
            MsgBox("A PartsList was just inserted.", vbInformation, "InsertPartsList Event")
			Logger.Info("A PartsList was just inserted.")
        End If
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 13

paul.gutierrezZNHGQ
Explorer
Explorer

Thank you so effing much!

This is the best reply I've had in my life about anything. Thank you so much, this is exactly what I needed.

In hindsight, it's obvious to have the event listener in and Addin, I'll build one when I grasp the concept of events, I think playing around with them in iLogic would help me implement it on an Addin.

Once again, thank you so much.

0 Likes
Message 11 of 13

WCrihfield
Mentor
Mentor

Hi @paul.gutierrezZNHGQ.  Here is another version of that same process in an iLogic rule, but using the updated codes/process that you can find online help documentation for.

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-8FCB98C5-CEAF-4358-88D9-47923E30BE4D 

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=UserInputEvents_OnActivateCommand 

 

Sub Main
	Dim oUIEvents As UserInputEvents = ThisApplication.CommandManager.UserInputEvents
	AddHandler oUIEvents.OnActivateCommand, AddressOf oUIEvents_OnActivateCommand
End Sub

Sub oUIEvents_OnActivateCommand(CommandName As String, oContext As NameValueMap)
        If CommandName = "DrawingPartsListCmd" Then
            MsgBox("The command for creating a PartsList was just activated.", vbInformation, "Create PartsList Event")
			Logger.Info("The command for creating a PartsList was just activated.")
        End If
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 13

paul.gutierrezZNHGQ
Explorer
Explorer
Thank you once again WCrihfield.

With your help I managed to put together this rule on my drawing template, it's triggered to run when I open the document:

Sub Main
oUIEvents = ThisApplication.CommandManager.UserInputEvents
End Sub

Sub ChangeLastBOMTitle()
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet

Dim oPL As PartsList

oPL = oSheet.PartsLists.Item(oSheet.PartsLists.Count)
Dim tableTitle As String
Dim fileTypeFound As Integer

tableTitle = oPL.ParentView.ReferencedFile.DisplayName
fileTypeFound = InStr(tableTitle, ".iam")
If fileTypeFound = 0 Then
oPL.Title = tableTitle & " PARTS LIST"
Else
oPL.Title = tableTitle.Substring(0, fileTypeFound - 1) & " PARTS LIST"
End If
oPL.Sort("ITEM", True)
End Sub

Dim WithEvents oUIEvents As Inventor.UserInputEvents

Sub oUIEvents_OnStopCommand(CommandID As CommandIDEnum) Handles oUIEvents.OnStopCommand
If CommandID = CommandIDEnum.kInsertPartsListCommand Then
ChangeLastBOMTitle()
End If
End Sub

I know my coding practices aren't..."world class" but as a proof of concept, it's working exactly as I wanted it to work.

However, following your comment about if I don't handle the event properly it will just keep running. That's exactly what's happening after I close the drawing file. I've been thinking of having another rule that runs when the document is closing so it stops the event, but I really haven't figure out a way how to do that.

Is there something in the autodesk files that I can look to see how to stop the event from running?

Thank you in advance.
0 Likes
Message 13 of 13

WCrihfield
Mentor
Mentor

Hi @paul.gutierrezZNHGQ.  Glad to see that your project is advancing as planned.  When you only plan to use an event listener for a limited duration, the same source code that creates the event listener, must also include some code to remove it at some specific point, or when some other event happens.  Otherwise you generally have to exit the Inventor application entirely to get rid of it, not just close all documents.  Depending on your specific needs, there are different ways to plan for and write the removal portion of the code.  Basically, that code that created the listener is being held in Inventor's session memory, and is still 'running' or 'active' in the background, and it still has the pointer/handle on that listener it created, and only it can remove it.  No other rule will be able to access it to get rid of it.  And changing the contents of the code, in the same session, after you have ran it, is not a good idea either, because the original version of the code is what is still being held in memory while it runs in the background.

 

I (and others) used SharedVariables for this purpose, because they are a way to store data temporarily (just in Inventor's session memory), while you do other things.  When your code creates the listener, it can also create one of these SharedVariables, with a name and value that make sense to you.  Your code can also check if this SharedVariable already exists, and what its value is before creating the listener.  You can use that to make sure you are not duplicating the listener (other one can not be removed then).  You can also use that, with the help of another rule which would change its value, to manually initiate getting rid of the listener, because if its value is a certain way, you can use that as a clue to get rid of an already existing listener.  When you run the other rule, it will change SharedVariable's value, then run the rule that created the listener again, which will check its value right at the start, and if its is a certain value, it will remove the existing listener, instead of creating a new one.

 

Another process is to create two listeners, one for the event you are really after, and another for when a specific document closes.  Then when that specific document closes, it will remove both listeners.  It can get as complicated as you want it.  And if you search around within this forum long enough, you will most likely find some examples of both of these ways, and maybe even other ways.

Below is a link to one of my contribution posts about creating event handlers within iLogic rules that may help.

https://knowledge.autodesk.com/community/article/348361 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)