Run Rule on Application Event Add-in????

Run Rule on Application Event Add-in????

MechMachineMan
Advisor Advisor
1,536 Views
14 Replies
Message 1 of 15

Run Rule on Application Event Add-in????

MechMachineMan
Advisor
Advisor

Has anyone come across the rule that does what the title says?

 

I'm looking for an add-in that allows the functionality of the Application Level Events by simply triggering a rule from there.

 

The reason I'm looking for this is so that I don't have to embed event triggers in every document.

 

The idea is that with this add-in functionality, I can tell it to run a rule on document save that will then check document type and run other rules accordingly.

 

Ideally, this would have a separate xml / config file that would allow me to attach certain rules/macros with certain Events.

 

 

Anyone heard of an add-in like such, or is it seeming like I will have to embark on making my own?


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
1,537 Views
14 Replies
Replies (14)
Message 2 of 15

pball
Mentor
Mentor

I haven't really dug around the available add-ins on the Autodesk website but this doesn't seem like that difficult of an add-in to code. If you'd like any help making an add-in just let me know and I'd be glad to give some input or share bits of code that might be helpful.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 3 of 15

Anonymous
Not applicable

There was such an add-in that was created some time ago as a response to iLogic being made available back a few years. This was before the code was found to inject the trigger events to existing parts. Ran a single 'master rule' for each part type on the desired trigger.

 

That being said, its a few installs and more than a few machines ago. I will look around, CurtisW might have been the author.. not confident.

0 Likes
Message 4 of 15

Anonymous
Not applicable

So MegaJerk created a CodeInjector tool out of VB.Net a while back that allows for code trigger injection:

http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-tri...

 

 

And Curtis Waguespack wrote about Jürgen Wagner's addin that created the same 'run ilogic before save' as an add-in.

https://inventortrenches.blogspot.com/2012/01/creating-basic-ilogic-rule-with-event.html

 

You might be able to dissect their code to get what you need from it. Best of luck.

0 Likes
Message 5 of 15

Owner2229
Advisor
Advisor

Check this post and my solution in it, it might be relevant to your issue:

 

http://forums.autodesk.com/t5/inventor-customization/my-first-addon-help/m-p/6245712#M62822

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 15

MechMachineMan
Advisor
Advisor

@Owner2229

 

Definitely looks promising, Mike!

 

It's a little bit beyond what I have done with VB so far, but I'm sure between your post and following the MyFirstAddin guide I should be able to figure it out when I get some time.

 

I'm sure I will have some questions for you throughout the process, but this definitely seems like it will accomplish what I want.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 15

Owner2229
Advisor
Advisor

Feel free to ask me anything and I'll try to answer it as good and fast as I can.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 8 of 15

MechMachineMan
Advisor
Advisor

I decided to go ahead with trying out the event handling within Inventor first to see how/if I could really accomplish what I wanted to.

 

It's looking very promising right now, and I think I'm about at the point that I can start converting to an add-in.

 

I'm posting my current code here for if anyone has suggestions/future reference is anyone else has questions.

 

 

What it does:

    Catches the before save event, and runs an iLogic rule within the document that is being saved (using ThisDoc).

 

HOWEVER, as outlined in the post I copied it from, the user needs to go in and run the "Start Event" macro every time a new application is opened to enable the event tracking.

 

1) Make a new class module within inventor VBA and rename to "AppEvents". Copy paste following into it.

Private WithEvents oAppEvents As ApplicationEvents
Public Sub Connect()
Set oAppEvents = ThisApplication.ApplicationEvents
End Sub
Public Sub disconnect()
Set oAppEvents = Nothing
End Sub

Private Sub oAppEvents_OnSaveDocument(ByVal DocumentObject As Document, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If BeforeOrAfter = kBefore Then
Call RunExternaliLogicRule(DocumentObject, "_BeforeSaveRule")
End If
End Sub

Private Sub RunExternaliLogicRule(ByVal doc As Document, ByVal ruleName As String)
Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Call iLogicAuto.RunExternalRule(doc, ruleName)
End Sub

Private Function GetiLogicAddin(oApplication As Inventor.Application) As Object
On Error GoTo NotFound

Dim addIn As ApplicationAddIn
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")

If (addIn Is Nothing) Then
'
Else
addIn.Activate
Set GetiLogicAddin = addIn.Automation
End If
NotFound:
End Function

2) Make a new module. Copy paste code below into it:

Option Explicit
Dim appevent As New AppEvents
Public Sub StartEvent()
    appevent.Connect
End Sub
Public Sub StopEvent()
    appevent.disconnect
End Sub

3) Create/add an external rule named "_BeforeSaveRule" such as the one below:

Sub Main()
    On Error Resume Next
        oDoc = ThisDoc.Document

	If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject
		MsgBox("The ext rule was run in DWG " & oDoc.FullFileName)
	Else
		MsgBox("Ext Rule run in: " & oDoc.FullFileName)
	End if
     If Err.Number <> 0
            MsgBox("Error in Ext Rule!")
     End if
End Sub

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 15

Owner2229
Advisor
Advisor

Good job. Take a look at these samples:

 

sample-code-for-inventor-add-in-dll-for-vb-net

 

You can download the one at bottom and by following the guideline you should be able to create your AddIn.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 10 of 15

MechMachineMan
Advisor
Advisor
With that, do I not need to download the addin wizard provided in the sdk?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 11 of 15

Owner2229
Advisor
Advisor

No, you don't. I've initialy made this template because I was not able to use VisualStudio, therefore I couldn't use the wizard eighter.

You can work with this even in text editor, but you still need a compiler. In case you wanna know, I'm using SharpDevelop 4.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 12 of 15

MechMachineMan
Advisor
Advisor
I think I'm going to try a trial by fire and see how using the wizard goes
of it came get it together.

This will definitely be a solid back up!

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 13 of 15

MechMachineMan
Advisor
Advisor

Fire encountered, indeed!

 

Looks like I am using your template.

 

(ran into this after install VB Express 2013, downloading msi tools, and downloading the .zip template and copying to the directory as stated in the My First Plug-in overview)

 

Looks like I'm using your templates!

 

Capture.JPG


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 14 of 15

Owner2229
Advisor
Advisor

(If I remembere correctly) you can't use VS Express 2013.

The only supported versions are 2008 and 2010.

You can try one of these instead.

 

Or you can use my template, whatever you want.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 15 of 15

MechMachineMan
Advisor
Advisor
Hmmm that's unfortunate! I guess I will have to re-download one of those. I
had thought they kept it it working for the Visual studio versions of 2
years before.

This would make a lot of sense!

Thanks again!

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes