Run external iLogic on event

Run external iLogic on event

Anonymous
Not applicable
1,237 Views
8 Replies
Message 1 of 9

Run external iLogic on event

Anonymous
Not applicable

Hello

 

I would like to create an addin which runs an external ilogic rule at a specified event. I know this can be done with the standard iLogic triggers, but this doesn't apply to files already created.

 

Example: I want my external rule Start.iLogicVb to run on Before Save Document (or any other event)

I want it to run every time i save the active document (initial and save as)

 

I've tried MuM - iLogic Run on Save ( http://inventortrenches.blogspot.fi/2011/08/built-for-speed-running-ilogic-rules.html ) but it does not let me specify which event i would like to use, and it does not run on the initial save of a new file or save as.

 

I only know the basics of iLogic and no other programming language. What is the best way for me to create such a program described above. 

I feel like that an experienced programmer would not need much more than a few hours to create this? Am i wrong, should i try to hire someone or is it possible i could solve this myself within a reasonable amount of time?

 

The threads below almost describes what i want.

 

https://forums.autodesk.com/t5/inventor-customization/launch-external-ilogic-rule-with-vba/m-p/31706...

https://forums.autodesk.com/t5/inventor-customization/run-ilogic-external-rule-with-inventor-vba/m-p...

 

Thankful for any help

 

0 Likes
1,238 Views
8 Replies
Replies (8)
Message 2 of 9

HermJan.Otterman
Advisor
Advisor

did you know about the code injector?

 

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

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 9

Anonymous
Not applicable

Thanx for your reply. I've briefly read through the post about the code injector, but to my understanding, this involves "injecting" code into existing files?

 

I would like to avoid having to much code and references to code inside my files if possible. But maybe this is a solution after all, as long as the references are to external ilogic which can easily be edited.

 

 

0 Likes
Message 4 of 9

HermJan.Otterman
Advisor
Advisor

I thought you could also "inject" triggers

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 5 of 9

JoAntt
Enthusiast
Enthusiast

Take this

 

File events

 

 

And this

 

 

Public Sub iLogic(rule As String, Optional bLocal As Boolean = False)
Dim iLogicAuto As Object
Dim addIn As Inventor.ApplicationAddIn
Try
addIn = invApp.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
addIn.Activate()
iLogicAuto = addIn.Automation
Catch
iLogicAuto = Nothing
End Try
If thisDoc Is Nothing Then
MsgBox("Cant find any open file")
Exit Sub
End If
If (iLogicAuto Is Nothing) Then Exit Sub
If bLocal = True Then
iLogicAuto.RunRule(thisDoc, rule)
Else
iLogicAuto.RunExternalRule(thisDoc, rule)
End If

End Sub
Message 6 of 9

Anonymous
Not applicable

Thanx guys. I'll give this programming thing a go and report back when i hit a dead end. 

 

Btw, would you say that the self paced guide by autodesk is a good way to start or are there any other resources which will suit me better?

 

/J

0 Likes
Message 7 of 9

MechMachineMan
Advisor
Advisor

Step 1: Install the devtools.msi that comes in the SDK with inventor.

Step 2: Find "VBAAutoMacro" sample.

Step 3: Open the sample and read the readme.

Step 4: Follow the instruction in the readme. Very simple. (to create the .addin file, just make a txt with the exact text in it, then rename the file to .addin).

Step 5: Open Inventor and reap the rewards.

Step 6: Write a marco to run on startup that enables event tracking in inventor

Step 7: Write the macro that catches the even and runs an iLogic rule.

Step 8: Implement them all properly.

Step 9: Profit.


--------------------------------------
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
Message 8 of 9

Anonymous
Not applicable

Okay, with the help from you guys I have managed to copy paste my way to a working add-in.

 

I'm using the add-in template 2017 and Microsoft Visual Studio 2015. I started by following this guide:

http://modthemachine.typepad.com/my_weblog/2008/10/converting-vba-auto-macros-to-an-add-in.html

 

Then i simply copy pasted some code from a thread here and tweaked it a bit.

 

Since I don't know how to write code, I did my best declaring variables and so on. I also deactivated some variable, but don't really know why.

 

1_snTXFElFuQLSFDnvZKJ6IA

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I actually don't know where to paste the code i found on this forum in my project, but it compiles and runs. 

 

Could i get some kind of quick peer review and comments on what changes i should make to my addin to avoid any problems

 

Thanks for your help!

 

See attached project

 

//J

 

 

0 Likes
Message 9 of 9

Anonymous
Not applicable

I've come across one snag.

 

My program now runs my external ilogic code on the event Before Save, when the active document is saved.

 

If i edit this part from a parent assembly from the BOM, nothing is updated in my parts when i save. But the addin runs for each part (because my msgbox pops up twice. Once from the active parent assembly and once for the part in the assembly)

 

If a add an iLogic event trigger in the ipt which fires on "before save". This is run, even if i edit my part from another document, For example from the BOM.

 

Is it possible to replicate this behaviour?

 

 

 

 

0 Likes