Modifications to rule to run from Visual Studio rather than just from Inventor

Modifications to rule to run from Visual Studio rather than just from Inventor

Ethibaudeau
Advocate Advocate
712 Views
8 Replies
Message 1 of 9

Modifications to rule to run from Visual Studio rather than just from Inventor

Ethibaudeau
Advocate
Advocate

Currently, I have been editing rules in Notepad++, and running them from within Inventor (iLogic pane, or adding a button on ribbon). But I would like to start using Visual Studio 2019 to run/debug code while still maintaining the ability to run these rules from Inventor.

 

This code works fine when running from Inventor:

Public Class HelperClass
    'Helper
End Class

Class ThisRule
    Dim oDocument As Document 'Declaring variable here so it can be
    'used across the subs/functions without having to pass it each time

    Sub Main
        'Code here
    End Sub

    Function DoStuff()
    End Function
End Class

 

To run the above code in Visual Studio, I know I need a few differences. I have the Visual Studio project referencing "Autodesk.Inventor.Interop" and I know I need to create an object for the Inventor application:

Imports Inventor

Public Class HelperClass
    'Helper
End Class

Class ThisRule           
    Dim ThisApplication As Inventor.Application
    Dim oDocument As Document 'Declaring variable here so it can be
    'used across the subs/functions without having to pass it each time

    Sub Main()
        ThisApplication = GetObject(, "Inventor.Application")
    End Sub

    Function DoStuff()
    End Function
End Class

But the code above results in an error in VS2019 "No accessible 'Main' method with an appropriate signature was found". I tried various iterations of making "Main" and "ThisRule" either "Public", or "Shared", but admittedly I don't know the best way to use those keywords in practice.

0 Likes
713 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @Ethibaudeau.  I see that you figured out the ThisApplication term, and how to replicate it in vb.net.  Here is a couple links to some other related things you may want to replicate.

This link shows several terms (pre-defined object variables) that only exist within an iLogic rule, because they are created for us behind the scenes for us by the iLogic ApplicationAddIn.

Rule Objects 

Then this link just clues you in to some settings that are set for us automatically behind the scenes in the iLogic rule editor.

Advanced iLogic Techniques Reference 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

Ethibaudeau
Advocate
Advocate

I appreciate the reply. I believe I have mostly avoided iLogic in the rules I've created so far (sticking to just using the Inventor API), so I don't think there's much to convert over except some Logger and MessageBox statements as well as more explicitly stating the namespace for some enums.

 

As far as my code that is not working, it looks like I've followed the general idea in your second link under "Additional Statements" for how to set up "Main()" and "Class ThisRule", so I'm still stuck on where I went wrong and the error that "Main" is not accessible. Changing to "Shared Sub Main" or "Public Sub Main" does not change the error.

0 Likes
Message 4 of 9

Frederick_Law
Mentor
Mentor

You might need to follow addin instruction:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-52422162-1784-4E8F-B495-CDB7BE9987AB

 

VBA and iLogic removed lots of setup codes so they're very easy to learn.

Addin on the other hand require a lot more.

 

Also look at this:

https://www.autodesk.com/support/technical/article/caas/tsarticles/ts/29mPk2V7aweIo6eLckSF1k.html#:~....

0 Likes
Message 5 of 9

Ethibaudeau
Advocate
Advocate

Thanks for those - though I wasn't able to get much from them. Those examples are more complicated than what I'm looking for. Maybe I'm being stubborn, but I'm not looking to create a add-in.

 

I just want rules I can run in Inventor and be able to edit/run them in Visual Studio.

0 Likes
Message 6 of 9

Frederick_Law
Mentor
Mentor



@Ethibaudeau wrote:

Maybe I'm being stubborn

I just want rules I can run in Inventor and be able to edit/run them in Visual Studio.


You can't.

You can keep hitting your head on the wall until the wall go away or find your way around the wall.

 

You're trying to put diesel in gasoline car.

You can get it to work if you swap the fuel system, ignition system and engine.

 

iLogic rules run inside IV.

VS run outside IV and need extra code to connect to IV.

 

iLogic don't have any debugging options.

VBA does.

 

Another way to debug iLogic is use Logger to put information in the log.

I use Logger.Info

0 Likes
Message 7 of 9

Ethibaudeau
Advocate
Advocate

I think that's totally fair that some extra code is needed to run from VS.

 

I'm just missing what code that is. In my initial post I made an attempt at simple template that has some of those changes to make the script run from VS.

 

Unless... are you saying that you can not run scripts from outside of Inventor - and that they must be compiled add-ins?

0 Likes
Message 8 of 9

Frederick_Law
Mentor
Mentor

I've setup VS Community to compile and run with full debug with IV addin.

There are a few things needed to setup to do that.

 

On one of the link I attached use simpler code than full addin.  I didn't went through that and test.

I think it's part of the "Check out the self-paced guide “My First Plug-in”" at the top of the forum.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/check-out-the-self-paced-guide-my-fi...

 

I started in VBA, skipped iLogic (because it doesn't has all the events), get to addin and trying iLogic again.

Lot's of reading.

0 Likes
Message 9 of 9

JelteDeJong
Mentor
Mentor

You might want to have a look at my project on Github. It was created to write and debug iLogic rules from Visual Studio. In the blog post "Writing and debugging iLogic rules" you will find some more info.

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

0 Likes