Execute External rule through a button in an iLogic Custom Made User Form

Execute External rule through a button in an iLogic Custom Made User Form

checkcheck_master
Advocate Advocate
810 Views
5 Replies
Message 1 of 6

Execute External rule through a button in an iLogic Custom Made User Form

checkcheck_master
Advocate
Advocate

I think I have a simple question but can't figure it out:
How can I execute an External rule through a button in an iLogic Custom Made User Form that I already have?
See image and code.

Thanks in advance.

AddReference "System.Drawing"
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Public Class WinForm
	Inherits System.Windows.Forms.Form
	' Declare any thing here that you want to use/access throughout all Subs & Functions
	Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)
		
	Public Sub New() ' Creates the new instance
		oForm = Me
		With oForm
			.FormBorderStyle = FormBorderStyle.FixedToolWindow
			.StartPosition = FormStartPosition.CenterScreen
			.Width = 600
			.Height = 300
			.TopMost = True
			.Font = oLargerFont
			.Text = "Windows Form"
			.Name = "Windows Form"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "HML Production Output"
			.Top = 25
			.Left = 25
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click	
		
		Dim oButton2 As New Button()
		With oButton2
			.Text = "HML Update Tool"
			.Top = 125
			.Left = 25
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton2)
		AddHandler oButton2.Click, AddressOf oButton2_Click	

	' This is the end of the main Sub that defines the Form
	End Sub

	Private Sub WinForm_FormClosing(ByVal oSender As Object, ByVal oFormCloseEvents As FormClosingEventArgs) Handles Me.FormClosing
	    If MsgBox("Are you sure you want to close this Form?",vbYesNo+vbQuestion, "CLOSE") = vbYes Then
	    Else
	      oFormCloseEvents.Cancel = True
	    End If
	 End Sub
  
	Private Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' oSender is a Button
		MsgBox("You just clicked the [" & oSender.Text & "] button.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		iLogicVb.RunExternalRule("HML - BetaV017")
				
	End Sub
	
	Private Sub oButton2_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' oSender is a Button
		MsgBox("You just clicked the [" & oSender.Text & "] button.",vbOKOnly+vbInformation,"EVENT FEEDBACK")
		'iLogicVb.RunExternalRule("HML Update Tool")		
	
	End Sub

	Private Sub oTextBox_Leave(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Text <> oOriginalText Then 'oSender is a TextBox
			MsgBox("The contents of the TextBox have changed.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
		
	Private Sub oCheckBox_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked = True Then 'Sender is a CheckBox
			MsgBox("You just Checked the [" & oSender.Text & "] checkbox.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
			MsgBox("You just UnChecked the [" & oSender.Text & "] checkbox.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
	
	Private Sub oComboBox_SelectionChangeCommitted(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		' oSender is a ComboBox
		MsgBox("You just chose " & oSender.Text & " from the ComboBox.",vbOKOnly+vbInformation,"EVENT FEEDBACK")
	End Sub
	
	Private Sub oRadioButton1_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		If oSender.Checked Then 'oSender is a RadioButton
			MsgBox("You just changed the Radio Button option to '" & oSender.Text & "'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		Else
			MsgBox("You just changed the Radio Button option to 'Choice 2'.", vbOKOnly + vbInformation, "EVENT FEEDBACK")
		End If
	End Sub
	
'	Private Sub oRadioButton2_CheckedChanged(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
'		MsgBox("You just changed the Radio Button option to " & oSender.Text & ".",vbOKOnly+vbInformation,"EVENT FEEDBACK")
'	End Sub
End Class

'This is the code that actually shows/runs the Form
Public Class RunMyForm
	Private Sub Main
		Dim oMyForm As New WinForm
		oMyForm.Show
	End Sub
End Class

 

0 Likes
Accepted solutions (1)
811 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @checkcheck_master.  If you are running this code from an iLogic rule, then I think you may be able to just add an additional line of code in your Public declarations near the top of your WinForm Class block.  Right now it doesn't recognize the 'iLogicVb' term, because it is defined elsewhere, and hasn't been introduced into this new Class yet.

Try adding this line:

Public iLogicVb As Autodesk.iLogic.Interfaces.ILowLevelSupport

...just after this line:

Public oLargerFont As System.Drawing.Font = New Font("Arial", 10)

...near the top of your WinForm Class block.  That should help it recognize that term, and use it properly later in those lines of code that are trying to run other external rules.  Let me know if that works out OK for you.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

checkcheck_master
Advocate
Advocate

Great, thank you so much!
Recently came up why you should be happy with Inventor.
I have plenty to say but someone mentioned the Forum as a plus, I'm happy to join!

 

I knew I had to declare iLogicVb somewhere but this way, 'As Autodesk.iLogic.Interfaces.ILowLevelSupport', I hadn't come up with.
So my next question is, how do you get here?

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

You can get one clue while within another regular iLogic rule window, and after you type in iLogicVb, hover your mouse over it and read the pop-up hint (intellisense).

WCrihfield_0-1658250959948.png

It tells us that this term is defined under the default Class called "ThisRule" (which is automatically created for us in the background in every rule), and that it represents something called "ILowLevelSupport", which provided general functions.  You can then go to the regular online help page (https://help.autodesk.com/view/INVNTOR/2022/ENU) and search for that term.

Here is the link to it within the 2022 online help:

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=05d9c5e8-452e-3474-8a81-2006b7aa69ac

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

checkcheck_master
Advocate
Advocate
Thanks again, very clear!
0 Likes
Message 6 of 6

checkcheck_master
Advocate
Advocate

Still a little less easy than expected, get this error message, see picture.

In line 76 which is 'commented'.

Hmm. Much to learn.

 

Also I'm struggling to exit the user form by Escape key.

Any tips in these are welcome.

 

0 Likes