Run iLogic code in Visual Studio to debug

Run iLogic code in Visual Studio to debug

chrisw01a
Collaborator Collaborator
1,614 Views
8 Replies
Message 1 of 9

Run iLogic code in Visual Studio to debug

chrisw01a
Collaborator
Collaborator

Can someone please get me started here?  

 

I have a iLogic rule that I need to run in visual studio 2022 so i can step through with debug and solve problems with new Inventor 2022 model states.  I can figure it out as soon as I get a program that can run but I don't know where to start.  I have a new project made and ready for code but I don't understand how to import the Inventor name space and whatever else I need.

 

For example, here is what the code begins with now:

 

Sub Main

'Get current document
Dim doc = ThisDoc.Document

Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition

'MessageBox.Show("debug")

doc.Rebuild()

'Get the BOM object
Dim oBOM As BOM = oAssyDef.BOM
'enable the Parts Only View
oBOM.PartsOnlyViewEnabled = True
'Get the Parts Only view of the BOM
Dim oBOMViewPO As BOMView = oBOM.BOMViews.Item("Parts Only")
'declare variable for each BOM row.
Dim oBOMRowPO As BOMRow

'For each row in the Parts Only BOM, do the following
For Each oBOMRowPO In oBOMViewPO.BOMRows
 'do some stuff
Next

' Get the active project
	Dim oProject As DesignProject = ThisApplication.DesignProjectManager.ActiveDesignProject

 

Looks like I will need to change "ThisDoc" to specify the Inventor app but thats where I'm stuck.

 

Here is what I have so far in VB, I just don't know how to add the reference so I can call the Inventor objects.

 

 

Public Class Form1
    Sub Main()

    End Sub

    Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click
        Main()
    End Sub
End Class

 

 

 

 

 

Thank you!

 

0 Likes
Accepted solutions (1)
1,615 Views
8 Replies
Replies (8)
Message 2 of 9

chrisw01a
Collaborator
Collaborator

Is there a file that I need to point to in the "references" area?

 

chrisw01a_0-1637595526774.png

 

0 Likes
Message 3 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

If you only want to debug rules then you don't need to reference anything as far as I know. But you better read this article it has all information that you need. On my GitHub page, you can find the project that I use to debug iLogic rules.

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 4 of 9

chrisw01a
Collaborator
Collaborator
The way it is now, I can't even run the VB code because there is no Thisdoc.doc or AssemblyComponentDefinition.

I'll look at the github. Thanks
0 Likes
Message 5 of 9

chrisw01a
Collaborator
Collaborator

So it looks like this might work but what am I missing here because I'm getting  a object reference not set to instance of an object error.

 

chrisw01a_0-1637627951993.png

 

 

chrisw01a_0-1637627875826.png

 

0 Likes
Message 6 of 9

chrisw01a
Collaborator
Collaborator

Ha!  Attaching Visual Studio to the Inventor process looks like it will do the trick.

 

Thank you!

0 Likes
Message 7 of 9

chrisw01a
Collaborator
Collaborator

I would still like to understand what is missing here with the "PartDocument" though.

0 Likes
Message 8 of 9

JelteDeJong
Mentor
Mentor

You didn't tell which document you wanted to use. For example if you want the active document then you could use:

 

Dim doc As PartDocument = ThisDoc.Document

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

chrisw01a
Collaborator
Collaborator

Got it.  Thank You!

0 Likes