Format - iLogic Custom Made User Form

Format - iLogic Custom Made User Form

a81383
Enthusiast Enthusiast
1,260 Views
8 Replies
Message 1 of 9

Format - iLogic Custom Made User Form

a81383
Enthusiast
Enthusiast

Good morning,

I'm working on building my first custom windows user form. I found majority of the following code on the forms here at,

https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-external-rule-through-a-button-in...

 

I've been picking away at it for a little while now and feel confident with the code below. But am now looking to start adding text, images, and change various formatting options (such as background color). And I'm not entirely sure where to start. Does anyone have a good resource or class or example code I could look at to begin building the rest of this form? 

 

Thank you for your time!

 

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 iLogicVb As Autodesk.iLogic.Interfaces.ILowLevelSupport
	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 = 500
			.Height = 750
			.TopMost = True
			.Font = oLargerFont
			.Text = "Template"
			.Name = "Template"
			.ShowInTaskbar = False
		End With
		
		Dim oButton1 As New Button()
		With oButton1
			.Text = "Buttom 1 Test"
			.Top = 25
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton1)
		AddHandler oButton1.Click, AddressOf oButton1_Click	
		
		Dim oButton2 As New Button()
		With oButton2
			.Text = "Buttom 2 Test"
			.Top = 125
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oButton2)
		AddHandler oButton2.Click, AddressOf oButton2_Click
		
		Dim oTextBox1 As New TextBox()
		With oTextBox1
			.Text = "I am a Text Box"
			.Top = 225
			.Left = 75
			.Font = oLargerFont
			.Enabled = True
			.Width = 250
			.Height = 50
		End With
		oForm.Controls.Add(oTextBox1)
		AddHandler oTextBox1.Leave, AddressOf oTextBox1_Leave
		
		Dim oCheckBox1 As New CheckBox()
		With oCheckBox1
			.Text = "Check Box"
			.Top = 325
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oCheckBox1)
		AddHandler oCheckBox1.CheckedChanged, AddressOf oCheckBox1_CheckedChanged
		
		Dim oComboBox1 As New ComboBox()
		With oComboBox1
	        .DataSource = {"A", "B", "C", "NA"}
			.Top = 425
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oComboBox1)
		AddHandler oComboBox1.SelectedIndexChanged, AddressOf oComboBox1_SelectedIndexChanged
		
		Dim oRadioButton1 As New RadioButton()
		With oRadioButton1
			.Text = "Radio Button 1"
			.Top = 525
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oRadioButton1)
		AddHandler oRadioButton1.CheckedChanged, AddressOf oRadioButton1_CheckedChanged
		
		Dim oRadioButton2 As New RadioButton()
		With oRadioButton2
			.Text = "Radio Button 2"
			.Top = 575
			.Left = 75
			.Enabled = True
			.AutoSize = True
		End With
		oForm.Controls.Add(oRadioButton2)
		AddHandler oRadioButton2.CheckedChanged, AddressOf oRadioButton2_CheckedChanged
	' This is the end of the main Sub that defines the Form .SelectionChangeCommitted
	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 oTextBox1_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 oCheckBox1_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 oComboBox1_SelectedIndexChanged(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)
		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
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
1,261 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @a81383.  That is likely going to be one of those tasks that you will need to develop over time through research and trial & error testing.  Most of that code looks similar to something I posted on the forums years ago as an example of what is possible from an iLogic rule.  All of those original user submitted KnowledgeBase articles that folks had posted were taken down though.  Designing and creating a really nice Windows Form from within an iLogic rule is pretty challenging, because there are no user interface tools to help you with that task, and very little hints or snippets to even help you get started down that path.  Forms like that are usually created within an external application designed for software development, like Microsoft's Visual Studio, where they have built-in tools to help with that specific task.  Since adding and laying out 'controls' within a Form completely by code, without any user interface helpers was already challenging enough, I did not really explore into customizing colors, or adding images at the time.  Most likely the best place to find help with that task is going to be either within the following Microsoft web address:

https://learn.microsoft.com/en-us/dotnet/api/ 

...and deeper within that area, such as the following links:

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form 

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.color 

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image 

...then just general internet searches, which I generally begin with the text "vb.net "...then the subject I am searching for.  By the way, when on the Microsoft websites, you may need to change the value of the little drop-down near the top of the pages to "VB", instead of "C#", or "F#", or "C++", in order to see examples in VB, since iLogic uses vb.net as its basis.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

mgrenier2
Collaborator
Collaborator

Did you figure it out? I'm also pulling my hair trying to set a backcolor for an iLogic form.

