Launching an iLogic Rule from a VB Form

Launching an iLogic Rule from a VB Form

D.Wheeler3GADA
Advocate Advocate
463 Views
4 Replies
Message 1 of 5

Launching an iLogic Rule from a VB Form

D.Wheeler3GADA
Advocate
Advocate

Is it possible to invoke an iLogic Rule from a VB Form?

 

I am trying to create an "Exit" button on a form that will not only exit the form, but launch an iLogic rule from within a component in the assembly. I am unsure if this is even a possibility, so I thought I'd ask here before spending hours researching it... As always, any tips/advice is greatly appreciated!

0 Likes
464 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @D.Wheeler3GADA.  This definitely sounds doable.  To be able to run a 'local' iLogic rule that is saved within a component in the active assembly from a vb.net Windows Form button click event, you will need 3 things.  The code that specifies the physical button within the form, the Sub routine to act as the event handler for the button click event, and another custom Sub routine for running the rule.  Within the event handler Sub routine, you can close the form, then run the other custom Sub routine that runs the rule.  Within the Sub routine to run the rule, you will need to get the Inventor Application object, then step down into its ApplicationAddIns, to get the one for the iLogic add-in.  Once you have that specific add-in object to a variable, get its 'Automation' object to a variable.  From that automation object you can use the methods that are available under it, which are roughly equivalent to the ones you see within an iLogic rule when you type in "iLogicVb.Automation" (Link).  There are 4 possible methods that you could use there for running a 'local' rule (not an external rule)(Link1, Link2, Link3, Link4), depending on your needs/plans.  This is very similar to the route you have to take when running an iLogic rule from a VBA macro.  There are several examples of that process on this forum too.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

D.Wheeler3GADA
Advocate
Advocate

@WCrihfield ,

        Thank you for the info! After thinking about it over the weekend, I decided to create a directory of external iLogic rules that I could launch from the form that will then launch the series of rules I want to run in the correct order.  Now all I need to do is get the Exit button to launch the external iLogic rule. I pulled the code snippet from the samples, but I am having issues with syntax (again)...

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

OK. I'm not 100% sure where you may be having the syntax issue, so I will attempt to show several example pieces of code in an attempt to help.

Within the 'main' part of your form class area, where all the visible stuff is described, there should be something similar looking to this:  (my example is using the AddHandler system, rather than the WithEvents system) (Link1)

Dim oCancelButton As New Button
With oCancelButton
	.Text = "CANCEL"
	.Top = oStartButton.Top
	.Left = oStartButton.Right + 10
	.Height = 25
	.Width = 75
	.Enabled = True
	.Name = "CancelButton"
End With
oForm.CancelButton = oCancelButton
oForm.Controls.Add(oCancelButton)
AddHandler oCancelButton.Click, AddressOf oCancelButton_Click

But, of course you said your button is going to be labeled as an 'exit' button, and may be a different size & location.

 

Then outside of that 'main' area of your form class, but still within that class, you should have a Sub routine to handle the button click event.  That might look something like this:

Private Sub oCancelButton_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
	Me.Close
	Dim oDoc As Inventor.Document = oInvApp.ActiveDocument
	RuniLogicExternalRule("ExternalRuleName", oDoc)
End Sub

That method name would need to match your other custom Sub routine for running the rule...I just made that one up and reversed the order of the input variables from the documented one.

 

Then the custom Sub for running the external rule might look something like this:

Private Sub RuniLogicExternalRule(oRuleName As String, oDocForRuleToTarget As Inventor.Document)
	Dim iLogicClassIDString As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
	Dim iLogicAddIn As Inventor.ApplicationAddIn = Nothing
	Try
		iLogicAddIn = oInvApp.ApplicationAddIns.ItemById(iLogicClassIDString)
	Catch
		Exit Sub
	End Try
	If Not iLogicAddIn.Activated Then iLogicAddIn.Activate
	Dim oAuto As Object = iLogicAddIn.Automation
	Try
		i = oAuto.RunExternalRule(oDocForRuleToTarget, oRuleName)
	Catch
	End Try
End Sub

Since you are going to be running an external rule from the button, then there are only two methods available for that.  The RunExternalRule method, and the RunExternalRuleWithArguments method.  Within your code for the sub to run the rule, you will most likely not have any 'Intellisense' type help after the iLogic AddIn's Automation object, because it will just be recognized as a generic Object.  But you should be able to just put one of those method codes after the 'dot', (right after that automation object variable) to be able to use them, as seen in the above example.

Again, these are just quickie rough example bits.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

D.Wheeler3GADA
Advocate
Advocate

@WCrihfield ,

    Thank you for the post. I am really struggling with this one. For some reason the things I think would be the easiest to achieve/code are the most difficult... I am thinking I am over complicating what I need to accomplish.

 

From what I can tell, I need to accomplish two things:

 

1) Define the function that launches the external rule. (This is where my issues arise, as I can't seem to make this work and I am not seeing anything in Inventor Help or in my reference materials about functions and iLogic rules...)

 

2) Code the "Exit" button to run the function. (I believe this is as simple as calling up the function)

 

Since the rule is external, I don't have to define a document the rule resides in or anything (I believe), just run it from within the assembly I am in (the one I launched the VB form from). Perhaps I am oversimplifying and not overcomplicating what I need to do. 

0 Likes