0 Likes
Message 4 of 9

WCrihfield
Mentor
Mentor

Hi @mgrenier2.  I assume you are talking about the Form.BackColor property (or the Control.DefaultBackColor property), which is available in the Windows forms spectrum.  No, I have not attempted to set that specification for an 'iLogic' Form by code, and do not know how to right now.  I have done a few deep dives into the iLogic resources used to define iLogic Forms, for various basic purposes, but never looked into the finer aesthetic details like that.  One of the last things concerning internal iLogic Forms I attempted to do by code was delete specific ones, by their name.  You can see an example of the code required for that task at the following forum post:

https://forums.autodesk.com/t5/inventor-programming-forum/delete-forms-with-rule/m-p/12560701/highli... 

Earlier in that same conversation you will see some other 'references' &/or 'Imports' that can be explored further, which touches on some of the supporting code tools used for managing iLogic forms, but that is just the tip of the iceberg, so to speak.  There is a ton more to it that I don't have time to go into here.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 9

mgrenier2
Collaborator
Collaborator
Function GetExportFormat() As String
    Dim frm As New System.Windows.Forms.Form()
    frm.Text = "Export DXF / DWG"
    frm.StartPosition = FormStartPosition.CenterScreen
    frm.Width = 300 : frm.Height = 150
	'frm.BackColor = RGB(59,68,83)
    ' Radios centrées horizontalement
    Dim rbtnDXF As New RadioButton() With {.Text = "DXF", .Top = 20, .Width=80}
    Dim rbtnDWG As New RadioButton() With {.Text = "DWG", .Top = 50, .Width=80}
    rbtnDXF.Checked = True
    ' Position horizontale centrée
    rbtnDXF.Left = (300-80) \ 2
    rbtnDWG.Left = (300-80) \ 2
    ' Bouton OK	
	Dim btnOK As New Button() With {.Text = "OK", .Top = 85, .Width=80}
	btnOK.Left= (300-80) \ 2
    AddHandler btnOK.Click, Sub(sender As Object, e As EventArgs)
                                 frm.DialogResult = DialogResult.OK
                                 frm.Close()
                             End Sub
    frm.Controls.Add(rbtnDXF) : frm.Controls.Add(rbtnDWG) : frm.Controls.Add(btnOK)

    If frm.ShowDialog() <> DialogResult.OK Then Return ""
    Return If(rbtnDXF.Checked, "DXF", "DWG")
End Function

 

I tried frm.BackColor=RGB(59,68,83)

frm.BackColor = System.Drawing.Color.FromArgb(59, 68, 83)
frm.BackColor = Red
frm.BackColor = System.Drawing.Color.White
 

It's always complaining System.Drawing.Primitives is not available

0 Likes
Message 6 of 9

SMillsYS3X2
Advocate
Advocate

Just to check, is there a reason why your using iLogic to make this form instead of the Form Editor in Inventor?

SMillsYS3X2_0-1764617741474.png

 

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

I am not sure why it would be complaining about that specific reference.  I assume you included the usual 'AddReference' line in the header for "System.Drawing", then the similar Imports line.  If so, I do not recall doing much more along those lines, or that specific 'Primitives' reference.  But I'm still using Inv Pro 2024.5.  And to be transparent, I am not exactly a Windows Forms guru, just someone who has dabbled with them on lots of occasions over the years.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 9

a81383
Enthusiast
Enthusiast

Hi @SMillsYS3X2

iLogic forms are quick and easy but quite limited in terms of layout, styling, and advanced functionality. I initially tried building a custom WinForms/WPF dialog from iLogic to get more control over the appearance and behavior, but it turned out to be more difficult and still very restrictive (especially with formatting and modal window limitations).

 

After testing both approaches, my recommendation is:

  • For simple parameter-driven forms, stick with built-in iLogic forms – they’re fast to create and perfectly adequate for most cases.
  • If you need full control over the UI (custom layout, advanced controls, docking, themes, etc.), the proper long-term solution is to develop a custom Inventor add-in (C# or VB.NET).

The official add-in samples and developer tools are installed here (replace 2025 with your version):

C:\Program Files\Autodesk\Inventor 2025\SDK\samples\AddIn\

You’ll find complete Visual Studio projects in C#, VB.NET, and C++ (the “StandardAddIn” sample is the best starting point).

Message 9 of 9

mgrenier2
Collaborator
Collaborator

I guess I just didn't really think about doing it this way.

But I always feel way too limited with the iLogic form editor, I like my radio buttons and checkboxes. I also did not want to create some useless boolean parameters in my template just for this